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