From 2b0dc0613fc60610ca9f9bd7c52f8367dc3fd56d Mon Sep 17 00:00:00 2001 From: Carl Johnsen Date: Tue, 3 Dec 2024 10:04:08 +0100 Subject: [PATCH] Added handling of existing symlinks --- Duplicati/Library/Main/Operation/RestoreHandler.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Duplicati/Library/Main/Operation/RestoreHandler.cs b/Duplicati/Library/Main/Operation/RestoreHandler.cs index b5bc69fc9..c28af80ce 100644 --- a/Duplicati/Library/Main/Operation/RestoreHandler.cs +++ b/Duplicati/Library/Main/Operation/RestoreHandler.cs @@ -599,7 +599,14 @@ namespace Duplicati.Library.Main.Operation // Make the symlink first, otherwise we cannot apply metadata to it if (metadata.TryGetValue("CoreSymlinkTarget", out k)) + { + // Check if the target exists, and overwrite it if it does. + if (System.IO.File.Exists(targetpath) || System.IO.Directory.Exists(targetpath)) + { + System.IO.File.Delete(targetpath); + } SystemIO.IO_OS.CreateSymlink(targetpath, k, isDirTarget); + } // If the target is a folder, make sure we create it first else if (isDirTarget && !SystemIO.IO_OS.DirectoryExists(targetpath)) SystemIO.IO_OS.DirectoryCreate(targetpath);