File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -235,6 +235,16 @@ mod test {
235
235
panic ! ( "Could not determine process umask" )
236
236
}
237
237
238
+ /// Older Windows versions don't support removing open files
239
+ fn os_supports_unlinked_tmp ( d : & Dir ) -> bool {
240
+ if cfg ! ( not( windows) ) {
241
+ return true ;
242
+ }
243
+ let name = "testfile" ;
244
+ let _f = d. create ( name) . unwrap ( ) ;
245
+ d. remove_file ( name) . and_then ( |_| d. create ( name) ) . is_ok ( )
246
+ }
247
+
238
248
#[ test]
239
249
fn test_tempfile ( ) -> io:: Result < ( ) > {
240
250
use crate :: ambient_authority;
@@ -269,6 +279,17 @@ mod test {
269
279
270
280
assert_eq ! ( td. read( "testfile" ) ?, b"hello world" ) ;
271
281
282
+ if os_supports_unlinked_tmp ( & td) {
283
+ let mut tf = TempFile :: new_anonymous ( & td) . unwrap ( ) ;
284
+ tf. write_all ( b"hello world, I'm anonymous" ) . unwrap ( ) ;
285
+ tf. seek ( std:: io:: SeekFrom :: Start ( 0 ) ) . unwrap ( ) ;
286
+ let mut buf = String :: new ( ) ;
287
+ tf. read_to_string ( & mut buf) . unwrap ( ) ;
288
+ assert_eq ! ( & buf, "hello world, I'm anonymous" ) ;
289
+ } else if cfg ! ( windows) {
290
+ eprintln ! ( "notice: Detected older Windows" ) ;
291
+ }
292
+
272
293
td. close ( )
273
294
}
274
295
}
You can’t perform that action at this time.
0 commit comments