mirror of
https://github.com/fluxcd/flux2.git
synced 2026-04-10 14:10:05 +00:00
fix: handle multiple symlinks to same target in build artifact
Signed-off-by: iam-karan-suresh <karansuresh.info@gmail.com>
This commit is contained in:
parent
7c9810ea3b
commit
69e2c6bc7d
2 changed files with 37 additions and 1 deletions
|
|
@ -172,7 +172,7 @@ func copyDir(srcDir, dstDir string, visited map[string]bool) error {
|
|||
return nil // break the cycle
|
||||
}
|
||||
visited[abs] = true
|
||||
|
||||
defer delete(visited, abs)
|
||||
entries, err := os.ReadDir(srcDir)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -179,3 +179,39 @@ func Test_resolveSymlinks_cycle(t *testing.T) {
|
|||
_, err = os.Stat(filepath.Join(resolved, "cycle", "cycle", "cycle"))
|
||||
g.Expect(os.IsNotExist(err)).To(BeTrue())
|
||||
}
|
||||
|
||||
func Test_resolveSymlinks_multipleLinksSameTarget(t *testing.T) {
|
||||
g := NewWithT(t)
|
||||
|
||||
// Create source directory with a real file inside a dir
|
||||
srcDir := t.TempDir()
|
||||
targetDir := filepath.Join(srcDir, "target")
|
||||
g.Expect(os.MkdirAll(targetDir, 0o755)).To(Succeed())
|
||||
g.Expect(os.WriteFile(filepath.Join(targetDir, "file.yaml"), []byte("data"), 0o644)).To(Succeed())
|
||||
|
||||
// Create a directory with multiple symlinks pointing to targetDir
|
||||
symlinkDir := t.TempDir()
|
||||
|
||||
// Link 1
|
||||
link1 := filepath.Join(symlinkDir, "link1")
|
||||
g.Expect(os.Symlink(targetDir, link1)).To(Succeed())
|
||||
|
||||
// Link 2
|
||||
link2 := filepath.Join(symlinkDir, "link2")
|
||||
g.Expect(os.Symlink(targetDir, link2)).To(Succeed())
|
||||
|
||||
// Resolve symlinks
|
||||
resolved, cleanupDir, err := resolveSymlinks(symlinkDir)
|
||||
g.Expect(err).To(BeNil())
|
||||
t.Cleanup(func() { os.RemoveAll(cleanupDir) })
|
||||
|
||||
// Verify link1 has the file
|
||||
content, err := os.ReadFile(filepath.Join(resolved, "link1", "file.yaml"))
|
||||
g.Expect(err).To(BeNil())
|
||||
g.Expect(string(content)).To(Equal("data"))
|
||||
|
||||
// Verify link2 ALSO has the file
|
||||
content2, err := os.ReadFile(filepath.Join(resolved, "link2", "file.yaml"))
|
||||
g.Expect(err).To(BeNil())
|
||||
g.Expect(string(content2)).To(Equal("data"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue