@@ -118,11 +118,38 @@ fn read_wasm(path: PathBuf) -> Result<Vec<u8>, String> {
118118 } )
119119}
120120
121+ fn preopen_dir < P : AsRef < Path > > ( path : P ) -> io:: Result < File > {
122+ #[ cfg( windows) ]
123+ {
124+ use std:: fs:: OpenOptions ;
125+ use std:: os:: windows:: fs:: OpenOptionsExt ;
126+ use winapi:: um:: winbase:: FILE_FLAG_BACKUP_SEMANTICS ;
127+
128+ // To open a directory using CreateFile2, specify the
129+ // FILE_FLAG_BACKUP_SEMANTICS flag as part of dwFileFlags...
130+ // cf. https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-createfile2
131+ OpenOptions :: new ( )
132+ . create ( false )
133+ . write ( true )
134+ . read ( true )
135+ . attributes ( FILE_FLAG_BACKUP_SEMANTICS )
136+ . open ( path)
137+ }
138+ #[ cfg( unix) ]
139+ {
140+ File :: open ( path)
141+ }
142+ #[ cfg( not( any( windows, unix) ) ) ]
143+ {
144+ unimplemented ! ( "this OS is currently not supported by Wasmtime" )
145+ }
146+ }
147+
121148fn compute_preopen_dirs ( flag_dir : & [ String ] , flag_mapdir : & [ String ] ) -> Vec < ( String , File ) > {
122149 let mut preopen_dirs = Vec :: new ( ) ;
123150
124151 for dir in flag_dir {
125- let preopen_dir = File :: open ( dir) . unwrap_or_else ( |err| {
152+ let preopen_dir = preopen_dir ( dir) . unwrap_or_else ( |err| {
126153 println ! ( "error while pre-opening directory {}: {}" , dir, err) ;
127154 exit ( 1 ) ;
128155 } ) ;
@@ -136,7 +163,7 @@ fn compute_preopen_dirs(flag_dir: &[String], flag_mapdir: &[String]) -> Vec<(Str
136163 exit ( 1 ) ;
137164 }
138165 let ( key, value) = ( parts[ 0 ] , parts[ 1 ] ) ;
139- let preopen_dir = File :: open ( value) . unwrap_or_else ( |err| {
166+ let preopen_dir = preopen_dir ( value) . unwrap_or_else ( |err| {
140167 println ! ( "error while pre-opening directory {}: {}" , value, err) ;
141168 exit ( 1 ) ;
142169 } ) ;
0 commit comments