Skip to content

Commit

Permalink
Merge pull request #3780 from jkmw/fix/2578
Browse files Browse the repository at this point in the history
Remove existing path before restoring a symlink
  • Loading branch information
MichaelEischer committed Sep 24, 2022
2 parents b48766d + ef618bd commit 041a515
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/pull-3780
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Make sure that symlinks can be created during recovery

When restoring a symlink, restic reported an error if the target path already existed.
With this change, the potentially existing target path is first removed before the symlink is recreated.

https://github.com/restic/restic/issues/2578
https://github.com/restic/restic/pull/3780
8 changes: 6 additions & 2 deletions internal/restic/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Remove(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")
}

Expand Down

0 comments on commit 041a515

Please sign in to comment.