diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryFileValidator.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryFileValidator.cs
index f9cb1663..c3385ed3 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryFileValidator.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryFileValidator.cs
@@ -44,64 +44,40 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
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;
@@ -109,6 +85,32 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
#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)
{
Request req = new Request
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
index c5998361..1cd7062f 100755
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
@@ -1816,11 +1816,11 @@
- The provided path specifies a directory but a file path is required: {0}
+ Please provide a file path instead of directory path
- Cannot verify the existence of the backup file location: {0}
+ The provided path is invalid
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
index 1f4d4d4e..d54cadc3 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
@@ -808,8 +808,8 @@ prototype_file_noApplicableFileGroup = No Applicable Filegroup
BackupTaskName = Backup Database
# Backup File Validation Errors
-BackupPathIsFolderError = The provided path specifies a directory but a file path is required: {0}
-InvalidBackupPathError = Cannot verify the existence of the backup file location: {0}
+BackupPathIsFolderError = Please provide a file path instead of directory path
+InvalidBackupPathError = The provided path is invalid
############################################################################
# Task Service
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf
index 300a99d1..87074ef5 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf
@@ -2256,12 +2256,12 @@
- The provided path specifies a directory but a file path is required: {0}
+ Please provide a file path instead of directory path
The file name specified is also a directory name: {0}
- Cannot verify the existence of the backup file location: {0}
+ The provided path is invalid
Cannot verify the existence of the backup file location: {0}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/DisasterRecovery/DisasterRecoveryFileValidatorUnitTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/DisasterRecovery/DisasterRecoveryFileValidatorUnitTests.cs
index e038006e..6581a410 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/DisasterRecovery/DisasterRecoveryFileValidatorUnitTests.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/DisasterRecovery/DisasterRecoveryFileValidatorUnitTests.cs
@@ -14,11 +14,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.DisasterRecovery
public class DisasterRecoveryFileValidatorUnitTests
{
[Fact]
- public void ValidatorShouldReturnFalseForNullArgument()
+ public void ValidatorShouldReturnTrueForNullArgument()
{
string message;
bool result = DisasterRecoveryFileValidator.ValidatePaths(null, out message);
- Assert.False(result);
+ Assert.True(result);
}
[Fact]