summaryrefslogtreecommitdiffstats
path: root/src/file_sum
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2020-09-06 18:43:31 +0200
committerCanop <cano.petrole@gmail.com>2020-09-06 18:43:31 +0200
commit5083dd0075d6f3753c4d72a6e7d37568283f0cc7 (patch)
tree45cc26adba11616b344ae9ca2952733b0a4a308f /src/file_sum
parent84995c105161aa7641ab2042fd58ef2d26354b05 (diff)
identify nodes with (inode, dev) instead of just inode in size summing
thus removing the theoretical risk of not counting some files because of an inode number found on two devices
Diffstat (limited to 'src/file_sum')
-rw-r--r--src/file_sum/sum_computation.rs28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/file_sum/sum_computation.rs b/src/file_sum/sum_computation.rs
index 27fff19..1e89945 100644
--- a/src/file_sum/sum_computation.rs
+++ b/src/file_sum/sum_computation.rs
@@ -23,6 +23,24 @@ use {
},
};
+/// a node id, taking the device into account to be sure to discriminate
+/// nodes with the same inode but on different devices
+#[derive(Debug, Clone, Copy, PartialEq, Hash, Eq)]
+struct NodeId {
+ /// inode number
+ inode: u64,
+ /// device number
+ dev: u64,
+}
+impl NodeId {
+ fn from(m: &fs::Metadata) -> Self {
+ Self {
+ inode: m.ino(),
+ dev: m.dev(),
+ }
+ }
+}
+
// threads used by one computation
const THREADS_COUNT: usize = 6;
@@ -38,9 +56,9 @@ pub fn compute_dir_sum(path: &Path, dam: &Dam) -> Option<FileSum> {
.num_threads(THREADS_COUNT*2).build().unwrap();
}
- // to avoid counting twice an inode, we store them in a set
+ // to avoid counting twice a node, we store their id in a set
#[cfg(unix)]
- let inodes = Arc::new(Mutex::new(HashSet::<u64>::default()));
+ let nodes = Arc::new(Mutex::new(HashSet::<NodeId>::default()));
// this MPMC channel contains the directory paths which must be handled.
// A None means there's nothing left and the thread may send its result and stop
@@ -62,7 +80,7 @@ pub fn compute_dir_sum(path: &Path, dam: &Dam) -> Option<FileSum> {
let (dirs_sender, dirs_receiver) = (dirs_sender.clone(), dirs_receiver.clone());
#[cfg(unix)]
- let inodes = inodes.clone();
+ let nodes = nodes.clone();
let observer = dam.observer();
let thread_sum_sender = thread_sum_sender.clone();
@@ -83,8 +101,8 @@ pub fn compute_dir_sum(path: &Path, dam: &Dam) -> Option<FileSum> {
#[cfg(unix)]
if md.nlink() > 1 {
- let mut inodes = inodes.lock().unwrap();
- if !inodes.insert(md.ino()) {
+ let mut nodes = nodes.lock().unwrap();
+ if !nodes.insert(NodeId::from(&md)) {
// it was already in the set
continue;
}