From 795027efceb599dc62a8c7410fa3396d2460bac0 Mon Sep 17 00:00:00 2001 From: Vlad Zarytovskii Date: Mon, 15 Aug 2022 12:09:04 +0200 Subject: [PATCH 1/2] Fix: open shadowcopy file stream for RW --- src/Compiler/Utilities/FileSystem.fs | 6 ++--- .../Program.fs | 1 + .../Sample_ConsoleApp_net7.fsproj | 24 +++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 tests/projects/Sample_ConsoleApp_FileSystemTests/Program.fs create mode 100644 tests/projects/Sample_ConsoleApp_FileSystemTests/Sample_ConsoleApp_net7.fsproj diff --git a/src/Compiler/Utilities/FileSystem.fs b/src/Compiler/Utilities/FileSystem.fs index 791e829a36..7a48804d82 100644 --- a/src/Compiler/Utilities/FileSystem.fs +++ b/src/Compiler/Utilities/FileSystem.fs @@ -530,7 +530,7 @@ type DefaultFileSystem() as this = // We want to use mmaped files only when: // - Opening large binary files (no need to use for source or resource files really) - // - Running on mono, since its MemoryMappedFile implementation throws when "mapName" is not provided (is null). + // - Not running on mono, since its MemoryMappedFile implementation throws when "mapName" is not provided (is null). // (See: https://github.com/mono/mono/issues/10245) if not useMemoryMappedFile then @@ -542,12 +542,12 @@ type DefaultFileSystem() as this = MemoryMappedFile.CreateNew( null, length, - MemoryMappedFileAccess.Read, + MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, HandleInheritability.None ) - use stream = mmf.CreateViewStream(0L, length, MemoryMappedFileAccess.Read) + use stream = mmf.CreateViewStream(0L, length, MemoryMappedFileAccess.ReadWrite) fileStream.CopyTo(stream) fileStream.Dispose() mmf diff --git a/tests/projects/Sample_ConsoleApp_FileSystemTests/Program.fs b/tests/projects/Sample_ConsoleApp_FileSystemTests/Program.fs new file mode 100644 index 0000000000..75e0a053f4 --- /dev/null +++ b/tests/projects/Sample_ConsoleApp_FileSystemTests/Program.fs @@ -0,0 +1 @@ +[] let main _ = 0 diff --git a/tests/projects/Sample_ConsoleApp_FileSystemTests/Sample_ConsoleApp_net7.fsproj b/tests/projects/Sample_ConsoleApp_FileSystemTests/Sample_ConsoleApp_net7.fsproj new file mode 100644 index 0000000000..2b06247db9 --- /dev/null +++ b/tests/projects/Sample_ConsoleApp_FileSystemTests/Sample_ConsoleApp_net7.fsproj @@ -0,0 +1,24 @@ + + + + Exe + net6.0 + true + + + + $(MSBuildThisFileDirectory)../../../artifacts/bin/fsc/Debug/net6.0/fsc.dll + $(MSBuildThisFileDirectory)../../../artifacts/bin/fsc/Debug/net6.0/fsc.dll + False + True + + + + + + + + + + + From 11d9b08ac79767fb9825e0b5a7254bcc8c91b421 Mon Sep 17 00:00:00 2001 From: Vlad Zarytovskii Date: Mon, 15 Aug 2022 19:32:43 +0200 Subject: [PATCH 2/2] Update comment --- src/Compiler/Utilities/FileSystem.fs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Compiler/Utilities/FileSystem.fs b/src/Compiler/Utilities/FileSystem.fs index 7a48804d82..722978e851 100644 --- a/src/Compiler/Utilities/FileSystem.fs +++ b/src/Compiler/Utilities/FileSystem.fs @@ -530,8 +530,6 @@ type DefaultFileSystem() as this = // We want to use mmaped files only when: // - Opening large binary files (no need to use for source or resource files really) - // - Not running on mono, since its MemoryMappedFile implementation throws when "mapName" is not provided (is null). - // (See: https://github.com/mono/mono/issues/10245) if not useMemoryMappedFile then fileStream :> Stream