Skip to content

Commit 387d20a

Browse files
TIHanbaronfel
authored andcommitted
Fixed exception that prevented creating a memory mapped file that shadow copies a file on-disk (#8238)
* Fixed exception that prevented creating a memory mapped file that is shadow copied * Update bytes.fs
1 parent 843af34 commit 387d20a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/absil/bytes.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,11 @@ type ByteMemory with
306306
leaveOpen=false)
307307
mmf, mmf.CreateViewAccessor(0L, length, memoryMappedFileAccess), length
308308

309+
// Validate MMF with the access that was intended.
309310
match access with
310-
| FileAccess.Read when not accessor.CanRead -> failwith "Cannot read file"
311-
| FileAccess.Write when not accessor.CanWrite -> failwith "Cannot write file"
312-
| _ when not accessor.CanRead || not accessor.CanWrite -> failwith "Cannot read or write file"
311+
| FileAccess.Read when not accessor.CanRead -> invalidOp "Cannot read file"
312+
| FileAccess.Write when not accessor.CanWrite -> invalidOp "Cannot write file"
313+
| FileAccess.ReadWrite when not accessor.CanRead || not accessor.CanWrite -> invalidOp "Cannot read or write file"
313314
| _ -> ()
314315

315316
let safeHolder =

0 commit comments

Comments
 (0)