From 9adaa6e24083df097858f1cc6c825ae1e74b7a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jerome=20K=C3=BCttner?= Date: Wed, 1 Jun 2022 17:26:25 +0200 Subject: [PATCH 1/3] Delete existing path before restoring a symlink --- internal/restic/node.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/restic/node.go b/internal/restic/node.go index 54b67c672..341d88118 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.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") } From 6f3883c9d23133255da11cd441caa01a1e6b1a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jerome=20K=C3=BCttner?= Date: Tue, 5 Jul 2022 08:47:48 +0200 Subject: [PATCH 2/3] add changelog --- changelog/unreleased/pull-3780 | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 changelog/unreleased/pull-3780 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 From ef618bdd3f1ccd53e53efd08b55375e7b3b6e949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jerome=20K=C3=BCttner?= Date: Wed, 14 Sep 2022 08:14:31 +0200 Subject: [PATCH 3/3] use os.Remove if path already exists on symlink restore --- internal/restic/node.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/restic/node.go b/internal/restic/node.go index 341d88118..bc64b7fc3 100644 --- a/internal/restic/node.go +++ b/internal/restic/node.go @@ -300,7 +300,7 @@ func (node Node) createSymlinkAt(path string) error { return nil } - if err := os.RemoveAll(path); err != nil && !errors.Is(err, os.ErrNotExist) { + if err := os.Remove(path); err != nil && !errors.Is(err, os.ErrNotExist) { return errors.Wrap(err, "Symlink") }