mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -05:00
Fix backup file validation error message (#472)
* Fix backup error message * check for file existence for restore * chang error message * address pr comment * cleanup
This commit is contained in:
@@ -44,64 +44,40 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
|
|||||||
connection = ReliableConnectionHelper.GetAsSqlConnection(dbConnection);
|
connection = ReliableConnectionHelper.GetAsSqlConnection(dbConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection != null)
|
|
||||||
{
|
|
||||||
bool isLocal = false;
|
|
||||||
if (string.Compare(GetMachineName(connection.DataSource), Environment.MachineName, StringComparison.OrdinalIgnoreCase) == 0)
|
|
||||||
{
|
|
||||||
isLocal = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (string filePath in args.FilePaths)
|
|
||||||
{
|
|
||||||
bool isFolder;
|
|
||||||
bool existing = IsPathExisting(connection, filePath, out isFolder);
|
|
||||||
|
|
||||||
if (existing)
|
|
||||||
{
|
|
||||||
if (isFolder)
|
|
||||||
{
|
|
||||||
errorMessage = string.Format(SR.BackupPathIsFolderError, filePath);
|
|
||||||
result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// If the file path doesn't exist, check if the folder exists
|
|
||||||
string folderPath = PathWrapper.GetDirectoryName(filePath);
|
|
||||||
if (isLocal)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(folderPath) && !Directory.Exists(folderPath))
|
|
||||||
{
|
|
||||||
errorMessage = string.Format(SR.InvalidBackupPathError, folderPath);
|
|
||||||
result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bool isFolderOnRemote;
|
|
||||||
bool existsOnRemote = IsPathExisting(connection, folderPath, out isFolderOnRemote);
|
|
||||||
if (!existsOnRemote)
|
|
||||||
{
|
|
||||||
errorMessage = string.Format(SR.InvalidBackupPathError, folderPath);
|
|
||||||
result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (connection != null)
|
||||||
{
|
{
|
||||||
result = false;
|
foreach (string filePath in args.FilePaths)
|
||||||
|
{
|
||||||
|
bool isFolder;
|
||||||
|
bool existing = IsPathExisting(connection, filePath, out isFolder);
|
||||||
|
|
||||||
|
if (existing)
|
||||||
|
{
|
||||||
|
if (isFolder)
|
||||||
|
{
|
||||||
|
errorMessage = SR.BackupPathIsFolderError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (args.ServiceType == FileValidationServiceConstants.Backup)
|
||||||
|
{
|
||||||
|
errorMessage = IsFolderPathExisting(connection, filePath);
|
||||||
|
}
|
||||||
|
else if (args.ServiceType == FileValidationServiceConstants.Restore)
|
||||||
|
{
|
||||||
|
errorMessage = SR.InvalidBackupPathError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(errorMessage))
|
||||||
|
{
|
||||||
|
result = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -109,6 +85,32 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
|
|||||||
|
|
||||||
#region private methods
|
#region private methods
|
||||||
|
|
||||||
|
internal static string IsFolderPathExisting(SqlConnection connection, string filePath)
|
||||||
|
{
|
||||||
|
// If the file path doesn't exist, check if the folder exists
|
||||||
|
string folderPath = PathWrapper.GetDirectoryName(filePath);
|
||||||
|
string errorMessage = string.Empty;
|
||||||
|
|
||||||
|
if (string.Compare(GetMachineName(connection.DataSource), Environment.MachineName, StringComparison.OrdinalIgnoreCase) == 0)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(folderPath) && !Directory.Exists(folderPath))
|
||||||
|
{
|
||||||
|
errorMessage = SR.InvalidBackupPathError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool isFolderOnRemote;
|
||||||
|
bool existsOnRemote = IsPathExisting(connection, folderPath, out isFolderOnRemote);
|
||||||
|
if (!existsOnRemote)
|
||||||
|
{
|
||||||
|
errorMessage = SR.InvalidBackupPathError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
internal static bool IsPathExisting(SqlConnection connection, string path, out bool isFolder)
|
internal static bool IsPathExisting(SqlConnection connection, string path, out bool isFolder)
|
||||||
{
|
{
|
||||||
Request req = new Request
|
Request req = new Request
|
||||||
|
|||||||
@@ -1816,11 +1816,11 @@
|
|||||||
<comment></comment>
|
<comment></comment>
|
||||||
</data>
|
</data>
|
||||||
<data name="BackupPathIsFolderError" xml:space="preserve">
|
<data name="BackupPathIsFolderError" xml:space="preserve">
|
||||||
<value>The provided path specifies a directory but a file path is required: {0}</value>
|
<value>Please provide a file path instead of directory path</value>
|
||||||
<comment></comment>
|
<comment></comment>
|
||||||
</data>
|
</data>
|
||||||
<data name="InvalidBackupPathError" xml:space="preserve">
|
<data name="InvalidBackupPathError" xml:space="preserve">
|
||||||
<value> Cannot verify the existence of the backup file location: {0}</value>
|
<value> The provided path is invalid</value>
|
||||||
<comment></comment>
|
<comment></comment>
|
||||||
</data>
|
</data>
|
||||||
<data name="TaskInProgress" xml:space="preserve">
|
<data name="TaskInProgress" xml:space="preserve">
|
||||||
|
|||||||
@@ -808,8 +808,8 @@ prototype_file_noApplicableFileGroup = No Applicable Filegroup
|
|||||||
BackupTaskName = Backup Database
|
BackupTaskName = Backup Database
|
||||||
|
|
||||||
# Backup File Validation Errors
|
# Backup File Validation Errors
|
||||||
BackupPathIsFolderError = The provided path specifies a directory but a file path is required: {0}
|
BackupPathIsFolderError = Please provide a file path instead of directory path
|
||||||
InvalidBackupPathError = Cannot verify the existence of the backup file location: {0}
|
InvalidBackupPathError = The provided path is invalid
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
# Task Service
|
# Task Service
|
||||||
|
|||||||
@@ -2256,12 +2256,12 @@
|
|||||||
<note></note>
|
<note></note>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="BackupPathIsFolderError">
|
<trans-unit id="BackupPathIsFolderError">
|
||||||
<source>The provided path specifies a directory but a file path is required: {0}</source>
|
<source>Please provide a file path instead of directory path</source>
|
||||||
<target state="new">The file name specified is also a directory name: {0}</target>
|
<target state="new">The file name specified is also a directory name: {0}</target>
|
||||||
<note></note>
|
<note></note>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="InvalidBackupPathError">
|
<trans-unit id="InvalidBackupPathError">
|
||||||
<source> Cannot verify the existence of the backup file location: {0}</source>
|
<source> The provided path is invalid</source>
|
||||||
<target state="new"> Cannot verify the existence of the backup file location: {0}</target>
|
<target state="new"> Cannot verify the existence of the backup file location: {0}</target>
|
||||||
<note></note>
|
<note></note>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.DisasterRecovery
|
|||||||
public class DisasterRecoveryFileValidatorUnitTests
|
public class DisasterRecoveryFileValidatorUnitTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ValidatorShouldReturnFalseForNullArgument()
|
public void ValidatorShouldReturnTrueForNullArgument()
|
||||||
{
|
{
|
||||||
string message;
|
string message;
|
||||||
bool result = DisasterRecoveryFileValidator.ValidatePaths(null, out message);
|
bool result = DisasterRecoveryFileValidator.ValidatePaths(null, out message);
|
||||||
Assert.False(result);
|
Assert.True(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
Reference in New Issue
Block a user