You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You need to use the special @path_str macro or explicitly construct a RelPath for this to work. It'd be nice to just allow using the complete key as a string.
The text was updated successfully, but these errors were encountered:
mbauman
changed the title
Allow indexing with string keys with path components in them
Allow indexing FileTree with string keys with path components in them
Nov 29, 2023
I am a little bit hesitant here, since it does look like it was a pretty conscious choice to not interpret slashes in Strings on the grounds that you may get weird platform-specific behavior. On unix-y systems, you might have a file with the name foo\bar, but we'd then interpret that as the path ("foo", "bar").
RelPath(::AbstractString) =error("RelPath(::String) is not defined to avoid ambiguities between operating systems. Use the `path\"...\"` string macro for path literals.")
function Base.joinpath(path::RelPath, xs::AbstractString...)
for x in xs
if'/'in x ||'\\'in x
error("Path components cannot contain '/' or '\\' (got $(repr(x)))")
end
end
RelPath(vcat(path.components, xs...))
end
On the other hand, such file names are effectively prohibited in DataSets.jl datasets because of this restriction, so it would probably not break anything if we just apply the same logic that path"" uses on strings passed to getindex.
Implementation-wise, this would be a pretty trivial change.
Currently:
julia> filetree["path/to/file.ext"] ERROR: Path components cannot contain '/' or '\' (got "path/to/file.ext") Stacktrace: [1] error(s::String) @ Base ./error.jl:35 [2] joinpath(path::DataSets.RelPath, xs::String) @ DataSets ~/data/.julia/packages/DataSets/DWg6S/src/paths.jl:28 [3] getindex(tree::BlobTree{JuliaHubData.DataRepoCache}, name::String) @ DataSets ~/data/.julia/packages/DataSets/DWg6S/src/BlobTree.jl:326 [4] top-level scope @ REPL[96]:1
You need to use the special
@path_str
macro or explicitly construct aRelPath
for this to work. It'd be nice to just allow using the complete key as a string.The text was updated successfully, but these errors were encountered: