mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #4991 from shinhs0506/du_apparent
du: directories have apparent size of 0
This commit is contained in:
commit
9149409065
3 changed files with 52 additions and 80 deletions
|
@ -145,7 +145,7 @@ impl Stat {
|
||||||
return Ok(Self {
|
return Ok(Self {
|
||||||
path: path.to_path_buf(),
|
path: path.to_path_buf(),
|
||||||
is_dir: metadata.is_dir(),
|
is_dir: metadata.is_dir(),
|
||||||
size: metadata.len(),
|
size: if path.is_dir() { 0 } else { metadata.len() },
|
||||||
blocks: metadata.blocks(),
|
blocks: metadata.blocks(),
|
||||||
inodes: 1,
|
inodes: 1,
|
||||||
inode: Some(file_info),
|
inode: Some(file_info),
|
||||||
|
@ -162,7 +162,7 @@ impl Stat {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
path: path.to_path_buf(),
|
path: path.to_path_buf(),
|
||||||
is_dir: metadata.is_dir(),
|
is_dir: metadata.is_dir(),
|
||||||
size: metadata.len(),
|
size: if path.is_dir() { 0 } else { metadata.len() },
|
||||||
blocks: size_on_disk / 1024 * 2,
|
blocks: size_on_disk / 1024 * 2,
|
||||||
inode: file_info,
|
inode: file_info,
|
||||||
inodes: 1,
|
inodes: 1,
|
||||||
|
|
|
@ -580,97 +580,58 @@ fn test_du_invalid_threshold() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_du_apparent_size() {
|
fn test_du_apparent_size() {
|
||||||
let ts = TestScenario::new(util_name!());
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
let result = ts.ucmd().arg("--apparent-size").succeeds();
|
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
at.mkdir_all("a/b");
|
||||||
|
|
||||||
|
at.write("a/b/file1", "foo");
|
||||||
|
at.write("a/b/file2", "foobar");
|
||||||
|
|
||||||
|
let result = ucmd.args(&["--apparent-size", "--all", "a"]).succeeds();
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
{
|
{
|
||||||
let result_reference = unwrap_or_return!(expected_result(&ts, &["--apparent-size"]));
|
result.stdout_contains_line("1\ta/b/file2");
|
||||||
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
result.stdout_contains_line("1\ta/b/file1");
|
||||||
|
result.stdout_contains_line("1\ta/b");
|
||||||
|
result.stdout_contains_line("1\ta");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
#[cfg(target_os = "windows")]
|
||||||
_du_apparent_size(result.stdout_str());
|
{
|
||||||
}
|
result.stdout_contains_line("1\ta\\b\\file2");
|
||||||
|
result.stdout_contains_line("1\ta\\b\\file1");
|
||||||
#[cfg(target_os = "windows")]
|
result.stdout_contains_line("1\ta\\b");
|
||||||
fn _du_apparent_size(s: &str) {
|
result.stdout_contains_line("1\ta");
|
||||||
assert_eq!(
|
}
|
||||||
s,
|
|
||||||
"1\t.\\subdir\\deeper\\deeper_dir
|
|
||||||
1\t.\\subdir\\deeper
|
|
||||||
6\t.\\subdir\\links
|
|
||||||
6\t.\\subdir
|
|
||||||
6\t.
|
|
||||||
"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
#[cfg(target_vendor = "apple")]
|
|
||||||
fn _du_apparent_size(s: &str) {
|
|
||||||
assert_eq!(
|
|
||||||
s,
|
|
||||||
"1\t./subdir/deeper/deeper_dir
|
|
||||||
1\t./subdir/deeper
|
|
||||||
6\t./subdir/links
|
|
||||||
6\t./subdir
|
|
||||||
6\t.
|
|
||||||
"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
#[cfg(target_os = "freebsd")]
|
|
||||||
fn _du_apparent_size(s: &str) {
|
|
||||||
assert_eq!(
|
|
||||||
s,
|
|
||||||
"1\t./subdir/deeper/deeper_dir
|
|
||||||
2\t./subdir/deeper
|
|
||||||
6\t./subdir/links
|
|
||||||
8\t./subdir
|
|
||||||
8\t.
|
|
||||||
"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
#[cfg(all(
|
|
||||||
not(target_vendor = "apple"),
|
|
||||||
not(target_os = "windows"),
|
|
||||||
not(target_os = "freebsd")
|
|
||||||
))]
|
|
||||||
fn _du_apparent_size(s: &str) {
|
|
||||||
assert_eq!(
|
|
||||||
s,
|
|
||||||
"5\t./subdir/deeper/deeper_dir
|
|
||||||
9\t./subdir/deeper
|
|
||||||
10\t./subdir/links
|
|
||||||
22\t./subdir
|
|
||||||
26\t.
|
|
||||||
"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_du_bytes() {
|
fn test_du_bytes() {
|
||||||
let ts = TestScenario::new(util_name!());
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
let result = ts.ucmd().arg("--bytes").succeeds();
|
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
at.mkdir_all("a/b");
|
||||||
|
|
||||||
|
at.write("a/b/file1", "foo");
|
||||||
|
at.write("a/b/file2", "foobar");
|
||||||
|
|
||||||
|
let result = ucmd.args(&["--bytes", "--all", "a"]).succeeds();
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
{
|
{
|
||||||
let result_reference = unwrap_or_return!(expected_result(&ts, &["--bytes"]));
|
result.stdout_contains_line("6\ta/b/file2");
|
||||||
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
result.stdout_contains_line("3\ta/b/file1");
|
||||||
|
result.stdout_contains_line("9\ta/b");
|
||||||
|
result.stdout_contains_line("9\ta");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
result.stdout_contains("5145\t.\\subdir\n");
|
{
|
||||||
#[cfg(target_vendor = "apple")]
|
result.stdout_contains_line("6\ta\\b\\file2");
|
||||||
result.stdout_contains("5625\t./subdir\n");
|
result.stdout_contains_line("3\ta\\b\\file1");
|
||||||
#[cfg(target_os = "freebsd")]
|
result.stdout_contains_line("9\ta\\b");
|
||||||
result.stdout_contains("7193\t./subdir\n");
|
result.stdout_contains_line("9\ta");
|
||||||
#[cfg(all(
|
}
|
||||||
not(target_vendor = "apple"),
|
|
||||||
not(target_os = "windows"),
|
|
||||||
not(target_os = "freebsd"),
|
|
||||||
not(target_os = "linux"),
|
|
||||||
not(target_os = "android"),
|
|
||||||
))]
|
|
||||||
result.stdout_contains("21529\t./subdir\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -659,6 +659,17 @@ impl CmdResult {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
|
pub fn stdout_contains_line<T: AsRef<str>>(&self, cmp: T) -> &Self {
|
||||||
|
assert!(
|
||||||
|
self.stdout_str().lines().any(|line| line == cmp.as_ref()),
|
||||||
|
"'{}' does not contain line '{}'",
|
||||||
|
self.stdout_str(),
|
||||||
|
cmp.as_ref()
|
||||||
|
);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn stderr_contains<T: AsRef<str>>(&self, cmp: T) -> &Self {
|
pub fn stderr_contains<T: AsRef<str>>(&self, cmp: T) -> &Self {
|
||||||
assert!(
|
assert!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue