Repository navigation
Archive the target directory when a download path is a symlink - #475
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
GET /fs/download_dir_zip and /fs/download_dir_zstd stat the path with os.Stat, so a symlink to a directory passes the directory check. The archivers then walk it with filepath.Walk, which does not descend into a symlinked root, and return an empty archive with a 200 status. Resolve the source directory with filepath.EvalSymlinks before walking.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
Summary
GET /fs/download_dir_zipandGET /fs/download_dir_zstdcheck the path withos.Stat, which follows symlinks, so a symlink to a directory passes the "is a directory" check.ziputil.ZipDirandzstdutil.TarZstdDirthen walk it withfilepath.Walk, which does not descend into a symlinked root. The response is a 200 with an empty archive.This change resolves the source directory with
filepath.EvalSymlinksbefore walking, in both archivers. Symlinks inside the directory are still archived as links.Tests
TestZipDirFollowsSymlinkedRootandTestTarZstdDirFollowsSymlinkedRootarchive a directory through a symlink and check that its file is in the archive. Both fail without the fix.go test -race ./lib/ziputil ./lib/zstdutilgo test -race ./cmd/api/api -run 'Zip|Zstd|Download|Upload'go vet ./lib/ziputil ./lib/zstdutil ./cmd/api/...Note
Low Risk
Localized bug fix in archive helpers with regression tests; symlink-in-archive behavior is unchanged.
Overview
Fixes empty zip/tar.zst downloads when the requested path is a symlink to a directory: API checks use
os.Stat(follows the link), butfilepath.Walkdoes not enter a symlinked root, so archives were built with no entries.ZipDirandTarZstdDirnow callfilepath.EvalSymlinkson the source path before walking, so the real directory is archived. Symlinks inside the tree are unchanged (still stored as links).Adds
TestZipDirFollowsSymlinkedRootandTestTarZstdDirFollowsSymlinkedRootto cover archiving through a symlinked root.Reviewed by Cursor Bugbot for commit a6fb8a7. Bugbot is set up for automated code reviews on this repo. Configure here.