diff --git a/changelog/unreleased/pull-3780 b/changelog/unreleased/pull-3780 new file mode 100644 index 000000000..8ec2ca076 --- /dev/null +++ b/changelog/unreleased/pull-3780 @@ -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 diff --git a/internal/restic/node.go b/internal/restic/node.go index 54b67c672..bc64b7fc3 100644 --- a/internal/restic/node.go +++ b/internal/restic/node.go @@ -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") }