Skip to content

Commit a4c1ef3

Browse files
committed
notifications: log directly when copying directories
1 parent 5469a78 commit a4c1ef3

File tree

4 files changed

+10
-28
lines changed

4 files changed

+10
-28
lines changed

src/dist/component/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl<'a> ChangedItem<'a> {
296296
src: &Path,
297297
) -> Result<Self> {
298298
let abs_path = ChangedItem::dest_abs_path(prefix, component, &relpath)?;
299-
utils::copy_dir(src, &abs_path, &|_: Notification<'_>| ())?;
299+
utils::copy_dir(src, &abs_path)?;
300300
Ok(ChangedItem::AddedDir(relpath))
301301
}
302302
fn remove_file(

src/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl InstallMethod<'_> {
9797

9898
match self {
9999
InstallMethod::Copy { src, .. } => {
100-
utils::copy_dir(src, path, notify_handler)?;
100+
utils::copy_dir(src, path)?;
101101
Ok(true)
102102
}
103103
InstallMethod::Link { src, .. } => {

src/notifications.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ pub enum Notification<'a> {
3737
StrayHash(&'a Path),
3838
SignatureInvalid(&'a str),
3939
RetryingDownload(&'a str),
40-
CopyingDirectory(&'a Path, &'a Path),
4140
RemovingDirectory(&'a str, &'a Path),
4241
DownloadingFile(&'a Url, &'a Path),
4342
/// Received the Content-Length of the to-be downloaded data with
@@ -122,7 +121,6 @@ impl Notification<'_> {
122121
SignatureInvalid(_) => NotificationLevel::Warn,
123122
SetDefaultBufferSize(_) => NotificationLevel::Trace,
124123
RemovingDirectory(_, _)
125-
| CopyingDirectory(_, _)
126124
| DownloadingFile(_, _)
127125
| DownloadContentLengthReceived(_, _)
128126
| DownloadDataReceived(_, _)
@@ -256,7 +254,6 @@ impl Display for Notification<'_> {
256254
SignatureInvalid(url) => write!(f, "Signature verification failed for '{url}'"),
257255
RetryingDownload(url) => write!(f, "retrying download for '{url}'"),
258256
Error(e) => write!(f, "error: '{e}'"),
259-
CopyingDirectory(src, _) => write!(f, "copying directory from: '{}'", src.display()),
260257
RemovingDirectory(name, path) => {
261258
write!(f, "removing {} directory: '{}'", name, path.display())
262259
}

src/utils/mod.rs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,8 @@ fn symlink_file(src: &Path, dest: &Path) -> Result<()> {
217217
})
218218
}
219219

220-
pub(crate) fn copy_dir<'a, N>(
221-
src: &'a Path,
222-
dest: &'a Path,
223-
notify_handler: &dyn Fn(N),
224-
) -> Result<()>
225-
where
226-
N: From<Notification<'a>>,
227-
{
228-
notify_handler(Notification::CopyingDirectory(src, dest).into());
220+
pub(crate) fn copy_dir(src: &Path, dest: &Path) -> Result<()> {
221+
debug!(source = %src.display(), destination = %dest.display(), "copying directory");
229222
raw::copy_dir(src, dest).with_context(|| {
230223
format!(
231224
"could not copy directory from '{}' to '{}'",
@@ -381,25 +374,17 @@ pub(crate) fn format_path_for_display(path: &str) -> String {
381374
}
382375

383376
#[cfg(target_os = "linux")]
384-
fn copy_and_delete<'a, N>(
385-
name: &'static str,
386-
src: &'a Path,
387-
dest: &'a Path,
388-
notify_handler: &'a dyn Fn(N),
389-
) -> Result<()>
390-
where
391-
N: From<Notification<'a>>,
392-
{
377+
fn copy_and_delete(name: &'static str, src: &Path, dest: &Path) -> Result<()> {
393378
// https://github.com/rust-lang/rustup/issues/1239
394379
// This uses std::fs::copy() instead of the faster std::fs::rename() to
395380
// avoid cross-device link errors.
396381
if src.is_dir() {
397-
copy_dir(src, dest, notify_handler).and(remove_dir_all::remove_dir_all(src).with_context(
398-
|| RustupError::RemovingDirectory {
382+
copy_dir(src, dest).and(remove_dir_all::remove_dir_all(src).with_context(|| {
383+
RustupError::RemovingDirectory {
399384
name,
400385
path: PathBuf::from(src),
401-
},
402-
))
386+
}
387+
}))
403388
} else {
404389
copy_file(src, dest).and(remove_file(name, src))
405390
}
@@ -435,7 +420,7 @@ where
435420
_ if process.var_os("RUSTUP_PERMIT_COPY_RENAME").is_some()
436421
&& Some(EXDEV) == e.raw_os_error() =>
437422
{
438-
match copy_and_delete(name, src, dest, notify_handler) {
423+
match copy_and_delete(name, src, dest) {
439424
Ok(()) => OperationResult::Ok(()),
440425
Err(_) => OperationResult::Err(e),
441426
}

0 commit comments

Comments
 (0)