@@ -11,13 +11,13 @@ pub mod artifact_names;
1111pub mod diff;
1212pub mod env_checked;
1313pub mod external_deps;
14+ pub mod fs_helpers;
1415pub mod fs_wrapper;
1516pub mod path_helpers;
1617pub mod run;
1718pub mod targets;
1819
1920use std:: fs;
20- use std:: io;
2121use std:: panic;
2222use std:: path:: { Path , PathBuf } ;
2323
@@ -71,35 +71,10 @@ pub use artifact_names::{
7171/// Path-related helpers.
7272pub use path_helpers:: { cwd, cygpath_windows, path, source_root} ;
7373
74- use command:: { Command , CompletedProcess } ;
74+ /// Helpers for common fs operations.
75+ pub use fs_helpers:: { copy_dir_all, create_symlink, read_dir} ;
7576
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 } ;
10378
10479// FIXME(Oneirical): This will no longer be required after compiletest receives the ability
10580// 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
275250 }
276251}
277252
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-
308253/// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise.
309254pub fn recursive_diff ( dir1 : impl AsRef < Path > , dir2 : impl AsRef < Path > ) {
310255 let dir2 = dir2. as_ref ( ) ;
@@ -330,12 +275,6 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
330275 } ) ;
331276}
332277
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-
339278/// Check that `actual` is equal to `expected`. Panic otherwise.
340279#[ track_caller]
341280pub fn assert_equals < S1 : AsRef < str > , S2 : AsRef < str > > ( actual : S1 , expected : S2 ) {
0 commit comments