Delete existing path before restoring a symlink

This commit is contained in:
Jerome Küttner 2022-06-01 17:26:25 +02:00
parent 74f7fe2b98
commit 9adaa6e240
1 changed files with 6 additions and 2 deletions

View File

@ -299,8 +299,12 @@ func (node Node) createSymlinkAt(path string) error {
if runtime.GOOS == "windows" {
return nil
}
err := fs.Symlink(node.LinkTarget, path)
if err != nil {
if err := os.RemoveAll(path); err != nil && !errors.Is(err, os.ErrNotExist) {
return errors.Wrap(err, "Symlink")
}
if err := fs.Symlink(node.LinkTarget, path); err != nil {
return errors.Wrap(err, "Symlink")
}