From 2fceb217ba71cc3cc652196964df852a263c8909 Mon Sep 17 00:00:00 2001 From: marana Date: Wed, 11 Feb 2026 13:36:34 -0600 Subject: [PATCH 1/2] fix(backup): device type --- src/SmoFacade/BackupFileTools.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SmoFacade/BackupFileTools.cs b/src/SmoFacade/BackupFileTools.cs index 96bbb32..9eb1c56 100755 --- a/src/SmoFacade/BackupFileTools.cs +++ b/src/SmoFacade/BackupFileTools.cs @@ -17,7 +17,7 @@ public enum BackupType public static bool IsValidFileUrl(string path) { return Uri.TryCreate(path, UriKind.Absolute, out var uriResult) - && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps || uriResult.IsUnc) + && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps) && Path.HasExtension(path); } From 7b63020e15ad78cdd2b1d051dc7da01d1575043c Mon Sep 17 00:00:00 2001 From: marana Date: Wed, 25 Feb 2026 20:14:52 -0600 Subject: [PATCH 2/2] fix(tests): IsPathRooted not OS agnostic --- src/SmoFacade/BackupFileTools.cs | 13 ++++++++++++- tests/AgDatabaseMove.Unit/FileToolsTest.cs | 13 +++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/SmoFacade/BackupFileTools.cs b/src/SmoFacade/BackupFileTools.cs index 9eb1c56..31f4dee 100755 --- a/src/SmoFacade/BackupFileTools.cs +++ b/src/SmoFacade/BackupFileTools.cs @@ -58,13 +58,24 @@ public static bool IsValidFilePath(string path) // This will throw an argument exception if the path is invalid Path.GetFullPath(path); // A relative path won't help us much if the destination is another server. It needs to be rooted. - return Path.IsPathRooted(path) && Path.HasExtension(path); + return (Path.IsPathRooted(path) || IsUncPath(path)) && Path.HasExtension(path); } catch(Exception) { return false; } } + private static bool IsUncPath(string path) + { + try { + var uri = new Uri(path); + return uri.IsUnc; + } + catch { + return false; + } + } + public static string CombinePaths(string path1, string path2) { if (string.IsNullOrEmpty(path1)) { return path2; } diff --git a/tests/AgDatabaseMove.Unit/FileToolsTest.cs b/tests/AgDatabaseMove.Unit/FileToolsTest.cs index 2546c49..df81775 100755 --- a/tests/AgDatabaseMove.Unit/FileToolsTest.cs +++ b/tests/AgDatabaseMove.Unit/FileToolsTest.cs @@ -15,9 +15,6 @@ public class BackupFileToolsTest [InlineData(@"https://storage-account.blob.core.windows.net/container/file.bad")] [InlineData(@"https://storage-account.blob.core.windows.net/container/sql/db_name/backup_2020_09_02_170003_697.trn")] [InlineData(@"http://a.bak")] - [InlineData(@"\\UNC\syntax\path\file.ext")] - [InlineData(@"\\server\file.ext")] - [InlineData(@"//Unix/syntax/file.ext")] public void ValidUrlTests(string url) { Assert.True(BackupFileTools.IsValidFileUrl(url)); @@ -59,8 +56,13 @@ public void BackupTypeAbbrevToType(string abbrev, BackupFileTools.BackupType typ } [Theory] - [InlineData(@"C:\dir\file.ext")] [InlineData(@"/some/file.ext")] + [InlineData(@"\\UNC\syntax\path\file.ext")] + [InlineData(@"\\server\file.ext")] + [InlineData(@"//Unix/syntax/file.ext")] + [InlineData(@"\\backup-server\dfs\backup\database.bak")] + [InlineData(@"\\storage-array\shared\backups\full_backup.full")] + [InlineData(@"\\network-storage\logs\transaction_log.trn")] public void ValidPathTests(string path) { Assert.True(BackupFileTools.IsValidFilePath(path)); @@ -83,6 +85,9 @@ public void ValidPathTests(string path) [InlineData(@"C:/is/not\valid")] [InlineData(@"C:\is\not\/valid")] [InlineData(@"C:/is/not/\valid")] + [InlineData(@"\\server")] + [InlineData(@"\\server\dir")] + [InlineData(@"\\server\dir\")] public void InValidPathTests(string path) { Assert.False(BackupFileTools.IsValidFilePath(path));