diff --git a/Duplicati/Library/AutoUpdater/UpdaterManager.cs b/Duplicati/Library/AutoUpdater/UpdaterManager.cs index 20468fafd..29fcb3c25 100644 --- a/Duplicati/Library/AutoUpdater/UpdaterManager.cs +++ b/Duplicati/Library/AutoUpdater/UpdaterManager.cs @@ -116,7 +116,7 @@ namespace Duplicati.Library.AutoUpdater static UpdaterManager() { // Set the installation path - INSTALLATIONDIR = Util.AppendDirSeparator(Path.GetDirectoryName(Utility.Utility.getEntryAssembly().Location)); + INSTALLATIONDIR = Util.AppendDirSeparator(Path.GetDirectoryName(Utility.Utility.getEntryAssembly().Location) ?? ""); // Attempt to read the installed manifest file UpdateInfo? selfVersion = null; diff --git a/Duplicati/Library/Main/Database/LocalRestoreDatabase.cs b/Duplicati/Library/Main/Database/LocalRestoreDatabase.cs index 07972a364..3e2bba917 100644 --- a/Duplicati/Library/Main/Database/LocalRestoreDatabase.cs +++ b/Duplicati/Library/Main/Database/LocalRestoreDatabase.cs @@ -862,7 +862,7 @@ namespace Duplicati.Library.Main.Database ELSE ""Path"" END ") - .SetParameterValue("@Path", Util.AppendDirSeparator(System.IO.Path.GetPathRoot(Library.Utility.TempFolder.SystemTempPath)).Replace("\\", "/")) + .SetParameterValue("@Path", Util.AppendDirSeparator(System.IO.Path.GetPathRoot(Library.Utility.TempFolder.SystemTempPath) ?? "").Replace("\\", "/")) .ExecuteNonQueryAsync(token) .ConfigureAwait(false); } diff --git a/Duplicati/Library/SourceProvider/Builtin/FileRestoreDestinationProvider.cs b/Duplicati/Library/SourceProvider/Builtin/FileRestoreDestinationProvider.cs index a5c259541..4f6afcd4c 100644 --- a/Duplicati/Library/SourceProvider/Builtin/FileRestoreDestinationProvider.cs +++ b/Duplicati/Library/SourceProvider/Builtin/FileRestoreDestinationProvider.cs @@ -152,7 +152,7 @@ public class FileRestoreDestinationProvider(string mountedPath, bool allowRestor var targetpath = isDirTarget ? path.Substring(0, path.Length - 1) : path; // Make the symlink first, otherwise we cannot apply metadata to it - if (metadata.TryGetValue("CoreSymlinkTarget", out var k)) + if (metadata.TryGetValue("CoreSymlinkTarget", out var k) && !string.IsNullOrWhiteSpace(k)) { if (!allowRestoreOutsideTargetDirectory && !string.IsNullOrWhiteSpace(TargetDestination)) { diff --git a/proprietary/Office365/RestoreProvider/RestoreProvider.Group.cs b/proprietary/Office365/RestoreProvider/RestoreProvider.Group.cs index bed3859f7..d469f3e16 100644 --- a/proprietary/Office365/RestoreProvider/RestoreProvider.Group.cs +++ b/proprietary/Office365/RestoreProvider/RestoreProvider.Group.cs @@ -623,7 +623,7 @@ public partial class RestoreProvider } // Remove the "/content.json" suffix to get the message path so replies can find it - var restoreMessagePath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath)); + var restoreMessagePath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath) ?? ""); if (!_ignoreExisting) { diff --git a/proprietary/Office365/RestoreProvider/RestoreProvider.OneNote.cs b/proprietary/Office365/RestoreProvider/RestoreProvider.OneNote.cs index 219f35db1..cda324c9b 100644 --- a/proprietary/Office365/RestoreProvider/RestoreProvider.OneNote.cs +++ b/proprietary/Office365/RestoreProvider/RestoreProvider.OneNote.cs @@ -256,7 +256,7 @@ public partial class RestoreProvider var displayName = metadata.GetValueOrDefault("o365:Name") ?? metadata.GetValueOrDefault("o365:DisplayName") ?? "Restored Section Group"; // Find parent - var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar))); + var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar)) ?? ""); string? parentId = null; bool isNotebookParent = false; @@ -310,7 +310,7 @@ public partial class RestoreProvider var displayName = metadata.GetValueOrDefault("o365:Name") ?? metadata.GetValueOrDefault("o365:DisplayName") ?? "Restored Section"; // Find parent - var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar))); + var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar)) ?? ""); string? parentId = null; bool isNotebookParent = false; @@ -360,7 +360,7 @@ public partial class RestoreProvider if (!filePath.EndsWith(".html", StringComparison.OrdinalIgnoreCase)) continue; - var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(filePath.TrimEnd(Path.DirectorySeparatorChar))); + var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(filePath.TrimEnd(Path.DirectorySeparatorChar)) ?? ""); if (parentPath == null) continue; diff --git a/proprietary/Office365/RestoreProvider/RestoreProvider.SharePointLists.cs b/proprietary/Office365/RestoreProvider/RestoreProvider.SharePointLists.cs index a2f71c438..b261ff328 100644 --- a/proprietary/Office365/RestoreProvider/RestoreProvider.SharePointLists.cs +++ b/proprietary/Office365/RestoreProvider/RestoreProvider.SharePointLists.cs @@ -240,7 +240,7 @@ public partial class RestoreProvider while (true) { - var parentDir = Util.AppendDirSeparator(Path.GetDirectoryName(currentPath.TrimEnd(Path.DirectorySeparatorChar))); + var parentDir = Util.AppendDirSeparator(Path.GetDirectoryName(currentPath.TrimEnd(Path.DirectorySeparatorChar)) ?? ""); if (string.IsNullOrEmpty(parentDir)) break; if (_restoredSharePointListMap.TryGetValue(parentDir, out var mappedListId)) @@ -307,7 +307,7 @@ public partial class RestoreProvider // Determine parent ID string parentId; - var itemParentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar))); + var itemParentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar)) ?? ""); try { @@ -441,7 +441,7 @@ public partial class RestoreProvider if (_restoredSharePointFolderMap.TryGetValue(currentPath, out var cachedId)) return cachedId; - var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(currentPath.TrimEnd(Path.DirectorySeparatorChar))); + var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(currentPath.TrimEnd(Path.DirectorySeparatorChar)) ?? ""); // Safety check to prevent infinite recursion if we go above listPath if (string.IsNullOrEmpty(parentPath) || currentPath.Length <= listPath.Length) diff --git a/proprietary/Office365/RestoreProvider/RestoreProvider.Tasks.cs b/proprietary/Office365/RestoreProvider/RestoreProvider.Tasks.cs index ee6d4d157..d2b01dd05 100644 --- a/proprietary/Office365/RestoreProvider/RestoreProvider.Tasks.cs +++ b/proprietary/Office365/RestoreProvider/RestoreProvider.Tasks.cs @@ -138,7 +138,7 @@ public partial class RestoreProvider var originalPath = task.Key; // Find parent list - var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar))); + var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar)) ?? ""); if (parentPath == null || !_restoredTaskListMap.TryGetValue(parentPath, out var listId)) { Log.WriteWarningMessage(LOGTAG, "RestoreTaskListTasksMissingParent", null, $"Could not find parent list for task {originalPath}, skipping."); @@ -213,7 +213,7 @@ public partial class RestoreProvider var parentDir = Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar)); // ChecklistItems if (parentDir == null) continue; - var taskPath = Util.AppendDirSeparator(Path.GetDirectoryName(parentDir)); // TaskId + var taskPath = Util.AppendDirSeparator(Path.GetDirectoryName(parentDir) ?? ""); // TaskId if (taskPath == null || !_restoredTaskMap.TryGetValue(taskPath, out var taskId)) { @@ -227,7 +227,7 @@ public partial class RestoreProvider var tasksDir = Path.GetDirectoryName(taskPath.TrimEnd(Path.DirectorySeparatorChar)); // Tasks if (tasksDir == null) continue; - var listPath = Util.AppendDirSeparator(Path.GetDirectoryName(tasksDir)); // ListId + var listPath = Util.AppendDirSeparator(Path.GetDirectoryName(tasksDir) ?? ""); // ListId if (listPath == null || !_restoredTaskListMap.TryGetValue(listPath, out var listId)) { @@ -273,7 +273,7 @@ public partial class RestoreProvider var parentDir = Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar)); // LinkedResources if (parentDir == null) continue; - var taskPath = Util.AppendDirSeparator(Path.GetDirectoryName(parentDir)); // TaskId + var taskPath = Util.AppendDirSeparator(Path.GetDirectoryName(parentDir) ?? ""); // TaskId if (taskPath == null || !_restoredTaskMap.TryGetValue(taskPath, out var taskId)) { @@ -285,7 +285,7 @@ public partial class RestoreProvider var tasksDir = Path.GetDirectoryName(taskPath.TrimEnd(Path.DirectorySeparatorChar)); // Tasks if (tasksDir == null) continue; - var listPath = Util.AppendDirSeparator(Path.GetDirectoryName(tasksDir)); // ListId + var listPath = Util.AppendDirSeparator(Path.GetDirectoryName(tasksDir) ?? ""); // ListId if (listPath == null || !_restoredTaskListMap.TryGetValue(listPath, out var listId)) { diff --git a/proprietary/Office365/RestoreProvider/RestoreProvider.cs b/proprietary/Office365/RestoreProvider/RestoreProvider.cs index b6e2842ce..af6823ef3 100644 --- a/proprietary/Office365/RestoreProvider/RestoreProvider.cs +++ b/proprietary/Office365/RestoreProvider/RestoreProvider.cs @@ -878,7 +878,7 @@ public partial class RestoreProvider : IRestoreDestinationProviderModule // Determine parent folder ID // We assume the path structure reflects the hierarchy // If parent path is not in map, we assume it's the root (mailboxId) - var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar))); + var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar)) ?? ""); var parentId = mailboxId; if (parentPath != null && _restoredEmailFolderMap.TryGetValue(parentPath, out var mappedParentId)) @@ -939,7 +939,7 @@ public partial class RestoreProvider : IRestoreDestinationProviderModule // Determine target folder var targetFolderId = mailboxId; - var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(emailSource.Key.TrimEnd(Path.DirectorySeparatorChar))); + var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(emailSource.Key.TrimEnd(Path.DirectorySeparatorChar)) ?? ""); if (parentPath != null && _restoredEmailFolderMap.TryGetValue(parentPath, out var mappedFolderId)) { targetFolderId = mappedFolderId; @@ -1068,7 +1068,7 @@ public partial class RestoreProvider : IRestoreDestinationProviderModule var restoreTarget = await DriveRestore.GetDefaultDriveAndFolder(cancel); if (!string.IsNullOrWhiteSpace(restoreTarget.FolderId)) { - var rootFolderPath = Util.AppendDirSeparator(Path.GetDirectoryName(sortedFolders.First().Key.TrimEnd(Path.DirectorySeparatorChar))); + var rootFolderPath = Util.AppendDirSeparator(Path.GetDirectoryName(sortedFolders.First().Key.TrimEnd(Path.DirectorySeparatorChar)) ?? ""); _restoredDriveFolderMap.AddOrUpdate(rootFolderPath, restoreTarget.FolderId, (k, v) => v); } @@ -1115,7 +1115,7 @@ public partial class RestoreProvider : IRestoreDestinationProviderModule } // Determine parent folder ID - var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar))); + var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar)) ?? ""); var parentId = defaultRootId; if (parentPath != null && (drivePath == null || parentPath.TrimEnd(Path.DirectorySeparatorChar) != drivePath.TrimEnd(Path.DirectorySeparatorChar))) @@ -1217,7 +1217,7 @@ public partial class RestoreProvider : IRestoreDestinationProviderModule } // Determine parent folder ID - var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar))); + var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar)) ?? ""); var parentId = defaultRootId; if (parentPath != null && (drivePath == null || parentPath.TrimEnd(Path.DirectorySeparatorChar) != drivePath.TrimEnd(Path.DirectorySeparatorChar))) @@ -1354,7 +1354,7 @@ public partial class RestoreProvider : IRestoreDestinationProviderModule // Group attachments by event path var attachments = GetMetadataByType(SourceItemType.CalendarEventAttachment) - .GroupBy(k => Util.AppendDirSeparator(Path.GetDirectoryName(k.Key.TrimEnd(Path.DirectorySeparatorChar)))) + .GroupBy(k => Util.AppendDirSeparator(Path.GetDirectoryName(k.Key.TrimEnd(Path.DirectorySeparatorChar)) ?? "")) .ToDictionary(g => g.Key, g => g.ToList()); var singles = new List<(string Path, GraphEvent Event)>(); @@ -1612,7 +1612,7 @@ public partial class RestoreProvider : IRestoreDestinationProviderModule } // Determine parent folder ID - var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar))); + var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar)) ?? ""); var parentId = defaultFolderId; if (parentPath != null && _restoredContactFolderMap.TryGetValue(parentPath, out var mappedParentId)) @@ -1672,7 +1672,7 @@ public partial class RestoreProvider : IRestoreDestinationProviderModule // Determine target folder var targetFolderId = defaultFolderId; - var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar))); + var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar)) ?? ""); if (parentPath != null && _restoredContactFolderMap.TryGetValue(parentPath, out var mappedFolderId)) { targetFolderId = mappedFolderId; @@ -1779,7 +1779,7 @@ public partial class RestoreProvider : IRestoreDestinationProviderModule // Determine target folder var targetFolderId = defaultFolderId; - var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar))); + var parentPath = Util.AppendDirSeparator(Path.GetDirectoryName(originalPath.TrimEnd(Path.DirectorySeparatorChar)) ?? ""); if (parentPath != null && _restoredContactFolderMap.TryGetValue(parentPath, out var mappedFolderId)) targetFolderId = mappedFolderId;