Skip to content

Commit 12d658a

Browse files
committed
feat(api): revert back to mutations
This reverts commit 8f79037.
1 parent 03b783d commit 12d658a

4 files changed

Lines changed: 15 additions & 22 deletions

File tree

src/app/sub.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,8 @@ where
129129
if !no_sort {
130130
data_tree.par_sort_by(|left, right| left.size().cmp(&right.size()).reverse());
131131
}
132-
133-
// errors caused by failing deduplication shouldn't prevent data_tree from being visualized
134-
match hardlinks_handler.deduplicate(data_tree) {
135-
Ok((data_tree, record)) => (data_tree, Ok(record)),
136-
Err((data_tree, error)) => (data_tree, Err(error)),
137-
}
132+
let deduplication_record = hardlinks_handler.deduplicate(&mut data_tree);
133+
(data_tree, deduplication_record)
138134
};
139135

140136
GLOBAL_STATUS_BOARD.clear_line(0);

src/hardlink/aware.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::{
2-
deduplicate, hardlink_list, DeduplicateSharedSize, HardlinkList, LinkPathList, RecordHardlinks,
2+
hardlink_list, DeduplicateSharedSize, HardlinkList, LinkPathList, RecordHardlinks,
33
RecordHardlinksArgument,
44
};
55
use crate::{
@@ -97,8 +97,8 @@ where
9797
type Error = Infallible;
9898
fn deduplicate(
9999
self,
100-
mut data_tree: DataTree<OsStringDisplay, Size>,
101-
) -> deduplicate::Result<Size, Self::Report, Self::Error> {
100+
data_tree: &mut DataTree<OsStringDisplay, Size>,
101+
) -> Result<Self::Report, Self::Error> {
102102
let record: Self::Report = self.into();
103103
let hardlink_info: Box<[(Size, LinkPathList)]> = record
104104
.iter()
@@ -109,6 +109,6 @@ where
109109
.map(|(size, paths)| (*size, paths.iter().map(AsRef::as_ref).collect()))
110110
.collect();
111111
data_tree.par_deduplicate_hardlinks(&hardlink_info);
112-
Ok((data_tree, record))
112+
Ok(record)
113113
}
114114
}

src/hardlink/deduplicate.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
use crate::{data_tree::DataTree, os_string_display::OsStringDisplay, size};
22

3+
// TODO:
4+
// Consider changing `deduplicate` into taking owned `DataTree` and returning `Result<(DataTree, Self::Report), Self::Error>`.
5+
36
// TODO:
47
// Consider changing `deduplicate` into one that transforms `HardlinkDuplicated<DataTree>` into `DataTree`.
58
// `HardlinkDuplicated` (name is non-final) cannot be constructed manually and is the only type accepted by `deduplicate`.
69

7-
type DataTreeTuple<Size, Other> = (DataTree<OsStringDisplay, Size>, Other);
8-
9-
/// Result type of [`DeduplicateSharedSize::deduplicate`].
10-
pub type Result<Size, Report, Error> =
11-
std::result::Result<DataTreeTuple<Size, Report>, DataTreeTuple<Size, Error>>;
12-
1310
/// Ability to correct the sizes in a [`DataTree`] by reducing the size of recorded shared links.
1411
///
1512
/// The input tree is assumed to be not yet deduplicated.
@@ -21,8 +18,8 @@ pub trait DeduplicateSharedSize<Size: size::Size>: Sized {
2118
/// Correct the sizes in a [`DataTree`] by reducing the size of recorded shared links.
2219
fn deduplicate(
2320
self,
24-
data_tree: DataTree<OsStringDisplay, Size>,
25-
) -> Result<Size, Self::Report, Self::Error>;
21+
data_tree: &mut DataTree<OsStringDisplay, Size>,
22+
) -> Result<Self::Report, Self::Error>;
2623
}
2724

2825
/// Do deduplicate the sizes of hardlinks.

src/hardlink/ignorant.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{deduplicate, DeduplicateSharedSize, RecordHardlinks, RecordHardlinksArgument};
1+
use super::{DeduplicateSharedSize, RecordHardlinks, RecordHardlinksArgument};
22
use crate::{data_tree::DataTree, os_string_display::OsStringDisplay, size};
33
use std::convert::Infallible;
44

@@ -37,8 +37,8 @@ where
3737
/// Do nothing.
3838
fn deduplicate(
3939
self,
40-
data_tree: DataTree<OsStringDisplay, Size>,
41-
) -> deduplicate::Result<Size, Self::Report, Self::Error> {
42-
Ok((data_tree, ()))
40+
_: &mut DataTree<OsStringDisplay, Size>,
41+
) -> Result<Self::Report, Self::Error> {
42+
Ok(())
4343
}
4444
}

0 commit comments

Comments
 (0)