@@ -18,10 +18,15 @@ fn windows_open_one() {
18
18
19
19
let dir = tmpdir. open_dir ( "aaa" ) ;
20
20
21
+ // Attempts to remove or rename the open directory should fail.
21
22
tmpdir. remove_dir ( "aaa" ) . unwrap_err ( ) ;
22
23
tmpdir. rename ( "aaa" , & tmpdir, "zzz" ) . unwrap_err ( ) ;
23
24
24
25
drop ( dir) ;
26
+
27
+ // Now that we've droped the handle, the same operations should succeed.
28
+ check ! ( tmpdir. rename( "aaa" , & tmpdir, "xxx" ) ) ;
29
+ check ! ( tmpdir. remove_dir( "xxx" ) ) ;
25
30
}
26
31
27
32
#[ test]
@@ -32,10 +37,58 @@ fn windows_open_multiple() {
32
37
33
38
let dir = tmpdir. open_dir ( "aaa/bbb" ) ;
34
39
40
+ // Attempts to remove or rename any component of the open directory should fail.
35
41
tmpdir. remove_dir ( "aaa/bbb" ) . unwrap_err ( ) ;
36
42
tmpdir. remove_dir ( "aaa" ) . unwrap_err ( ) ;
37
- tmpdir. rename ( "aaa/bbb" , & tmpdir, "aaa/zzz " ) . unwrap_err ( ) ;
43
+ tmpdir. rename ( "aaa/bbb" , & tmpdir, "aaa/yyy " ) . unwrap_err ( ) ;
38
44
tmpdir. rename ( "aaa" , & tmpdir, "zzz" ) . unwrap_err ( ) ;
39
45
40
46
drop ( dir) ;
47
+
48
+ // Now that we've droped the handle, the same operations should succeed.
49
+ check ! ( tmpdir. rename( "aaa/bbb" , & tmpdir, "aaa/www" ) ) ;
50
+ check ! ( tmpdir. rename( "aaa" , & tmpdir, "xxx" ) ) ;
51
+ check ! ( tmpdir. remove_dir( "xxx/www" ) ) ;
52
+ check ! ( tmpdir. remove_dir( "xxx" ) ) ;
53
+ }
54
+
55
+ /// Like `windows_open_multiple`, but does so within a directory that we
56
+ /// can close and then independently mutate.
57
+ #[ test]
58
+ #[ cfg( windows) ]
59
+ fn windows_open_tricky ( ) {
60
+ let tmpdir = tmpdir ( ) ;
61
+ check ! ( tmpdir. create_dir( "qqq" ) ) ;
62
+
63
+ let qqq = check ! ( tmpdir. open_dir( "qqq" ) ) ;
64
+ check ! ( qqq. create_dir_all( "aaa/bbb" ) ) ;
65
+
66
+ let dir = check ! ( qqq. open_dir( "aaa/bbb" ) ) ;
67
+
68
+ // Now drop `qqq`.
69
+ drop ( qqq) ;
70
+
71
+ // Attempts to remove or rename any component of the open directory should fail.
72
+ dir. remove_dir ( "aaa/bbb" ) . unwrap_err ( ) ;
73
+ dir. remove_dir ( "aaa" ) . unwrap_err ( ) ;
74
+ dir. rename ( "aaa/bbb" , & tmpdir, "aaa/yyy" ) . unwrap_err ( ) ;
75
+ dir. rename ( "aaa" , & tmpdir, "zzz" ) . unwrap_err ( ) ;
76
+ tmpdir. remove_dir ( "qqq/aaa/bbb" ) . unwrap_err ( ) ;
77
+ tmpdir. remove_dir ( "qqq/aaa" ) . unwrap_err ( ) ;
78
+ tmpdir. remove_dir ( "qqq" ) . unwrap_err ( ) ;
79
+ tmpdir
80
+ . rename ( "qqq/aaa/bbb" , & tmpdir, "qqq/aaa/yyy" )
81
+ . unwrap_err ( ) ;
82
+ tmpdir. rename ( "qqq/aaa" , & tmpdir, "qqq/zzz" ) . unwrap_err ( ) ;
83
+ tmpdir. rename ( "qqq" , & tmpdir, "vvv" ) . unwrap_err ( ) ;
84
+
85
+ drop ( dir) ;
86
+
87
+ // Now that we've droped the handle, the same operations should succeed.
88
+ check ! ( tmpdir. rename( "qqq/aaa/bbb" , & tmpdir, "qqq/aaa/www" ) ) ;
89
+ check ! ( tmpdir. rename( "qqq/aaa" , & tmpdir, "qqq/xxx" ) ) ;
90
+ check ! ( tmpdir. rename( "qqq" , & tmpdir, "uuu" ) ) ;
91
+ check ! ( tmpdir. remove_dir( "uuu/xxx/www" ) ) ;
92
+ check ! ( tmpdir. remove_dir( "uuu/xxx" ) ) ;
93
+ check ! ( tmpdir. remove_dir( "uuu" ) ) ;
41
94
}
0 commit comments