@@ -620,7 +620,7 @@ module Eventually =
620620
621621 let force e = Option.get ( forceWhile ( fun () -> true ) e)
622622
623- /// Keep running the computation bit by bit until a time limit is reached.
623+ /// Keep running the computation bit by bit until a time limit is reached.
624624 /// The runner gets called each time the computation is restarted
625625 let repeatedlyProgressUntilDoneOrTimeShareOver timeShareInMilliseconds runner e =
626626 let sw = new System.Diagnostics.Stopwatch()
@@ -942,64 +942,66 @@ type LayeredMultiMap<'Key,'Value when 'Key : equality and 'Key : comparison>(con
942942module Shim =
943943
944944 open System.IO
945- [<AbstractClass>]
946- type FileSystem () =
947- abstract ReadAllBytesShim: fileName : string -> byte []
948- default this.ReadAllBytesShim ( fileName : string ) =
949- use stream = this.FileStreamReadShim fileName
950- let len = stream.Length
951- let buf = Array.zeroCreate< byte> ( int len)
952- stream.Read( buf, 0 , ( int len)) |> ignore
953- buf
954945
946+ type IFileSystem =
947+ abstract ReadAllBytesShim: fileName : string -> byte []
955948 abstract FileStreamReadShim: fileName : string -> System.IO.Stream
956949 abstract FileStreamCreateShim: fileName : string -> System.IO.Stream
957- abstract GetFullPathShim : fileName : string -> string
950+ abstract FileStreamWriteExistingShim : fileName : string -> System.IO.Stream
958951 /// Take in a filename with an absolute path, and return the same filename
959952 /// but canonicalized with respect to extra path separators (e.g. C:\\\\foo.txt)
960953 /// and '..' portions
961- abstract SafeGetFullPath : fileName : string -> string
954+ abstract GetFullPathShim : fileName : string -> string
962955 abstract IsPathRootedShim: path : string -> bool
963-
964- abstract IsInvalidFilename: filename : string -> bool
956+ abstract IsInvalidPathShim: filename : string -> bool
965957 abstract GetTempPathShim : unit -> string
966958 abstract GetLastWriteTimeShim: fileName : string -> System.DateTime
967959 abstract SafeExists: fileName : string -> bool
968960 abstract FileDelete: fileName : string -> unit
969961 abstract AssemblyLoadFrom: fileName : string -> System.Reflection.Assembly
970962 abstract AssemblyLoad: assemblyName : System.Reflection.AssemblyName -> System.Reflection.Assembly
971963
972- default this.AssemblyLoadFrom ( fileName : string ) =
973- #if FX_ ATLEAST_ 40_ COMPILER_ LOCATION
974- System.Reflection.Assembly.UnsafeLoadFrom fileName
975- #else
976- System.Reflection.Assembly.LoadFrom fileName
977- #endif
978- default this.AssemblyLoad ( assemblyName : System.Reflection.AssemblyName ) = System.Reflection.Assembly.Load assemblyName
979-
980-
981- let mutable FileSystem =
982- { new FileSystem() with
983- override __.ReadAllBytesShim ( fileName : string ) = File.ReadAllBytes fileName
964+ type DefaultFileSystem () =
965+ interface IFileSystem with
966+ member __.AssemblyLoadFrom ( fileName : string ) =
967+ #if FX_ ATLEAST_ 40_ COMPILER_ LOCATION
968+ System.Reflection.Assembly.UnsafeLoadFrom fileName
969+ #else
970+ System.Reflection.Assembly.LoadFrom fileName
971+ #endif
972+ member __.AssemblyLoad ( assemblyName : System.Reflection.AssemblyName ) = System.Reflection.Assembly.Load assemblyName
973+
974+ member __.ReadAllBytesShim ( fileName : string ) = File.ReadAllBytes fileName
984975 member __.FileStreamReadShim ( fileName : string ) = new FileStream( fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite) :> Stream
985976 member __.FileStreamCreateShim ( fileName : string ) = new FileStream( fileName, FileMode.Create, FileAccess.Write, FileShare.Read , 0x1000 , false ) :> Stream
977+ member __.FileStreamWriteExistingShim ( fileName : string ) = new FileStream( fileName, FileMode.Open, FileAccess.Write, FileShare.Read , 0x1000 , false ) :> Stream
986978 member __.GetFullPathShim ( fileName : string ) = System.IO.Path.GetFullPath fileName
987- member __.SafeGetFullPath ( fileName : string ) =
988- //System.Diagnostics.Debug.Assert(Path.IsPathRooted(fileName), sprintf "SafeGetFullPath: '%s' is not absolute" fileName)
989- Path.GetFullPath fileName
990979
991980 member __.IsPathRootedShim ( path : string ) = Path.IsPathRooted path
992981
993- member __.IsInvalidFilename ( filename : string ) =
994- String.IsNullOrEmpty( filename) || filename.IndexOfAny( Path.GetInvalidFileNameChars()) <> - 1
982+ member __.IsInvalidPathShim ( path : string ) =
983+ let isInvalidPath ( p : string ) =
984+ String.IsNullOrEmpty( p) || p.IndexOfAny( System.IO.Path.GetInvalidPathChars()) <> - 1
985+
986+ let isInvalidFilename ( p : string ) =
987+ String.IsNullOrEmpty( p) || p.IndexOfAny( System.IO.Path.GetInvalidFileNameChars()) <> - 1
988+
989+ let isInvalidDirectory ( d : string ) =
990+ d= null || d.IndexOfAny( Path.GetInvalidPathChars()) <> - 1
991+
992+ isInvalidPath ( path) ||
993+ let directory = Path.GetDirectoryName( path)
994+ let filename = Path.GetFileName( path)
995+ isInvalidDirectory( directory) || isInvalidFilename( filename)
995996
996997 member __.GetTempPathShim () = System.IO.Path.GetTempPath()
997998
998999 member __.GetLastWriteTimeShim ( fileName : string ) = File.GetLastWriteTime fileName
9991000 member __.SafeExists ( fileName : string ) = System.IO.File.Exists fileName
1000- member __.FileDelete ( fileName : string ) = System.IO.File.Delete fileName }
1001+ member __.FileDelete ( fileName : string ) = System.IO.File.Delete fileName
10011002
10021003 type System.Text.Encoding with
10031004 static member GetEncodingShim ( n : int ) =
10041005 System.Text.Encoding.GetEncoding( n)
10051006
1007+ let mutable FileSystem = DefaultFileSystem() :> IFileSystem
0 commit comments