@@ -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
@@ -255,36 +230,6 @@ pub fn invalid_utf8_not_contains<P: AsRef<Path>, S: AsRef<str>>(path: P, expecte
255
230
}
256
231
}
257
232
258
- /// Copy a directory into another.
259
- pub fn copy_dir_all ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) {
260
- fn copy_dir_all_inner ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) -> io:: Result < ( ) > {
261
- let dst = dst. as_ref ( ) ;
262
- if !dst. is_dir ( ) {
263
- std:: fs:: create_dir_all ( & dst) ?;
264
- }
265
- for entry in std:: fs:: read_dir ( src) ? {
266
- let entry = entry?;
267
- let ty = entry. file_type ( ) ?;
268
- if ty. is_dir ( ) {
269
- copy_dir_all_inner ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
270
- } else {
271
- std:: fs:: copy ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
272
- }
273
- }
274
- Ok ( ( ) )
275
- }
276
-
277
- if let Err ( e) = copy_dir_all_inner ( & src, & dst) {
278
- // Trying to give more context about what exactly caused the failure
279
- panic ! (
280
- "failed to copy `{}` to `{}`: {:?}" ,
281
- src. as_ref( ) . display( ) ,
282
- dst. as_ref( ) . display( ) ,
283
- e
284
- ) ;
285
- }
286
- }
287
-
288
233
/// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise.
289
234
pub fn recursive_diff ( dir1 : impl AsRef < Path > , dir2 : impl AsRef < Path > ) {
290
235
let dir2 = dir2. as_ref ( ) ;
@@ -310,12 +255,6 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
310
255
} ) ;
311
256
}
312
257
313
- pub fn read_dir < F : FnMut ( & Path ) > ( dir : impl AsRef < Path > , mut callback : F ) {
314
- for entry in fs_wrapper:: read_dir ( dir) {
315
- callback ( & entry. unwrap ( ) . path ( ) ) ;
316
- }
317
- }
318
-
319
258
/// Check that `actual` is equal to `expected`. Panic otherwise.
320
259
#[ track_caller]
321
260
pub fn assert_equals < S1 : AsRef < str > , S2 : AsRef < str > > ( actual : S1 , expected : S2 ) {
0 commit comments