Skip to content

Commit 3b997db

Browse files
committed
handle symlink already exists
1 parent 0598e5e commit 3b997db

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

test/utils/ocm.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,18 @@ func DownloadOCMAndAddToPath(t *testing.T) {
8484
t.Fatalf("failed to chmod ocm binary: %v", err)
8585
}
8686

87-
if err := os.Symlink(ocmPath, filepath.Join(cacheDir, "ocm")); err != nil {
87+
// if symlink already exists, remove it
88+
symlinkPath := filepath.Join(cacheDir, "ocm")
89+
if _, err := os.Lstat(symlinkPath); err == nil {
90+
if err := os.Remove(symlinkPath); err != nil {
91+
t.Fatalf("failed to remove existing symlink: %v", err)
92+
}
93+
} else if !os.IsNotExist(err) {
94+
t.Fatalf("failed to check existing symlink: %v", err)
95+
}
96+
97+
// create symlink to the ocm binary
98+
if err := os.Symlink(ocmPath, symlinkPath); err != nil {
8899
t.Fatalf("failed to create symlink for ocm binary: %v", err)
89100
}
90101
} else {

0 commit comments

Comments
 (0)