Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
matrixhead committed Sep 12, 2024
1 parent 0811df8 commit 338ed28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 47 deletions.
36 changes: 16 additions & 20 deletions src/uu/mv/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ fn is_empty_dir(path: &Path) -> bool {
fn move_dir(from: &Path, to: &Path, progress_bar: Option<&ProgressBar>) -> FsXResult<u64> {
// The return value that represents the number of bytes copied.
let mut result: u64 = 0;
let mut error_occured = false;
let mut error_occurred = false;
for dir_entry_result in WalkDir::new(from) {
match dir_entry_result {
Ok(dir_entry) => {
Expand All @@ -759,11 +759,11 @@ fn move_dir(from: &Path, to: &Path, progress_bar: Option<&ProgressBar>) -> FsXRe
}
}
Err(_) => {
error_occured = true;
error_occurred = true;

Check warning on line 762 in src/uu/mv/src/mv.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mv/src/mv.rs#L761-L762

Added lines #L761 - L762 were not covered by tests
}
}
}
if !error_occured {
if !error_occurred {
remove(from)?;
}
Ok(result)
Expand Down Expand Up @@ -797,24 +797,20 @@ fn copy_file(
} else {
None
};
let result_file_copy = {
let md = from.metadata()?;
if cfg!(unix) && FileTypeExt::is_fifo(&md.file_type()) {
let file_size = md.len();
uucore::fs::copy_fifo(to)?;
if let Some(progress_bar) = progress_bar {
progress_bar.set_position(file_size + progress_bar_start_val);
}
Ok(file_size)
} else {
if let Some(progress_handler) = progress_handler {
file::copy_with_progress(from, to, &copy_options, progress_handler)
} else {
file::copy(from, to, &copy_options)
}

let md = from.metadata()?;
if cfg!(unix) && FileTypeExt::is_fifo(&md.file_type()) {
let file_size = md.len();

Check warning on line 803 in src/uu/mv/src/mv.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mv/src/mv.rs#L803

Added line #L803 was not covered by tests
uucore::fs::copy_fifo(to)?;
if let Some(progress_bar) = progress_bar {
progress_bar.set_position(file_size + progress_bar_start_val);

Check warning on line 806 in src/uu/mv/src/mv.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mv/src/mv.rs#L806

Added line #L806 was not covered by tests
}
};
result_file_copy
Ok(file_size)

Check warning on line 808 in src/uu/mv/src/mv.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mv/src/mv.rs#L808

Added line #L808 was not covered by tests
} else if let Some(progress_handler) = progress_handler {
file::copy_with_progress(from, to, &copy_options, progress_handler)
} else {
file::copy(from, to, &copy_options)
}
}

#[cfg(test)]
Expand Down
27 changes: 0 additions & 27 deletions tests/by-util/test_mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,33 +1321,6 @@ fn test_mv_verbose() {
"renamed '{file_a}' -> '{file_b}' (backup: '{file_b}~')\n"
));
}
#[test]
fn test_verbose_src_symlink() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_mv_verbose_file_a";
let ln = "link";
at.touch(file_a);
at.symlink_file(&file_a, &ln);
scene
.ucmd()
.arg("-v")
.arg(file_a)
.arg(ln)
.succeeds()
.stdout_only(format!("renamed '{file_a}' -> '{ln}'\n"));

at.touch(file_a);
scene
.ucmd()
.arg("-vb")
.arg(file_a)
.arg(ln)
.succeeds()
.stdout_only(format!(
"renamed '{file_a}' -> '{ln}' (backup: '{ln}~')\n"
));
}

#[test]
#[cfg(any(target_os = "linux", target_os = "android"))] // mkdir does not support -m on windows. Freebsd doesn't return a permission error either.
Expand Down

0 comments on commit 338ed28

Please sign in to comment.