@@ -11,13 +11,13 @@ pub mod artifact_names;
11
11
pub mod diff;
12
12
pub mod env_checked;
13
13
pub mod external_deps;
14
+ pub mod fs_helpers;
14
15
pub mod fs_wrapper;
15
16
pub mod path_helpers;
16
17
pub mod run;
17
18
pub mod targets;
18
19
19
20
use std:: fs;
20
- use std:: io;
21
21
use std:: panic;
22
22
use std:: path:: { Path , PathBuf } ;
23
23
@@ -71,35 +71,10 @@ pub use artifact_names::{
71
71
/// Path-related helpers.
72
72
pub use path_helpers:: { cwd, cygpath_windows, path, source_root} ;
73
73
74
- use command:: { Command , CompletedProcess } ;
74
+ /// Helpers for common fs operations.
75
+ pub use fs_helpers:: { copy_dir_all, create_symlink, read_dir} ;
75
76
76
- /// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
77
- #[ cfg( target_family = "windows" ) ]
78
- pub fn create_symlink < P : AsRef < Path > , Q : AsRef < Path > > ( original : P , link : Q ) {
79
- if link. as_ref ( ) . exists ( ) {
80
- std:: fs:: remove_dir ( link. as_ref ( ) ) . unwrap ( ) ;
81
- }
82
- use std:: os:: windows:: fs;
83
- fs:: symlink_file ( original. as_ref ( ) , link. as_ref ( ) ) . expect ( & format ! (
84
- "failed to create symlink {:?} for {:?}" ,
85
- link. as_ref( ) . display( ) ,
86
- original. as_ref( ) . display( ) ,
87
- ) ) ;
88
- }
89
-
90
- /// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
91
- #[ cfg( target_family = "unix" ) ]
92
- pub fn create_symlink < P : AsRef < Path > , Q : AsRef < Path > > ( original : P , link : Q ) {
93
- if link. as_ref ( ) . exists ( ) {
94
- std:: fs:: remove_dir ( link. as_ref ( ) ) . unwrap ( ) ;
95
- }
96
- use std:: os:: unix:: fs;
97
- fs:: symlink ( original. as_ref ( ) , link. as_ref ( ) ) . expect ( & format ! (
98
- "failed to create symlink {:?} for {:?}" ,
99
- link. as_ref( ) . display( ) ,
100
- original. as_ref( ) . display( ) ,
101
- ) ) ;
102
- }
77
+ use command:: { Command , CompletedProcess } ;
103
78
104
79
// FIXME(Oneirical): This will no longer be required after compiletest receives the ability
105
80
// to manipulate read-only files. See https://github.com/rust-lang/rust/issues/126334
@@ -275,36 +250,6 @@ pub fn invalid_utf8_not_contains<P: AsRef<Path>, S: AsRef<str>>(path: P, expecte
275
250
}
276
251
}
277
252
278
- /// Copy a directory into another.
279
- pub fn copy_dir_all ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) {
280
- fn copy_dir_all_inner ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) -> io:: Result < ( ) > {
281
- let dst = dst. as_ref ( ) ;
282
- if !dst. is_dir ( ) {
283
- std:: fs:: create_dir_all ( & dst) ?;
284
- }
285
- for entry in std:: fs:: read_dir ( src) ? {
286
- let entry = entry?;
287
- let ty = entry. file_type ( ) ?;
288
- if ty. is_dir ( ) {
289
- copy_dir_all_inner ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
290
- } else {
291
- std:: fs:: copy ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
292
- }
293
- }
294
- Ok ( ( ) )
295
- }
296
-
297
- if let Err ( e) = copy_dir_all_inner ( & src, & dst) {
298
- // Trying to give more context about what exactly caused the failure
299
- panic ! (
300
- "failed to copy `{}` to `{}`: {:?}" ,
301
- src. as_ref( ) . display( ) ,
302
- dst. as_ref( ) . display( ) ,
303
- e
304
- ) ;
305
- }
306
- }
307
-
308
253
/// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise.
309
254
pub fn recursive_diff ( dir1 : impl AsRef < Path > , dir2 : impl AsRef < Path > ) {
310
255
let dir2 = dir2. as_ref ( ) ;
@@ -330,12 +275,6 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
330
275
} ) ;
331
276
}
332
277
333
- pub fn read_dir < F : FnMut ( & Path ) > ( dir : impl AsRef < Path > , mut callback : F ) {
334
- for entry in fs_wrapper:: read_dir ( dir) {
335
- callback ( & entry. unwrap ( ) . path ( ) ) ;
336
- }
337
- }
338
-
339
278
/// Check that `actual` is equal to `expected`. Panic otherwise.
340
279
#[ track_caller]
341
280
pub fn assert_equals < S1 : AsRef < str > , S2 : AsRef < str > > ( actual : S1 , expected : S2 ) {
0 commit comments