Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/SmoFacade/BackupFileTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any upstream dependency breaking cause it was relying on UNC urls to succeed here which it won't now do?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my knowledge no, but I'll see if I can't confirm that through unit tests.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, that should be good enough, the lib version upgrade can always be backed out and fixed during server integration

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually can't find an example of this. From what I gather, a network file represented through a UNC path should always be a FILE device type.

As far as I can tell, URL device types should only be used when backing up to Azure Blob Storage or S3-compatible object storage. I think the current test cases for URLs effectively cover these cases.

In other words, I don't think we should ever have a case where a UNC path should be identified as a URL device type.

&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps)
&& Path.HasExtension(path);
}

Expand Down Expand Up @@ -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; }
Expand Down
12 changes: 9 additions & 3 deletions tests/AgDatabaseMove.Unit/FileToolsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -61,6 +58,12 @@ 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));
Expand All @@ -83,6 +86,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));
Expand Down