2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 02:48:55 +00:00

Merge pull request #3780 from jkmw/fix/2578

Remove existing path before restoring a symlink
This commit is contained in:
Michael Eischer 2022-09-24 12:34:42 +02:00 committed by GitHub
commit 041a51512a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -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

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.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")
}