From: Kenneth Pouncey Date: Tue, 4 Aug 2020 14:57:14 +0000 (+0200) Subject: [browser][io] Workaround for issue MoveDirectory (#40310) X-Git-Tag: submit/tizen/20210909.063632~6238 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=21ea59f90044f4f662117fc43022f07eafb485cd;p=platform%2Fupstream%2Fdotnet%2Fruntime.git [browser][io] Workaround for issue MoveDirectory (#40310) * [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 * Update src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs Co-authored-by: Alexander Köplinger Co-authored-by: Alexander Köplinger --- 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 cb39fcb..df790a5 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,19 @@ namespace System.IO 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();