fixed the issue with parsing a windows path was failing in mac (#503)

* fixed the issue with parsing a windows path was failing in mac
This commit is contained in:
Leila Lali
2017-10-18 12:02:24 -07:00
committed by GitHub
parent 4bf9b9ddae
commit 8db19d4b61
2 changed files with 31 additions and 29 deletions

View File

@@ -32,20 +32,38 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
public RestoreConfigInfoResponse CreateConfigInfoResponse(RestoreConfigInfoRequestParams restoreConfigInfoRequest)
{
RestoreConfigInfoResponse response = new RestoreConfigInfoResponse();
RestoreDatabaseTaskDataObject restoreTaskObject = CreateRestoreForNewSession(restoreConfigInfoRequest.OwnerUri);
if (restoreTaskObject != null)
RestoreDatabaseTaskDataObject restoreTaskObject = null;
try
{
// Default Data folder path in the target server
response.ConfigInfo.Add(RestoreOptionsHelper.DataFileFolder, restoreTaskObject.DefaultDataFileFolder);
// Default log folder path in the target server
response.ConfigInfo.Add(RestoreOptionsHelper.LogFileFolder, restoreTaskObject.DefaultLogFileFolder);
// The db names with backup set
response.ConfigInfo.Add(RestoreOptionsHelper.SourceDatabaseNamesWithBackupSets, restoreTaskObject.GetDatabaseNamesWithBackupSets());
// Default backup folder path in the target server
response.ConfigInfo.Add(RestoreOptionsHelper.DefaultBackupFolder, restoreTaskObject.DefaultBackupFolder);
restoreTaskObject = CreateRestoreForNewSession(restoreConfigInfoRequest.OwnerUri);
if (restoreTaskObject != null)
{
// Default Data folder path in the target server
response.ConfigInfo.Add(RestoreOptionsHelper.DataFileFolder, restoreTaskObject.DefaultDataFileFolder);
// Default log folder path in the target server
response.ConfigInfo.Add(RestoreOptionsHelper.LogFileFolder, restoreTaskObject.DefaultLogFileFolder);
// The db names with backup set
response.ConfigInfo.Add(RestoreOptionsHelper.SourceDatabaseNamesWithBackupSets, restoreTaskObject.GetDatabaseNamesWithBackupSets());
// Default backup folder path in the target server
response.ConfigInfo.Add(RestoreOptionsHelper.DefaultBackupFolder, restoreTaskObject.DefaultBackupFolder);
}
}
catch(Exception ex)
{
Logger.Write(LogLevel.Warning, $"Failed to create restore config info. error: { ex.Message}");
response.ErrorMessage = ex.Message;
}
finally
{
ServerConnection serverConnection = restoreTaskObject?.Server?.ConnectionContext;
if (serverConnection != null && serverConnection.IsOpen)
{
restoreTaskObject.Server.ConnectionContext.Disconnect();
}
}
return response;
}
/// <summary>
@@ -174,23 +192,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
if (connInfo != null)
{
SqlConnection connection;
DbConnection dbConnection = connInfo.AllConnections.First();
ReliableSqlConnection reliableSqlConnection = dbConnection as ReliableSqlConnection;
SqlConnection sqlConnection = dbConnection as SqlConnection;
if (reliableSqlConnection != null)
{
connection = reliableSqlConnection.GetUnderlyingConnection();
}
else if (sqlConnection != null)
{
connection = sqlConnection;
}
else
{
Logger.Write(LogLevel.Warning, "Cannot find any sql connection for restore operation");
return null;
}
SqlConnection connection = ConnectionService.OpenSqlConnection(connInfo, "Restore");
Server server = new Server(new ServerConnection(connection));
RestoreDatabaseTaskDataObject restoreDataObject = new RestoreDatabaseTaskDataObject(server, targetDatabaseName);

View File

@@ -794,7 +794,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
/// <returns></returns>
private string GetTargetDbFilePhysicalName(string sourceDbFilePhysicalLocation)
{
string pathSeparator = PathWrapper.PathSeparatorFromServerConnection(Server.ConnectionContext);
string pathSeparator = Path.DirectorySeparatorChar.ToString();
sourceDbFilePhysicalLocation = sourceDbFilePhysicalLocation.Replace("/", pathSeparator);
sourceDbFilePhysicalLocation = sourceDbFilePhysicalLocation.Replace("\\", pathSeparator);
string fileName = Path.GetFileName(sourceDbFilePhysicalLocation);