fsspec / fsspec/filesystem_spec
Sanitize some common TAR path occurrences such as leading dots ./
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.4k
- Forks
- 490
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 38
Description
Hi there,
we already wrote a bit back and forth in the issue in the smart_open repository. I wanted to give fsspec.fuse a quick try using the tar/libarchive backend. Unluckily, my very first test failed. I created the test tar with:
echo foo > large
tar -cf ./large{.tar,}
tar tvlf large.tar # -rwx------ user/user 4 2024-04-10 23:04 ./large
Then, I tried to mount it with:
from fsspec.implementations.tar import TarFileSystem as tafs
fs = tafs("large.tar")
import fsspec.fuse
fsspec.fuse.run(fs, "", "mounted")'
and access it with:
ls -la mounted/
# total 4
# drwxrwxrwx 0 user user 0 Apr 10 23:07 .
# drwxrwxrwx 0 user user 0 Apr 10 23:07 .
# drwx------ 1 user user 4096 Apr 10 23:04 ..
ls -la mounted/./
# total 4
# drwxrwxrwx 0 user user 0 Apr 10 23:07 .
# drwxrwxrwx 0 user user 0 Apr 10 23:07 .
# drwx------ 1 user user 4096 Apr 10 23:04 ..
As you can see, the leading dot is interpreted as a valid folder even though it isn't. And even though it is shown because of the FUSE-specifics, which already normalizes paths before the implementation is called, it is not possible to access the large file.
I think, the TAR and libarchive backends should normalize paths to some degree. At least leading dots. Maybe also . and .. inside the path. Funnily enough, I had the exact same issue with fuse-archive: https://github.com/google/fuse-archive/issues/2 . There are also more complex cases, e.g., try this:
tar -cf large.tar ./././large
tar tvlf large.tar
#-rwx------ user/user 4 2024-04-10 23:04 ./././large
I was not able to create a path with .. in it. Gnu tar strips it and even the leading dots when a .. occurs. But it might be possible to create such TARs with Python's tarfile and/or with other tools.
Specifying path = "./" to fsspec.fuse.run kinda works around this issue and large will be visible in the mount point, but:
- I would have to know whether there are leading dots first, which complicates usage.
- It doesn't fix working with TARs with files both with leading dot and without, e.g.:
echo foo > bar
echo foo > large
tar -cf large.tar bar ./large
tar tvlf large.tar
# -rwx------ user/user 4 2024-04-10 23:20 bar
# -rwx------ user/user 4 2024-04-10 23:04 ./large
python3.12 -c '
from fsspec.implementations.tar import TarFileSystem as tafs
fs = tafs("large.tar")
import fsspec.fuse
fsspec.fuse.run(fs, "", "mounted")' &
ls -la mounted
# ls: cannot access 'mounted/bar': No such file or directory
# total 4
# drwxrwxrwx 0 user user 0 Apr 10 23:21 .
# drwxrwxrwx 0 user user 0 Apr 10 23:21 .
# drwx------ 1 user user 4096 Apr 10 23:20 ..
# ?????????? ? ? ? ? ? bar
fusermount -u mounted
python3.12 -c '
from fsspec.implementations.tar import TarFileSystem as tafs
fs = tafs("large.tar")
import fsspec.fuse
fsspec.fuse.run(fs, "./", "mounted")' &
ls -la mounted
# total 4
# drwxrwxrwx 0 user user 0 Apr 10 23:23 .
# drwx------ 1 user user 4096 Apr 10 23:20 ..
# -rwx------ 1 user user 4 Apr 10 23:04 large
Note also how something goes wrong with bar resulting in the metadata not getting shown.
Btw, I was wondering about the path parameter to fsspec.fuse.run. It didn't make sense for such a required parameter to exist, so I had to read up the pretty good online manual, but still, I'd prefer the parameter to be something like prefix = "/", i.e., a self-explanatory name and a default that should cover 99% of the use cases.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with fsspec.implementations.tar.TarFileSystem and the fsspec.fuse.run entry point, then reproduce the reported archives containing ./large and both bar and ./large. Trace how archive member paths are exposed and determine the intended normalization for leading dots and possible . or .. components. Done means files with equivalent normalized paths are accessible consistently through the TAR and libarchive backends, without breaking distinct archive entries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100