Skip to content

Commit 968521f

Browse files
Handle race when removing a broken symlink (#2016)
If another process races the current process in fixing a broken symlink, the remove operation will return an error unnecessarily. This fixes that.
1 parent cda9a4c commit 968521f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pkg/paths/paths.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ func AdvertiseCachedFile(src, dst string) error {
6060
}
6161
// Broken symlink (Lstat succeeded but Stat failed) - remove it.
6262
if err := os.Remove(dst); err != nil {
63+
if errors.Is(err, os.ErrNotExist) {
64+
// Race condition: something removed it between our Lstat and Remove.
65+
// Re-run to handle it properly.
66+
return AdvertiseCachedFile(src, dst)
67+
}
6368
return fmt.Errorf("removing broken symlink %s: %w", dst, err)
6469
}
6570
}

0 commit comments

Comments
 (0)