Skip to content

Commit

Permalink
Work around ReferenceStore uri having an empty uri field (what?)
Browse files Browse the repository at this point in the history
  • Loading branch information
asinghvi17 committed Oct 9, 2024
1 parent 5ea1198 commit 501e80f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/referencestore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,27 @@ function Zarr.storefromstring(::Type{<: ReferenceStore}, url, _)
# Extract the parameters, and reformat the URI
params = URIs.queryparams(uri)
uri = URIs.URI(uri; query = URIs.absent)
provided_path = URIs.uristring(uri)

# If the URI's scheme is empty, we're resolving a local file path.
# Note that we always use PosixPaths here, because the Zarr spec mandates that
# all path separators be forward slashes. Kerchunk also mandates this.
file_path = if isempty(uri.scheme)
if isabspath(uri.uri)
FilePathsBase.PosixPath(uri.uri)
elseif ispath(uri.uri)
FilePathsBase.PosixPath(joinpath(pwd(), uri.uri))
if ispath(provided_path)
if isabspath(provided_path)
FilePathsBase.PosixPath(provided_path)
else
FilePathsBase.PosixPath(joinpath(pwd(), provided_path))
end
else
error("Invalid path, presumed local but not resolvable as absolute or relative path: $(uri)")
error("Invalid path, presumed local but not resolvable as absolute or relative path: `$(uri)`")
end
elseif uri.scheme == "file" # Otherwise, we check the protocol and create the appropriate path type.
FilePathsBase.Path(uri.path)
elseif uri.scheme == "s3"
AWSS3.S3Path(uri.uri)
AWSS3.S3Path(provided_path)
else
FilePathsBase.@p_str uri.path
end # TODO: add more protocols, like HTTP, Google Cloud, Azure, etc.

rs = ReferenceStore(file_path)
Expand All @@ -222,7 +227,7 @@ function Zarr.storefromstring(::Type{<: ReferenceStore}, url, _)
end
# One could add more corrections here...

return rs, "" # ReferenceStore never has a relative path
return (rs, "") # ReferenceStore never has a relative path
end

function Zarr.subdirs(store::ReferenceStore, key)
Expand Down

0 comments on commit 501e80f

Please sign in to comment.