@@ -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,63 +942,64 @@ type LayeredMultiMap<'Key,'Value when 'Key : equality and 'Key : comparison>(con
942942module Shim =
943943
944944 open System.IO
945-
946- type IFileSystem =
945+ [<AbstractClass>]
946+ type FileSystem () =
947947 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
954+
948955 abstract FileStreamReadShim: fileName : string -> System.IO.Stream
949956 abstract FileStreamCreateShim: fileName : string -> System.IO.Stream
950- abstract FileStreamWriteExistingShim : fileName : string -> System.IO.Stream
957+ abstract GetFullPathShim : fileName : string -> string
951958 /// Take in a filename with an absolute path, and return the same filename
952959 /// but canonicalized with respect to extra path separators (e.g. C:\\\\foo.txt)
953960 /// and '..' portions
954- abstract GetFullPathShim : fileName : string -> string
961+ abstract SafeGetFullPath : fileName : string -> string
955962 abstract IsPathRootedShim: path : string -> bool
956- abstract IsInvalidPathShim: filename : string -> bool
963+
964+ abstract IsInvalidFilename: filename : string -> bool
957965 abstract GetTempPathShim : unit -> string
958966 abstract GetLastWriteTimeShim: fileName : string -> System.DateTime
959967 abstract SafeExists: fileName : string -> bool
960968 abstract FileDelete: fileName : string -> unit
961969 abstract AssemblyLoadFrom: fileName : string -> System.Reflection.Assembly
962970 abstract AssemblyLoad: assemblyName : System.Reflection.AssemblyName -> System.Reflection.Assembly
963971
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
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
975984 member __.FileStreamReadShim ( fileName : string ) = new FileStream( fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite) :> Stream
976985 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
978986 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
979990
980991 member __.IsPathRootedShim ( path : string ) = Path.IsPathRooted path
981992
982- member __.IsInvalidPathShim ( path : string ) =
983- let isInvalidPath ( p : string ) =
984- String.IsNullOrEmpty( p) || p.IndexOfAny( System.IO.Path.GetInvalidPathChars()) <> - 1
985-
986- let isInvalidDirectory ( d : string ) =
987- d= null || d.IndexOfAny( Path.GetInvalidPathChars()) <> - 1
988-
989- isInvalidPath ( path) ||
990- let directory = Path.GetDirectoryName( path)
991- let filename = Path.GetFileName( path)
992- isInvalidDirectory( directory) || isInvalidPath( filename)
993+ member __.IsInvalidFilename ( filename : string ) =
994+ String.IsNullOrEmpty( filename) || filename.IndexOfAny( Path.GetInvalidFileNameChars()) <> - 1
993995
994996 member __.GetTempPathShim () = System.IO.Path.GetTempPath()
995997
996998 member __.GetLastWriteTimeShim ( fileName : string ) = File.GetLastWriteTime fileName
997999 member __.SafeExists ( fileName : string ) = System.IO.File.Exists fileName
998- member __.FileDelete ( fileName : string ) = System.IO.File.Delete fileName
1000+ member __.FileDelete ( fileName : string ) = System.IO.File.Delete fileName }
9991001
10001002 type System.Text.Encoding with
10011003 static member GetEncodingShim ( n : int ) =
10021004 System.Text.Encoding.GetEncoding( n)
10031005
1004- let mutable FileSystem = DefaultFileSystem() :> IFileSystem
0 commit comments