From 66db1395ad5b8566955b225fd3b2cb8a9858ab13 Mon Sep 17 00:00:00 2001 From: Kenneth Pouncey Date: Tue, 4 Aug 2020 13:40:09 +0200 Subject: [PATCH 1/2] [browser][io] Workaround for issue MoveDirectory - Issue workaround while waiting for emscripten fix. https://github.com/dotnet/runtime/issues/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: https://github.com/emscripten-core/emscripten/issues/11804 --- .../src/System/IO/FileSystem.Unix.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs b/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs index cb39fcb7e03047..f27d70937c7394 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs @@ -381,6 +381,17 @@ public static void MoveDirectory(string sourceFullPath, string destFullPath) throw new IOException(SR.Format(SR.IO_AlreadyExists_Name, destFullPath)); } +#if TARGET_BROWSER + 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(); From 04981ba103ee36fda76e678400afb8cb150273f5 Mon Sep 17 00:00:00 2001 From: Kenneth Pouncey Date: Tue, 4 Aug 2020 15:39:22 +0200 Subject: [PATCH 2/2] Update src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alexander Köplinger --- .../System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs b/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs index f27d70937c7394..df790a51b8d9f6 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs @@ -382,6 +382,8 @@ public static void MoveDirectory(string sourceFullPath, string 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));