Skip to content

Commit 8d50e37

Browse files
committed
Merge branch 'hardlink-awareness' into tmp.test.windows-path-join-absolute
2 parents 5f10ccd + cbc0982 commit 8d50e37

8 files changed

Lines changed: 42 additions & 25 deletions

File tree

src/data_tree/hardlink.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ where
1111
Size: size::Size + Sync,
1212
{
1313
/// Reduce the size of the directories that have hardlinks.
14+
#[cfg_attr(not(unix), expect(unused))]
1415
pub(crate) fn par_deduplicate_hardlinks(&mut self, hardlink_info: &[(Size, Vec<&Path>)]) {
1516
if hardlink_info.is_empty() {
1617
return;

src/hardlink/deduplicate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub trait DeduplicateSharedSize<Size: size::Size>: Sized {
1616
}
1717

1818
/// Do deduplicate the sizes of hardlinks.
19+
#[cfg(unix)]
1920
pub type Do<Size> = super::HardlinkAware<Size>;
2021
/// Do not deduplicate the sizes of hardlinks.
2122
pub type DoNot = super::HardlinkIgnorant;

src/hardlink/hardlink_list.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ impl<Size> HardlinkList<Size> {
6060
}
6161
}
6262

63-
/// Error that occurs when a different size was detected for the same [`ino`](std::os::unix::fs::MetadataExt::ino).
63+
/// Error that occurs when a different size was detected for the same [`ino`][ino].
64+
///
65+
/// <!-- Should have been `std::os::unix::fs::MetadataExt::ino` but it would error on Windows -->
66+
/// [ino]: https://doc.rust-lang.org/std/os/unix/fs/trait.MetadataExt.html#tymethod.ino
6467
#[derive(Debug, Display, Error)]
6568
#[display(bound(Size: Debug))]
6669
#[display("Size for inode {ino} changed from {recorded:?} to {detected:?}")]
@@ -83,6 +86,7 @@ where
8386
Size: size::Size,
8487
{
8588
/// Add an entry to the record.
89+
#[cfg_attr(not(unix), expect(unused))]
8690
pub(crate) fn add(
8791
&self,
8892
ino: InodeNumber,

src/hardlink/record.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub trait RecordHardlinks<Size, Reporter: ?Sized> {
3636
}
3737

3838
/// Do detect and record hardlinks.
39+
#[cfg(unix)]
3940
pub type Do<Size> = super::HardlinkAware<Size>;
4041
/// Do not detect nor record hardlinks.
4142
pub type DoNot = super::HardlinkIgnorant;

tests/cli_errors.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
#![cfg(feature = "cli")]
2+
#![cfg_attr(not(unix), allow(unused))] // TODO: remove this after merging from master
23

34
pub mod _utils;
45
pub use _utils::*;
56

67
use command_extra::CommandExtra;
8+
use pipe_trait::Pipe;
9+
use pretty_assertions::assert_eq;
10+
use std::process::{Command, Output, Stdio};
11+
use text_block_macros::text_block;
12+
13+
#[cfg(unix)]
714
use maplit::btreeset;
15+
#[cfg(unix)]
816
use parallel_disk_usage::{
917
bytes_format::BytesFormat,
1018
data_tree::DataTree,
@@ -15,14 +23,8 @@ use parallel_disk_usage::{
1523
reporter::{ErrorOnlyReporter, ErrorReport},
1624
visualizer::{BarAlignment, ColumnWidthDistribution, Direction, Visualizer},
1725
};
18-
use pipe_trait::Pipe;
19-
use pretty_assertions::assert_eq;
20-
use std::{
21-
collections::BTreeSet,
22-
path::Path,
23-
process::{Command, Output, Stdio},
24-
};
25-
use text_block_macros::text_block;
26+
#[cfg(unix)]
27+
use std::{collections::BTreeSet, path::Path};
2628

2729
#[cfg(windows)]
2830
fn test_path_join_absolute() {

tests/data_tree_reflection.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,15 @@ fn display_excessive_children() {
136136
.par_try_into_tree()
137137
.expect_err("create error")
138138
.to_string();
139-
let expected = r#"ExcessiveChildren: "root/b/0" (Bytes(321)) is less than a child named "def" (Bytes(456))"#;
139+
let expected = if cfg!(unix) {
140+
r#"ExcessiveChildren: "root/b/0" (Bytes(321)) is less than a child named "def" (Bytes(456))"#
141+
} else if cfg!(windows) {
142+
// TODO: stop using debug format
143+
r#"ExcessiveChildren: "root\\b\\0" (Bytes(321)) is less than a child named "def" (Bytes(456))"#
144+
} else {
145+
eprintln!("ACTUAL: {actual}");
146+
panic!("This platform isn't supported!");
147+
};
140148
assert_eq!(actual, expected);
141149
}
142150

tests/fs_tree_builder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
pub mod _utils;
22
pub use _utils::*;
33

4-
use parallel_disk_usage::{
5-
get_size::{GetApparentSize, GetBlockCount, GetBlockSize},
6-
size::Bytes,
7-
};
4+
use parallel_disk_usage::{get_size::GetApparentSize, size::Bytes};
85

96
#[cfg(unix)]
10-
use parallel_disk_usage::size::Blocks;
7+
use parallel_disk_usage::{
8+
get_size::{GetBlockCount, GetBlockSize},
9+
size::Blocks,
10+
};
1111

1212
#[test]
1313
fn len_as_bytes() {

tests/usual_cli.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use parallel_disk_usage::{
88
bytes_format::BytesFormat,
99
data_tree::DataTree,
1010
fs_tree_builder::FsTreeBuilder,
11-
get_size::{GetApparentSize, GetBlockCount, GetBlockSize},
11+
get_size::GetApparentSize,
1212
hardlink::HardlinkIgnorant,
1313
os_string_display::OsStringDisplay,
1414
reporter::{ErrorOnlyReporter, ErrorReport},
@@ -18,6 +18,9 @@ use pipe_trait::Pipe;
1818
use pretty_assertions::assert_eq;
1919
use std::process::{Command, Stdio};
2020

21+
#[cfg(unix)]
22+
use parallel_disk_usage::get_size::{GetBlockCount, GetBlockSize};
23+
2124
fn stdio(command: Command) -> Command {
2225
command
2326
.with_stdin(Stdio::null())
@@ -448,14 +451,13 @@ fn quantity_block_count() {
448451
assert_eq!(actual, expected);
449452
}
450453

451-
#[cfg(unix)]
452454
#[test]
453455
fn bytes_format_plain() {
454456
let workspace = SampleWorkspace::default();
455457
let actual = Command::new(PDU)
456458
.with_current_dir(&workspace)
457459
.with_arg("--total-width=100")
458-
.with_arg("--quantity=block-size")
460+
.with_arg("--quantity=apparent-size")
459461
.with_arg("--bytes-format=plain")
460462
.pipe(stdio)
461463
.output()
@@ -465,7 +467,7 @@ fn bytes_format_plain() {
465467

466468
let builder = FsTreeBuilder {
467469
root: workspace.to_path_buf(),
468-
size_getter: GetBlockSize,
470+
size_getter: GetApparentSize,
469471
hardlinks_recorder: &HardlinkIgnorant,
470472
reporter: &ErrorOnlyReporter::new(ErrorReport::SILENT),
471473
max_depth: 10,
@@ -488,14 +490,13 @@ fn bytes_format_plain() {
488490
assert_eq!(actual, expected);
489491
}
490492

491-
#[cfg(unix)]
492493
#[test]
493494
fn bytes_format_metric() {
494495
let workspace = SampleWorkspace::default();
495496
let actual = Command::new(PDU)
496497
.with_current_dir(&workspace)
497498
.with_arg("--total-width=100")
498-
.with_arg("--quantity=block-size")
499+
.with_arg("--quantity=apparent-size")
499500
.with_arg("--bytes-format=metric")
500501
.pipe(stdio)
501502
.output()
@@ -505,7 +506,7 @@ fn bytes_format_metric() {
505506

506507
let builder = FsTreeBuilder {
507508
root: workspace.to_path_buf(),
508-
size_getter: GetBlockSize,
509+
size_getter: GetApparentSize,
509510
hardlinks_recorder: &HardlinkIgnorant,
510511
reporter: &ErrorOnlyReporter::new(ErrorReport::SILENT),
511512
max_depth: 10,
@@ -528,14 +529,13 @@ fn bytes_format_metric() {
528529
assert_eq!(actual, expected);
529530
}
530531

531-
#[cfg(unix)]
532532
#[test]
533533
fn bytes_format_binary() {
534534
let workspace = SampleWorkspace::default();
535535
let actual = Command::new(PDU)
536536
.with_current_dir(&workspace)
537537
.with_arg("--total-width=100")
538-
.with_arg("--quantity=block-size")
538+
.with_arg("--quantity=apparent-size")
539539
.with_arg("--bytes-format=binary")
540540
.pipe(stdio)
541541
.output()
@@ -545,7 +545,7 @@ fn bytes_format_binary() {
545545

546546
let builder = FsTreeBuilder {
547547
root: workspace.to_path_buf(),
548-
size_getter: GetBlockSize,
548+
size_getter: GetApparentSize,
549549
hardlinks_recorder: &HardlinkIgnorant,
550550
reporter: &ErrorOnlyReporter::new(ErrorReport::SILENT),
551551
max_depth: 10,

0 commit comments

Comments
 (0)