From ba359e7a687e6d75b567e995dbfee486358f00dc Mon Sep 17 00:00:00 2001 From: Leila Lali Date: Mon, 6 Nov 2017 12:12:52 -0800 Subject: [PATCH] fix the file path with the wrong path separator (#545) * fix the file path with the wrong path separator * fixed a typo --- .../RestoreDatabaseTaskDataObject.cs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/RestoreOperation/RestoreDatabaseTaskDataObject.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/RestoreOperation/RestoreDatabaseTaskDataObject.cs index 7e2fda66..ede25b08 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/RestoreOperation/RestoreDatabaseTaskDataObject.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/RestoreOperation/RestoreDatabaseTaskDataObject.cs @@ -637,7 +637,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation { if (!string.IsNullOrEmpty(this.DataFilesFolder)) { - dbFile.PhysicalNameRelocate = PathWrapper.Combine(this.DataFilesFolder, fileName); + dbFile.PhysicalNameRelocate = CombineToServerConnectionPath(this.DataFilesFolder, fileName); } else { @@ -648,7 +648,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation { if (!string.IsNullOrEmpty(this.LogFilesFolder)) { - dbFile.PhysicalNameRelocate = PathWrapper.Combine(this.LogFilesFolder, fileName); + dbFile.PhysicalNameRelocate = CombineToServerConnectionPath(this.LogFilesFolder, fileName); } else { @@ -663,6 +663,23 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation } } + /// + /// Combining the root and file name using the server connection file path seperator + /// + private string CombineToServerConnectionPath(string root, string filePath) + { + string pathSeparatorFromServerConnection = PathWrapper.PathSeparatorFromServerConnection(Server.ConnectionContext); + string combinedPath = PathWrapper.Combine(root, filePath); + + // Make sure all path seperators are server connection separator + string result = combinedPath.Replace(Path.DirectorySeparatorChar.ToString(), pathSeparatorFromServerConnection); + + // Make sure there's not any double file seperator in the path + result = result.Replace(pathSeparatorFromServerConnection + pathSeparatorFromServerConnection, + pathSeparatorFromServerConnection); + return result; + } + /// /// Updates the Restore folder location of those db files whose orginal directory location /// is not present in the destination computer.