Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove existing path before restoring a symlink #3780

Merged
merged 3 commits into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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