diff --git a/Cargo.lock b/Cargo.lock index fb99531..ea292a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,7 +38,7 @@ dependencies = [ "getrandom", "once_cell", "version_check", - "zerocopy 0.7.35", + "zerocopy", ] [[package]] @@ -107,19 +107,20 @@ checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "assert_cmd" -version = "2.0.15" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc65048dd435533bb1baf2ed9956b9a278fbfdcf90301b39ee117f06c0199d37" +checksum = "dc1835b7f27878de8525dc71410b5a31cdcc5f230aed5ba5df968e09c201b23d" dependencies = [ "anstyle", "bstr", "doc-comment", + "libc", "predicates", "predicates-core", "predicates-tree", @@ -165,6 +166,28 @@ dependencies = [ "wyz", ] +[[package]] +name = "bon" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea8256e3cff531086cc3faf94c1649930ff64bceb2d0e8cc84fc0356d7ee9806" +dependencies = [ + "bon-macros", +] + +[[package]] +name = "bon-macros" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b99838f77c5073bc7846ecce92b64e7e5a5bd152a8ec392facf90ee4d90b4b35" +dependencies = [ + "darling", + "ident_case", + "proc-macro2", + "quote", + "syn 2.0.76", +] + [[package]] name = "borsh" version = "1.5.1" @@ -185,7 +208,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.76", "syn_derive", ] @@ -241,15 +264,18 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.1" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" [[package]] name = "cc" -version = "1.1.7" +version = "1.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +dependencies = [ + "shlex", +] [[package]] name = "cfg-if" @@ -265,9 +291,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "clap" -version = "4.5.11" +version = "4.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35723e6a11662c2afb578bcf0b88bf6ea8e21282a953428f240574fcc3a2b5b3" +checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019" dependencies = [ "clap_builder", "clap_derive", @@ -285,9 +311,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.11" +version = "4.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49eb96cbfa7cfa35017b7cd548c75b14c3118c98b423041d70562665e07fb0fa" +checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" dependencies = [ "anstream", "anstyle", @@ -297,14 +323,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.11" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d029b67f89d30bbb547c89fd5161293c0aec155fc691d7924b64550662db93e" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.76", ] [[package]] @@ -374,6 +400,41 @@ dependencies = [ "memchr", ] +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.76", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.76", +] + [[package]] name = "difflib" version = "0.4.0" @@ -409,9 +470,9 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] name = "dunce" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" [[package]] name = "either" @@ -457,6 +518,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "funty" version = "2.0.0" @@ -548,6 +615,12 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "ignore" version = "0.4.22" @@ -566,9 +639,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" dependencies = [ "equivalent", "hashbrown 0.14.5", @@ -588,9 +661,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "libc" -version = "0.2.155" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "libredox" @@ -656,9 +729,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.2" +version = "0.36.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f203fa8daa7bb185f760ae12bd8e097f63d17041dcdcaf675ac54cdf863170e" +checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" dependencies = [ "memchr", ] @@ -688,11 +761,11 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.18" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee4364d9f3b902ef14fab8a1ddffb783a1cb6b4bba3bfc1fa3922732c7de97f" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" dependencies = [ - "zerocopy 0.6.6", + "zerocopy", ] [[package]] @@ -788,9 +861,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -853,9 +926,9 @@ dependencies = [ [[package]] name = "redox_users" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom", "libredox", @@ -864,9 +937,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.5" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -902,9 +975,9 @@ dependencies = [ [[package]] name = "rkyv" -version = "0.7.44" +version = "0.7.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cba464629b3394fc4dbc6f940ff8f5b4ff5c7aef40f29166fd4ad12acbc99c0" +checksum = "9008cd6385b9e161d8229e1f6549dd23c3d022f132a2ea37ac3a10ac4935779b" dependencies = [ "bitvec", "bytecheck", @@ -920,9 +993,9 @@ dependencies = [ [[package]] name = "rkyv_derive" -version = "0.7.44" +version = "0.7.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7dddfff8de25e6f62b9d64e6e432bf1c6736c57d20323e15ee10435fbda7c65" +checksum = "503d1d27590a2b0a3a4ca4c94755aa2875657196ecbf401a42eff41d7de532c0" dependencies = [ "proc-macro2", "quote", @@ -931,9 +1004,9 @@ dependencies = [ [[package]] name = "rust_decimal" -version = "1.35.0" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1790d1c4c0ca81211399e0e0af16333276f375209e71a37b67698a373db5b47a" +checksum = "b082d80e3e3cc52b2ed634388d436fe1f4de6af5786cc2de9ba9737527bdf555" dependencies = [ "arrayvec", "borsh", @@ -974,29 +1047,29 @@ checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" [[package]] name = "serde" -version = "1.0.204" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.204" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.76", ] [[package]] name = "serde_json" -version = "1.0.121" +version = "1.0.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ab380d7d9f22ef3f21ad3e6c1ebe8e4fc7a2000ccba2e4d71fc96f15b2cb609" +checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" dependencies = [ "itoa", "memchr", @@ -1013,6 +1086,12 @@ dependencies = [ "serde", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "simdutf8" version = "0.1.4" @@ -1044,9 +1123,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.72" +version = "2.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" dependencies = [ "proc-macro2", "quote", @@ -1062,7 +1141,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.76", ] [[package]] @@ -1094,7 +1173,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.76", ] [[package]] @@ -1114,21 +1193,21 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "toml" -version = "0.8.16" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81967dd0dd2c1ab0bc3468bd7caecc32b8a4aa47d0c8c695d8c2b2108168d62c" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.17", + "toml_edit 0.22.20", ] [[package]] name = "toml_datetime" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8fb9f64314842840f1d940ac544da178732128f1c78c21772e876579e0da1db" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" dependencies = [ "serde", ] @@ -1146,9 +1225,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.17" +version = "0.22.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d9f8729f5aea9562aac1cc0441f5d6de3cff1ee0c5d67293eeca5eb36ee7c16" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" dependencies = [ "indexmap", "serde", @@ -1167,26 +1246,6 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "typed-builder" -version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06fbd5b8de54c5f7c91f6fe4cebb949be2125d7758e630bb58b1d831dbce600" -dependencies = [ - "typed-builder-macro", -] - -[[package]] -name = "typed-builder-macro" -version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9534daa9fd3ed0bd911d462a37f172228077e7abf18c18a5f67199d959205f8" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.72", -] - [[package]] name = "unicode-ident" version = "1.0.12" @@ -1247,11 +1306,11 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "winapi-util" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1272,6 +1331,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -1413,11 +1481,12 @@ dependencies = [ [[package]] name = "yadf" -version = "1.2.0" +version = "1.3.0" dependencies = [ "ahash 0.8.11", "anyhow", "assert_cmd", + "bon", "byte-unit", "clap", "clap-verbosity-flag", @@ -1442,17 +1511,6 @@ dependencies = [ "serde", "serde_json", "twox-hash", - "typed-builder", -] - -[[package]] -name = "zerocopy" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854e949ac82d619ee9a14c66a1b674ac730422372ccb759ce0c39cabcf2bf8e6" -dependencies = [ - "byteorder", - "zerocopy-derive 0.6.6", ] [[package]] @@ -1461,18 +1519,8 @@ version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ - "zerocopy-derive 0.7.35", -] - -[[package]] -name = "zerocopy-derive" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "125139de3f6b9d625c39e2efdd73d41bdac468ccd556556440e322be0e1bbd91" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.72", + "byteorder", + "zerocopy-derive", ] [[package]] @@ -1483,5 +1531,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.76", ] diff --git a/Cargo.toml b/Cargo.toml index 0529889..d69db3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ build-bin = [ [dependencies] # library dependencies +bon = "2.0.0" crossbeam-channel = "0.5.0" dunce = "1.0.1" globset = "0.4.6" @@ -49,12 +50,15 @@ num_cpus = "1.13.0" rayon = "1.3.1" regex = "1.4.2" serde = "1.0.114" -typed-builder = "0.19.1" # binary dependencies ahash = { version = "0.8.10", optional = true } anyhow = { version = "1.0.38", optional = true } byte-unit = { version = "5.1.4", features = ["byte"], optional = true } -clap = { version = "4.4.14", features = ["cargo", "derive", "string"], optional = true } +clap = { version = "4.4.14", features = [ + "cargo", + "derive", + "string", +], optional = true } clap-verbosity-flag = { version = "2.1.1", optional = true } csv = { version = "1.1.4", optional = true } env_logger = { version = "0.11.2", optional = true } diff --git a/src/fs/filter.rs b/src/fs/filter.rs index 9284fef..072d851 100644 --- a/src/fs/filter.rs +++ b/src/fs/filter.rs @@ -7,27 +7,10 @@ pub struct FileFilter { max: Option, regex: Option, glob: Option, - #[cfg(unix)] inodes_filter: inode::Filter, } impl FileFilter { - #[cfg(not(unix))] - pub fn new( - min: Option, - max: Option, - regex: Option, - glob: Option, - ) -> Self { - Self { - min, - max, - regex, - glob, - } - } - - #[cfg(unix)] pub fn new( min: Option, max: Option, @@ -81,11 +64,9 @@ impl Matcher for globset::GlobMatcher { } } -#[cfg(unix)] mod inode { use std::collections::HashSet; use std::fs::Metadata; - use std::os::unix::fs::MetadataExt; use std::sync::Mutex; /// Filter out unique inodes @@ -100,6 +81,10 @@ mod inode { impl Filter { pub fn new(disable_hard_links_filter: bool) -> Self { + #[cfg(not(unix))] + { + return Self::Disabled; + } if disable_hard_links_filter { Self::Disabled } else { @@ -116,8 +101,14 @@ mod inode { } impl InodeSet { + #[cfg(unix)] fn is_unique(&self, meta: &Metadata) -> bool { + use std::os::unix::fs::MetadataExt; self.0.lock().unwrap().insert(meta.ino()) } + #[cfg(not(unix))] + fn is_unique(&self, meta: &Metadata) -> bool { + true + } } } diff --git a/src/lib.rs b/src/lib.rs index 3ce8347..aa5d10d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ //! //! ```toml //! [dependencies] -//! yadf = { version = "0.15.0", default-features = false } +//! yadf = { version = "*", default-features = false } //! ``` //! //! A collection of functions and structs to find duplicate files. @@ -14,7 +14,7 @@ //! Find and display all the duplicate files at the given paths : //! //! ```no_run -//! # fn foo(paths: &[std::path::PathBuf]) { +//! # fn foo(paths: Vec) { //! let counter = yadf::Yadf::builder() //! .paths(paths) //! .build() @@ -35,7 +35,7 @@ pub use globset; pub use path::Path; pub use regex; use std::hash::Hasher; -use std::rc::Rc; +use std::path::PathBuf; pub type FileCounter = TreeBag; pub type FileReplicates<'a> = bag::Replicates<'a, u64, Path>; @@ -45,49 +45,45 @@ pub type FileReplicates<'a> = bag::Replicates<'a, u64, Path>; /// # Example /// /// ```no_run -/// # fn foo(paths: &[std::path::PathBuf]) { +/// # fn foo(paths: Vec) { /// let counter = yadf::Yadf::builder() /// .paths(paths) // required /// .minimum_file_size(64) // optional /// .maximum_file_size(1024 * 8) // optional -/// .regex(None) // optional -/// .glob(None) // optional +/// .maybe_regex(None) // optional +/// .maybe_glob(None) // optional /// .build() /// .scan::(); /// # } /// ``` /// /// see the docs for the [`YadfBuilder`](YadfBuilder) -#[derive(Debug, typed_builder::TypedBuilder)] -#[builder(doc)] -pub struct Yadf> { - #[builder(setter(into, doc = "Paths that will be checked for duplicate files"))] - paths: Rc<[P]>, - #[builder(default, setter(into, doc = "Minimum file size"))] +#[derive(Debug)] +#[bon::builder] +pub struct Yadf { + /// Paths that will be checked for duplicate files + paths: Vec, + /// Minimum file size minimum_file_size: Option, - #[builder(default, setter(into, doc = "Maximum file size"))] + /// Maximum file size maximum_file_size: Option, - #[builder(default, setter(into, doc = "Maximum recursion depth"))] + /// Maximum recursion depth max_depth: Option, - #[builder(default, setter(into, doc = "File name must match this regex"))] + /// File name must match this regex regex: Option, - #[builder(default, setter(into, doc = "File name must match this glob"))] + /// File name must match this glob glob: Option, - #[cfg(unix)] - #[builder(default, setter(doc = "Treat hard links as duplicates"))] + /// Treat hard links as duplicates + #[builder(default)] hard_links: bool, } -impl

Yadf

-where - P: AsRef, -{ +impl Yadf { /// This will attemps a complete scan according to its configuration. pub fn scan(self) -> FileCounter where H: Hasher + Default, { - #[cfg(unix)] let file_filter = fs::filter::FileFilter::new( self.minimum_file_size, self.maximum_file_size, @@ -95,13 +91,6 @@ where self.glob.map(|g| g.compile_matcher()), self.hard_links, ); - #[cfg(not(unix))] - let file_filter = fs::filter::FileFilter::new( - self.minimum_file_size, - self.maximum_file_size, - self.regex, - self.glob.map(|g| g.compile_matcher()), - ); let bag = fs::find_dupes_partial::(&self.paths, self.max_depth, file_filter); if log::log_enabled!(log::Level::Info) { log::info!( diff --git a/src/main.rs b/src/main.rs index 560f665..1d9d305 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,36 +35,20 @@ fn main() -> anyhow::Result<()> { Ok(()) } -#[cfg(unix)] -fn build_config(args: &Args) -> yadf::Yadf { +fn build_config(args: &Args) -> yadf::Yadf { yadf::Yadf::builder() - .paths(args.paths.as_ref()) - .minimum_file_size(args.min()) - .maximum_file_size(args.max()) - .regex(args.regex.clone()) - .glob(args.pattern.clone()) - .max_depth(args.max_depth) + .paths(args.paths.clone()) + .maybe_minimum_file_size(args.min()) + .maybe_maximum_file_size(args.max()) + .maybe_regex(args.regex.clone()) + .maybe_glob(args.pattern.clone()) + .maybe_max_depth(args.max_depth) .hard_links(args.hard_links) .build() } -#[cfg(not(unix))] -fn build_config(args: &Args) -> yadf::Yadf { - yadf::Yadf::builder() - .paths(args.paths.as_ref()) - .minimum_file_size(args.min()) - .maximum_file_size(args.max()) - .regex(args.regex.clone()) - .glob(args.pattern.clone()) - .max_depth(args.max_depth) - .build() -} - impl Algorithm { - fn run

(&self, config: yadf::Yadf

) -> yadf::FileCounter - where - P: AsRef, - { + fn run(&self, config: yadf::Yadf) -> yadf::FileCounter { log::debug!("using {:?} hashing", self); match self { Algorithm::AHash => config.scan::(), @@ -126,9 +110,8 @@ pub struct Args { /// Maximum recursion depth #[clap(short = 'd', long = "depth", value_name = "depth")] max_depth: Option, - /// Treat hard links to same file as duplicates - #[cfg_attr(unix, clap(short = 'H', long))] - #[cfg(unix)] + /// Treat hard links to same file as duplicates (unix only) + #[clap(short = 'H', long)] hard_links: bool, /// Check files with a name matching a Perl-style regex, /// see: https://docs.rs/regex/1.4.2/regex/index.html#syntax diff --git a/tests/common/mod.rs b/tests/common/mod.rs index b97ec60..32d38f8 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -19,7 +19,7 @@ where #[allow(dead_code)] pub fn find_dupes>(path: &P) -> yadf::FileCounter { yadf::Yadf::builder() - .paths([path].as_ref()) + .paths(vec![path.as_ref().to_owned()]) .build() .scan::() } diff --git a/tests/integration.rs b/tests/integration.rs index 6f54b7f..2a4f86e 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -171,8 +171,6 @@ fn non_utf8_paths() -> AnyResult { #[test] fn hard_links_flag() -> AnyResult { let predicate = predstr::contains("--hard-links"); - #[cfg(not(unix))] - let predicate = predicate.not(); assert_cmd::Command::cargo_bin(assert_cmd::crate_name!())? .arg("-h") .assert()