run-make-support: re-export recursive_remove
This facade is like other `run_make_support::fs` APIs that panic-on-failure but includes the path that the operation was called on in the panic message.
This commit is contained in:
parent
7e2240338a
commit
4d3bf1f5ee
1 changed files with 19 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
use std::fs::FileType;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
|
@ -6,7 +7,8 @@ use std::path::{Path, PathBuf};
|
|||
pub fn copy_symlink(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
|
||||
let src = src.as_ref();
|
||||
let dst = dst.as_ref();
|
||||
if let Err(e) = copy_symlink_raw(src, dst) {
|
||||
let metadata = symlink_metadata(src);
|
||||
if let Err(e) = copy_symlink_raw(metadata.file_type(), src, dst) {
|
||||
panic!("failed to copy symlink from `{}` to `{}`: {e}", src.display(), dst.display(),);
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +58,7 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
|
|||
if ty.is_dir() {
|
||||
copy_dir_all_inner(entry.path(), dst.join(entry.file_name()))?;
|
||||
} else if ty.is_symlink() {
|
||||
copy_symlink_raw(entry.path(), dst.join(entry.file_name()))?;
|
||||
copy_symlink_raw(ty, entry.path(), dst.join(entry.file_name()))?;
|
||||
} else {
|
||||
std::fs::copy(entry.path(), dst.join(entry.file_name()))?;
|
||||
}
|
||||
|
@ -82,6 +84,21 @@ pub fn read_dir_entries<P: AsRef<Path>, F: FnMut(&Path)>(dir: P, mut callback: F
|
|||
}
|
||||
}
|
||||
|
||||
/// A wrapper around [`build_helper::fs::recursive_remove`] which includes the file path in the
|
||||
/// panic message.
|
||||
///
|
||||
/// This handles removing symlinks on Windows (e.g. symlink-to-file will be removed via
|
||||
/// [`std::fs::remove_file`] while symlink-to-dir will be removed via [`std::fs::remove_dir`]).
|
||||
#[track_caller]
|
||||
pub fn recursive_remove<P: AsRef<Path>>(path: P) {
|
||||
if let Err(e) = build_helper::fs::recursive_remove(path.as_ref()) {
|
||||
panic!(
|
||||
"failed to recursive remove filesystem entities at `{}`: {e}",
|
||||
path.as_ref().display()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper around [`std::fs::remove_file`] which includes the file path in the panic message.
|
||||
#[track_caller]
|
||||
pub fn remove_file<P: AsRef<Path>>(path: P) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue