Skip to content

Commit

Permalink
[browser][io] Workaround for issue MoveDirectory (#40310)
Browse files Browse the repository at this point in the history
* [browser][io] Workaround for issue MoveDirectory

- Issue workaround while waiting for emscripten fix.  #40305
- The following code checks for the existence of the source and destination directories which replaces the same code in the emscripten code.

emscripten tracking issue:  emscripten-core/emscripten#11804

* Update src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs

Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>

Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
  • Loading branch information
kjpou1 and akoeplinger authored Aug 4, 2020
1 parent c469ac9 commit 21ea59f
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,19 @@ public static void MoveDirectory(string sourceFullPath, string destFullPath)
throw new IOException(SR.Format(SR.IO_AlreadyExists_Name, destFullPath));
}

#if TARGET_BROWSER
// renaming a file doesn't return correct error code on emscripten if one of the parent paths does not exist,
// manually workaround it for now (https://github.com/dotnet/runtime/issues/40305)
if (!Directory.Exists(Path.GetDirectoryName(sourceFullPath)))
{
throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, sourceFullPath));
}
if (!Directory.Exists(Path.GetDirectoryName(destFullPath)))
{
throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, destFullPath));
}
#endif

if (Interop.Sys.Rename(sourceFullPath, destFullPath) < 0)
{
Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
Expand Down

0 comments on commit 21ea59f

Please sign in to comment.