Repository: pkolaczk/fclones (language: rust)

Issue:
Tests failing on file systems which don't support querying file creation (birth) time like zfs or f2fs
fclones fails to build on my Arch Linux f2fs partition.
```
failures:

---- dedupe::test::test_partition_respects_creation_time_priority stdout ----
[2021-07-29 18:44:45.674] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/ctime_priority/file_3: creation time is not available for the filesystem
[2021-07-29 18:44:45.674] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/ctime_priority/file_2: creation time is not available for the filesystem
[2021-07-29 18:44:45.674] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/ctime_priority/file_2: creation time is not available for the filesystem
[2021-07-29 18:44:45.674] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/ctime_priority/file_1: creation time is not available for the filesystem
thread 'dedupe::test::test_partition_respects_creation_time_priority' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: "Could not determine files to drop in group with hash 00000000000000000000000000000000 and len 0: Metadata of some files could not be read." }', src/dedupe.rs:856:80
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- dedupe::test::test_partition_respects_drop_patterns stdout ----
[2021-07-29 18:44:45.675] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/drop/file_3: creation time is not available for the filesystem
[2021-07-29 18:44:45.675] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/drop/file_2: creation time is not available for the filesystem
[2021-07-29 18:44:45.675] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/drop/file_2: creation time is not available for the filesystem
[2021-07-29 18:44:45.675] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/drop/file_1: creation time is not available for the filesystem
thread 'dedupe::test::test_partition_respects_drop_patterns' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: "Could not determine files to drop in group with hash 00000000000000000000000000000000 and len 0: Metadata of some files could not be read." }', src/dedupe.rs:923:68

---- dedupe::test::test_partition_respects_keep_patterns stdout ----
[2021-07-29 18:44:45.675] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/keep/file_3: creation time is not available for the filesystem
[2021-07-29 18:44:45.675] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/keep/file_2: creation time is not available for the filesystem
[2021-07-29 18:44:45.675] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/keep/file_2: creation time is not available for the filesystem
[2021-07-29 18:44:45.675] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/keep/file_1: creation time is not available for the filesystem
thread 'dedupe::test::test_partition_respects_keep_patterns' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: "Could not determine files to drop in group with hash 00000000000000000000000000000000 and len 0: Metadata of some files could not be read." }', src/dedupe.rs:904:68

---- dedupe::test::test_run_dedupe_script stdout ----
[2021-07-29 18:44:45.676] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/dedupe_script/file_3: creation time is not available for the filesystem
[2021-07-29 18:44:45.676] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/dedupe_script/file_2: creation time is not available for the filesystem
[2021-07-29 18:44:45.676] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/dedupe_script/file_2: creation time is not available for the filesystem
[2021-07-29 18:44:45.676] fclones-6cdeb7b3f6a11fd5:  warn: Failed to read creation time of file /home/et/yay/fclones/src/fclones-0.12.3/target/test/dedupe/partition/dedupe_script/file_1: creation time is not available for the filesystem
[2021-07-29 18:44:45.676] fclones-6cdeb7b3f6a11fd5:  warn: Could not determine files to drop in group with hash 00000000000000000000000000000000 and len 0: Metadata of some files could not be read.
thread 'dedupe::test::test_run_dedupe_script' panicked at 'assertion failed: `(left == right)`
  left: `0`,
 right: `2`', src/dedupe.rs:944:13


failures:
    dedupe::test::test_partition_respects_creation_time_priority
    dedupe::test::test_partition_respects_drop_patterns
    dedupe::test::test_partition_respects_keep_patterns
    dedupe::test::test_run_dedupe_script

test result: FAILED. 94 passed; 4 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.49s

error: test failed, to rerun pass '--lib'
```


Discussion / hints:
This is a known issue. This isn't anything serious - it only means that on some file systems you're not able to pick files for deletion based on their creation time. I think I need to make the test properly detect the creation time feature is not supported and then just skip the tests which rely on it. And some other tests are probably ok to change to use modification time rather than creation time.

Fix patch:
diff --git a/src/dedupe.rs b/src/dedupe.rs
index 9cffcc7..94f4ea9 100644
--- a/src/dedupe.rs
+++ b/src/dedupe.rs
@@ -849,8 +849,12 @@ mod test {
     #[test]
     fn test_partition_respects_creation_time_priority() {
         with_dir("dedupe/partition/ctime_priority", |root| {
+            if fs::metadata(root).unwrap().created().is_err() {
+                // can't run the test because the filesystem doesn't support fetching
+                // file creation time
+                return;
+            }
             let group = make_group(root);
-
             let mut config = DedupeConfig::default();
             config.priority = vec![Priority::Newest];
             let partitioned_1 = partition(group.clone(), &config, &Log::new()).unwrap();
@@ -899,7 +903,7 @@ mod test {
         with_dir("dedupe/partition/keep", |root| {
             let group = make_group(root);
             let mut config = DedupeConfig::default();
-            config.priority = vec![Priority::Oldest];
+            config.priority = vec![Priority::LeastRecentlyModified];
             config.keep_name_patterns = vec![Pattern::glob("*_1").unwrap()];
             let p = partition(group.clone(), &config, &Log::new()).unwrap();
             assert_eq!(p.to_keep.len(), 1);
@@ -918,7 +922,7 @@ mod test {
         with_dir("dedupe/partition/drop", |root| {
             let group = make_group(root);
             let mut config = DedupeConfig::default();
-            config.priority = vec![Priority::Oldest];
+            config.priority = vec![Priority::LeastRecentlyModified];
             config.name_patterns = vec![Pattern::glob("*_3").unwrap()];
             let p = partition(group.clone(), &config, &Log::new()).unwrap();
             assert_eq!(p.to_drop.len(), 1);
@@ -937,7 +941,7 @@ mod test {
         with_dir("dedupe/partition/dedupe_script", |root| {
             let group = make_group(root);
             let mut config = DedupeConfig::default();
-            config.priority = vec![Priority::Oldest]; // remove oldest
+            config.priority = vec![Priority::LeastRecentlyModified];
             let log = Log::new();
             let script = dedupe(vec![group], DedupeOp::Remove, &config, &log);
             let dedupe_result = run_script(script, &log);


Test patch: