-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle recursive links in runtime sources.
- Loading branch information
1 parent
fbf7ca2
commit d33a4d0
Showing
5 changed files
with
104 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 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, nil) | ||
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) | ||
} |
This file contains 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 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