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) public RestoreConfigInfoResponse CreateConfigInfoResponse(RestoreConfigInfoRequestParams restoreConfigInfoRequest)
{ {
RestoreConfigInfoResponse response = new RestoreConfigInfoResponse(); RestoreConfigInfoResponse response = new RestoreConfigInfoResponse();
RestoreDatabaseTaskDataObject restoreTaskObject = CreateRestoreForNewSession(restoreConfigInfoRequest.OwnerUri); RestoreDatabaseTaskDataObject restoreTaskObject = null;
if (restoreTaskObject != null)
try
{ {
// Default Data folder path in the target server restoreTaskObject = CreateRestoreForNewSession(restoreConfigInfoRequest.OwnerUri);
response.ConfigInfo.Add(RestoreOptionsHelper.DataFileFolder, restoreTaskObject.DefaultDataFileFolder); if (restoreTaskObject != null)
// Default log folder path in the target server {
response.ConfigInfo.Add(RestoreOptionsHelper.LogFileFolder, restoreTaskObject.DefaultLogFileFolder); // Default Data folder path in the target server
// The db names with backup set response.ConfigInfo.Add(RestoreOptionsHelper.DataFileFolder, restoreTaskObject.DefaultDataFileFolder);
response.ConfigInfo.Add(RestoreOptionsHelper.SourceDatabaseNamesWithBackupSets, restoreTaskObject.GetDatabaseNamesWithBackupSets()); // Default log folder path in the target server
// Default backup folder path in the target server response.ConfigInfo.Add(RestoreOptionsHelper.LogFileFolder, restoreTaskObject.DefaultLogFileFolder);
response.ConfigInfo.Add(RestoreOptionsHelper.DefaultBackupFolder, restoreTaskObject.DefaultBackupFolder); // 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; return response;
} }
/// <summary> /// <summary>
@@ -174,23 +192,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
if (connInfo != null) if (connInfo != null)
{ {
SqlConnection connection; SqlConnection connection = ConnectionService.OpenSqlConnection(connInfo, "Restore");
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;
}
Server server = new Server(new ServerConnection(connection)); Server server = new Server(new ServerConnection(connection));
RestoreDatabaseTaskDataObject restoreDataObject = new RestoreDatabaseTaskDataObject(server, targetDatabaseName); RestoreDatabaseTaskDataObject restoreDataObject = new RestoreDatabaseTaskDataObject(server, targetDatabaseName);

View File

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