fix(IsValidFilePath): Can now validate Windows UNC paths on Unix runtime#64
Conversation
updating from upstream
Updating from upstream
|
Alex Irion (@alexirion10) Ryan Clare (@Kaneraz) AgDatabaseMove/src/SmoFacade/BackupFileTools.cs Lines 16 to 19 in babf28a |
Alex Irion (alexirion10)
left a comment
There was a problem hiding this comment.
Looks good. Ya you should be able to use new Uri constructor on URLs instead of the regex.
I thought we were done with DFS backup paths by now...
|
Cool, will change that function too. |
…g the UNC check inside that as well
|
Alex Irion (@alexirion10) I'm just wondering now, do we really need all these checks for the url/path. I believe invalid, relative and incorrect paths/urls would error out naturally when you try to use it? Moreover, I believe having these silent filters here could lead to a head scratching problem for users as their files would mysteriously disappear in the backup chain without any warnings in some cases. What's your view on this? |
|
Aditya Niraula (@AdityaNPL) - for FireFish that might be the case, but not for the rest of the usecase in this repository. |
|
My opinion here is that we can treat our functions in this module (like I believe, this will keep things loosely-coupled and we won't have to handle edge-cases like these in the future. To address this particular example: AgDatabaseMove/src/AgDatabaseMove.cs Line 76 in babf28a looks like under the hood it calls this SMO function: AgDatabaseMove/src/SmoFacade/Server.cs Line 164 in babf28a So I was thinking a better design would be to let the SMO function raise an exception during the restore process if it can't get the file for any reason. We can then propagate the error back to the user. |
|
You're then going to need to check file validity in every consuming location, hence duplicating that code and logic everywhere. I don't want to go down that path. |
Just re-read my comment above and looks like it was a bit confusing here. For the functions in this tool that consume the backup chain, the functions can just return the same error they get from the underlying SMO functions - so no need to duplicate any logic anywhere. |
|
Had a conversation with Alex Irion (@alexirion10) offline about this. We came to the conclusion that there may be some aspects of For this PR we decided to keep it simple and just change the url/path checks and the respective tests. However, I want to see if we can remove these checks easily. |
Tests and function names changed to reflect the same
Before,
Path.IsPathRooted(meta.PhysicalDeviceName);would return false for Windows UNC paths on Unix runtime due to a difference in dotnet's implementation of the function for the diff runtimes:Windows Runtime: https://github.com/dotnet/runtime/blob/44f8f0faee42367bdd39277d8295f6e914ad7f4a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs#L194
vs.
Unix Runtime: https://github.com/dotnet/runtime/blob/44f8f0faee42367bdd39277d8295f6e914ad7f4a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Unix.cs#L113
This would lead to backup files being filtered out and an exception being thrown during the creation of the backup chain.
Now we use the
IsUncproperty of theUriclass to detect UNC paths and since UNCs have to be fully-qualified by design, we can validate them straight away (just like how we do for URLs).Have also made a few refactors to ease testing of this new approach.