context: follow symlink roots during Walk - #319
Open
sueun-dev wants to merge 1 commit into
Open
Conversation
Context.Walk currently replaces a symlink root with the raw os.Readlink result before calling filepath.Walk. That only works when the symlink target is absolute. For a relative symlink, filepath.Walk starts from the process working directory; for a symlink-to-symlink root, it walks the intermediate link instead of the referenced directory. Use the context root path with a trailing separator when the root itself is a symlink, so filepath.Walk enters the target directory while the reported paths remain relative to the context root. Add a regression test for absolute symlink, relative symlink, and symlink-to-symlink roots. Signed-off-by: Sueun Cho <sueun.dev@gmail.com>
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.
This fixes the root-symlink case from #232.
Context.Walkcurrently replaces a symlink root withReadlink(root). That works only when the symlink target is absolute. For relative symlinks,Readlinkreturns the stored relative target, sofilepath.Walkstarts from the process working directory. For a symlink-to-symlink root it walks the second link instead of the target directory.Keep walking through the context path and add a trailing separator when the root itself is a symlink. That makes
filepath.Walkenter the referenced directory while keeping path containment relative to the context root.The new test covers absolute symlink, relative symlink, and symlink-to-symlink roots.
Fixes #232.
Tests:
go test -run TestContextWalkSymlinkRoot -count=20 ./go test -count=1 -mod=vendor ./...go test -race -run TestContextWalkSymlinkRoot -count=10 ./go test -race -count=1 -mod=vendor ./...make build testmake lintGOOS=linux make buildGOOS=windows make buildGOOS=freebsd make buildgo test -run TestContextWalkSymlinkRoot -count=20 .andgo test -short -mod=vendor ./...go test -run TestContextWalkSymlinkRoot -count=20 .,go test -short -mod=vendor ./..., andmake build