Skip to content

Commit 620442c

Browse files
committed
More consistent handling of non-existent paths
1 parent 60e5464 commit 620442c

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Zarr.m

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,19 @@
7070

7171
if resolvedPath == ""
7272
% If the given path does not exist, it is likely due to
73-
% trailing directories not existing yet. Resolve parent
74-
% directory's path, and append child directory.
73+
% trailing directories not existing yet. Try to resolve its
74+
% parent path.
7575
[pathToParentFolder, child, ext] = fileparts(path);
7676

7777
if pathToParentFolder==path
78-
% If the path was not resolved and we are not able to
79-
% exract a different parent path, we have failed to
80-
% resolve a full path
81-
error("MATLAB:Zarr:invalidPath",...
82-
"Unable to access path ""%s"".", path)
78+
% If the path was not resolved and it is the same as
79+
% its parent path, then we have failed to resolve a
80+
% full path. This likely indicates a problem.
81+
resolvedPath = "";
82+
return
8383
end
8484

85+
% Resolve parent directory's path, and append child directory.
8586
resolvedParentPath = Zarr.getFullPath(pathToParentFolder);
8687
resolvedPath = fullfile(resolvedParentPath, child+ext);
8788
end
@@ -104,13 +105,13 @@
104105
% Get the parent path
105106
[pathToParentFolder, ~, ~] = fileparts(path);
106107
if pathToParentFolder == path
107-
% If the path is not an existing folder and it has no
108-
% parent folder, we have failed to find an existing parent
109-
% folder. This likely indicates a problem.
108+
% If the path is not an existing folder and it is the same
109+
% as its parent path, we have failed to find an existing
110+
% parent folder. This likely indicates a problem.
110111
existingParent = "";
111112
return
112113
end
113-
% Continue recursing until an exisiting parent path is found
114+
% Continue recursing until an existing parent path is found
114115
existingParent = Zarr.getExistingParentFolder(pathToParentFolder);
115116

116117
end
@@ -187,8 +188,13 @@ function makeZarrGroups(existingParentPath, newGroupsPath)
187188
obj.KVStoreSchema = py.ZarrPy.createKVStore(obj.isRemote, objectPath, bucketName);
188189

189190
else % Local file
190-
% use full path
191+
% Use full path
191192
obj.Path = Zarr.getFullPath(path);
193+
if obj.Path == ""
194+
% Error out if the full path could not be resolved
195+
error("MATLAB:Zarr:invalidPath",...
196+
"Unable to access path ""%s"".", path)
197+
end
192198
obj.KVStoreSchema = py.ZarrPy.createKVStore(obj.isRemote, obj.Path);
193199
end
194200
end

0 commit comments

Comments
 (0)