-
Notifications
You must be signed in to change notification settings - Fork 14
Handle recursive links in runtime sources. #3600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d33a4d0
Handle recursive links in runtime sources.
mitchell-as da5fee5
Recurse into recursively linked directories not more than once.
mitchell-as 9dd2ff9
Revert "Recurse into recursively linked directories not more than once."
mitchell-as f0c7784
Make it explicit that re-encountering file involves a symlink source.
mitchell-as b75482b
When deploying via link, deploy symlinks directly instead of resolvin…
mitchell-as d1a7e18
Minimize changes from previous commit.
mitchell-as File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package smartlink | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "runtime" | ||
| "testing" | ||
|
|
||
| "github.com/ActiveState/cli/internal/fileutils" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestLinkContentsWithCircularLink(t *testing.T) { | ||
| srcDir, err := os.MkdirTemp("", "src") | ||
| require.NoError(t, err) | ||
| defer os.RemoveAll(srcDir) | ||
|
|
||
| destDir, err := os.MkdirTemp("", "dest") | ||
| require.NoError(t, err) | ||
| defer os.RemoveAll(destDir) | ||
|
|
||
| // Create test file structure: | ||
| // src/ | ||
| // ├── regular.txt | ||
| // └── subdir/ | ||
| // ├── circle -> subdir (circular link) | ||
| // └── subfile.txt | ||
|
|
||
| testFile := filepath.Join(srcDir, "regular.txt") | ||
| err = os.WriteFile(testFile, []byte("test content"), 0644) | ||
| require.NoError(t, err) | ||
|
|
||
| subDir := filepath.Join(srcDir, "subdir") | ||
| err = os.Mkdir(subDir, 0755) | ||
| require.NoError(t, err) | ||
|
|
||
| subFile := filepath.Join(subDir, "subfile.txt") | ||
| err = os.WriteFile(subFile, []byte("sub content"), 0644) | ||
| require.NoError(t, err) | ||
|
|
||
| circularLink := filepath.Join(subDir, "circle") | ||
| err = os.Symlink(subDir, circularLink) | ||
| require.NoError(t, err) | ||
|
|
||
| err = LinkContents(srcDir, destDir) | ||
| if runtime.GOOS == "windows" { | ||
| require.Error(t, err) | ||
| return // hard links to directories are not allowed on Windows | ||
| } | ||
| require.NoError(t, err) | ||
|
|
||
| // Verify file structure. | ||
| destFile := filepath.Join(destDir, "regular.txt") | ||
| require.FileExists(t, destFile) | ||
| content, err := os.ReadFile(destFile) | ||
| require.NoError(t, err) | ||
| require.Equal(t, "test content", string(content)) | ||
|
|
||
| destSubFile := filepath.Join(destDir, "subdir", "subfile.txt") | ||
| require.FileExists(t, destSubFile) | ||
| subContent, err := os.ReadFile(destSubFile) | ||
| require.NoError(t, err) | ||
| require.Equal(t, "sub content", string(subContent)) | ||
|
|
||
| destCircular := filepath.Join(destDir, "subdir", "circle") | ||
| require.FileExists(t, destCircular) | ||
| target, err := fileutils.ResolveUniquePath(destCircular) | ||
| require.NoError(t, err) | ||
| srcCircular := filepath.Join(srcDir, "subdir") | ||
| if runtime.GOOS == "darwin" { | ||
| srcCircular, err = fileutils.ResolveUniquePath(srcCircular) // needed for full $TMPDIR resolution | ||
| require.NoError(t, err) | ||
| } | ||
| require.Equal(t, target, srcCircular) | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.