Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mv: gnu test case part-hardlink fix #6632

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 1 addition & 37 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use platform::copy_on_write;
use uucore::display::Quotable;
use uucore::error::{set_exit_code, UClapError, UError, UResult, UUsageError};
use uucore::fs::{
are_hardlinks_to_same_file, canonicalize, get_filename, is_symlink_loop,
are_hardlinks_to_same_file, canonicalize, disk_usage, get_filename, is_symlink_loop,
path_ends_with_terminator, paths_refer_to_same_file, FileInformation, MissingHandling,
ResolveMode,
};
Expand Down Expand Up @@ -2447,42 +2447,6 @@ pub fn localize_to_target(root: &Path, source: &Path, target: &Path) -> CopyResu
Ok(target.join(local_to_root))
}

/// Get the total size of a slice of files and directories.
///
/// This function is much like the `du` utility, by recursively getting the sizes of files in directories.
/// Files are not deduplicated when appearing in multiple sources. If `recursive` is set to `false`, the
/// directories in `paths` will be ignored.
fn disk_usage(paths: &[PathBuf], recursive: bool) -> io::Result<u64> {
let mut total = 0;
for p in paths {
let md = fs::metadata(p)?;
if md.file_type().is_dir() {
if recursive {
total += disk_usage_directory(p)?;
}
} else {
total += md.len();
}
}
Ok(total)
}

/// A helper for `disk_usage` specialized for directories.
fn disk_usage_directory(p: &Path) -> io::Result<u64> {
let mut total = 0;

for entry in fs::read_dir(p)? {
let entry = entry?;
if entry.file_type()?.is_dir() {
total += disk_usage_directory(&entry.path())?;
} else {
total += entry.metadata()?.len();
}
}

Ok(total)
}

#[cfg(test)]
mod tests {

Expand Down
7 changes: 7 additions & 0 deletions src/uu/mv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@ path = "src/mv.rs"
clap = { workspace = true }
fs_extra = { workspace = true }
indicatif = { workspace = true }
walkdir = { workspace = true }
filetime = { workspace = true }
uucore = { workspace = true, features = [
"backup-control",
"fs",
"fsxattr",
"update-control",
"perms",
"entries",
] }

[dev-dependencies]
tempfile = { workspace = true }

[[bin]]
name = "mv"
path = "src/main.rs"
16 changes: 16 additions & 0 deletions src/uu/mv/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

use uucore::error::UError;

use fs_extra::error::Error as FsXError;

#[derive(Debug)]
pub enum MvError {
NoSuchFile(String),
Expand All @@ -19,6 +21,8 @@
NotADirectory(String),
TargetNotADirectory(String),
FailedToAccessNotADirectory(String),
FsXError(FsXError),

Check warning on line 24 in src/uu/mv/src/error.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mv/src/error.rs#L24

Added line #L24 was not covered by tests
NotAllFilesMoved,
}

impl Error for MvError {}
Expand Down Expand Up @@ -49,6 +53,18 @@
Self::FailedToAccessNotADirectory(t) => {
write!(f, "failed to access {t}: Not a directory")
}
Self::FsXError(err) => {
write!(f, "{err}")

Check warning on line 57 in src/uu/mv/src/error.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mv/src/error.rs#L56-L57

Added lines #L56 - L57 were not covered by tests
}
Self::NotAllFilesMoved => {
write!(f, "failed to move all files")

Check warning on line 60 in src/uu/mv/src/error.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mv/src/error.rs#L60

Added line #L60 was not covered by tests
}
}
}
}

impl From<FsXError> for MvError {
fn from(err: FsXError) -> Self {
Self::FsXError(err)
}

Check warning on line 69 in src/uu/mv/src/error.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mv/src/error.rs#L67-L69

Added lines #L67 - L69 were not covered by tests
}
Loading
Loading