@@ -7,9 +7,6 @@ use std::io;
7
7
use std:: path:: { Path , PathBuf } ;
8
8
use std:: collections:: HashMap ;
9
9
10
- use quickcheck:: { Arbitrary , Gen , QuickCheck , StdGen } ;
11
- use rand:: { self , Rng , RngCore } ;
12
-
13
10
use super :: { DirEntry , WalkDir , IntoIter , Error , ErrorInner } ;
14
11
15
12
#[ derive( Clone , Debug , Eq , Ord , PartialEq , PartialOrd ) ]
@@ -95,14 +92,6 @@ impl Tree {
95
92
. unwrap_or_default ( ) ) )
96
93
}
97
94
98
- fn name ( & self ) -> & Path {
99
- match * self {
100
- Tree :: Dir ( ref pb, _) => pb,
101
- Tree :: File ( ref pb) => pb,
102
- Tree :: Symlink { ref dst, .. } => dst,
103
- }
104
- }
105
-
106
95
fn unwrap_singleton ( self ) -> Tree {
107
96
match self {
108
97
Tree :: File ( _) | Tree :: Symlink { .. } => {
@@ -170,97 +159,6 @@ impl Tree {
170
159
}
171
160
}
172
161
}
173
-
174
- fn dedup ( & self ) -> Tree {
175
- match * self {
176
- Tree :: Symlink { ref src, ref dst, dir } => {
177
- Tree :: Symlink { src : src. clone ( ) , dst : dst. clone ( ) , dir : dir }
178
- }
179
- Tree :: File ( ref p) => {
180
- Tree :: File ( p. clone ( ) )
181
- }
182
- Tree :: Dir ( ref p, ref cs) => {
183
- let mut nodupes: Vec < Tree > = vec ! [ ] ;
184
- for ( i, c1) in cs. iter ( ) . enumerate ( ) {
185
- if !cs[ i+1 ..] . iter ( ) . any ( |c2| c1. name ( ) == c2. name ( ) )
186
- && !nodupes. iter ( ) . any ( |c2| c1. name ( ) == c2. name ( ) ) {
187
- nodupes. push ( c1. dedup ( ) ) ;
188
- }
189
- }
190
- Tree :: Dir ( p. clone ( ) , nodupes)
191
- }
192
- }
193
- }
194
-
195
- fn gen < G : Gen > ( g : & mut G , depth : usize ) -> Tree {
196
- #[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
197
- struct NonEmptyAscii ( String ) ;
198
-
199
- impl Arbitrary for NonEmptyAscii {
200
- fn arbitrary < G : Gen > ( g : & mut G ) -> NonEmptyAscii {
201
- use std:: char:: from_u32;
202
- let upper_bound = g. size ( ) ;
203
- // We start with a lower bound of `4` to avoid
204
- // generating the special file name `con` on Windows,
205
- // because such files cannot exist...
206
- let size = g. gen_range ( 4 , upper_bound) ;
207
- NonEmptyAscii ( ( 0 ..size)
208
- . map ( |_| from_u32 ( g. gen_range ( 97 , 123 ) ) . unwrap ( ) )
209
- . collect ( ) )
210
- }
211
-
212
- fn shrink ( & self ) -> Box < Iterator < Item =NonEmptyAscii > > {
213
- let mut smaller = vec ! [ ] ;
214
- for i in 1 ..self . 0 . len ( ) {
215
- let s: String = self . 0 . chars ( ) . skip ( i) . collect ( ) ;
216
- smaller. push ( NonEmptyAscii ( s) ) ;
217
- }
218
- Box :: new ( smaller. into_iter ( ) )
219
- }
220
- }
221
-
222
- let name = pb ( NonEmptyAscii :: arbitrary ( g) . 0 ) ;
223
- if depth == 0 {
224
- Tree :: File ( name)
225
- } else {
226
- let children: Vec < Tree > =
227
- ( 0 ..g. gen_range ( 0 , 5 ) )
228
- . map ( |_| Tree :: gen ( g, depth-1 ) )
229
- . collect ( ) ;
230
- Tree :: Dir ( name, children)
231
- }
232
- }
233
- }
234
-
235
- impl Arbitrary for Tree {
236
- fn arbitrary < G : Gen > ( g : & mut G ) -> Tree {
237
- let depth = g. gen_range ( 0 , 5 ) ;
238
- Tree :: gen ( g, depth) . dedup ( )
239
- }
240
-
241
- fn shrink ( & self ) -> Box < Iterator < Item =Tree > > {
242
- let trees: Box < Iterator < Item =Tree > > = match * self {
243
- Tree :: Symlink { .. } => unimplemented ! ( ) ,
244
- Tree :: File ( ref path) => {
245
- let s = path. to_string_lossy ( ) . into_owned ( ) ;
246
- Box :: new ( s. shrink ( ) . map ( |s| Tree :: File ( pb ( s) ) ) )
247
- }
248
- Tree :: Dir ( ref path, ref children) => {
249
- let s = path. to_string_lossy ( ) . into_owned ( ) ;
250
- if children. is_empty ( ) {
251
- Box :: new ( s. shrink ( ) . map ( |s| Tree :: Dir ( pb ( s) , vec ! [ ] ) ) )
252
- } else if children. len ( ) == 1 {
253
- let c = & children[ 0 ] ;
254
- Box :: new ( Some ( c. clone ( ) ) . into_iter ( ) . chain ( c. shrink ( ) ) )
255
- } else {
256
- Box :: new ( children
257
- . shrink ( )
258
- . map ( move |cs| Tree :: Dir ( pb ( s. clone ( ) ) , cs) ) )
259
- }
260
- }
261
- } ;
262
- Box :: new ( trees. map ( |t| t. dedup ( ) ) )
263
- }
264
162
}
265
163
266
164
#[ derive( Debug ) ]
@@ -328,9 +226,13 @@ impl Drop for TempDir {
328
226
}
329
227
330
228
fn tmpdir ( ) -> TempDir {
229
+ use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
230
+
231
+ static COUNTER : AtomicUsize = AtomicUsize :: new ( 0 ) ;
232
+
331
233
let p = env:: temp_dir ( ) ;
332
- let mut r = rand :: thread_rng ( ) ;
333
- let ret = p. join ( & format ! ( "rust-{}" , r . next_u32 ( ) ) ) ;
234
+ let idx = COUNTER . fetch_add ( 1 , Ordering :: SeqCst ) ;
235
+ let ret = p. join ( & format ! ( "rust-{}" , idx ) ) ;
334
236
fs:: create_dir ( & ret) . unwrap ( ) ;
335
237
TempDir ( ret)
336
238
}
@@ -782,34 +684,6 @@ fn walk_dir_filter() {
782
684
assert_eq ! ( got, vec![ "bar" , "faz" , "foo" ] ) ;
783
685
}
784
686
785
- #[ test]
786
- fn qc_roundtrip ( ) {
787
- fn p ( exp : Tree ) -> bool {
788
- let ( _tmp, got) = dir_setup ( & exp) ;
789
- exp. canonical ( ) == got. canonical ( )
790
- }
791
- QuickCheck :: new ( )
792
- . gen ( StdGen :: new ( rand:: thread_rng ( ) , 15 ) )
793
- . tests ( 1_000 )
794
- . max_tests ( 10_000 )
795
- . quickcheck ( p as fn ( Tree ) -> bool ) ;
796
- }
797
-
798
- // Same as `qc_roundtrip`, but makes sure `follow_links` doesn't change
799
- // the behavior of walking a directory *without* symlinks.
800
- #[ test]
801
- fn qc_roundtrip_no_symlinks_with_follow ( ) {
802
- fn p ( exp : Tree ) -> bool {
803
- let ( _tmp, got) = dir_setup_with ( & exp, |wd| wd. follow_links ( true ) ) ;
804
- exp. canonical ( ) == got. canonical ( )
805
- }
806
- QuickCheck :: new ( )
807
- . gen ( StdGen :: new ( rand:: thread_rng ( ) , 15 ) )
808
- . tests ( 1_000 )
809
- . max_tests ( 10_000 )
810
- . quickcheck ( p as fn ( Tree ) -> bool ) ;
811
- }
812
-
813
687
#[ test]
814
688
fn walk_dir_sort ( ) {
815
689
let exp = td ( "foo" , vec ! [
0 commit comments