From 6df8af91bb93c4d8be9780051acba4dcdaafac67 Mon Sep 17 00:00:00 2001 From: glitchySid Date: Mon, 29 Dec 2025 18:47:50 +0530 Subject: [PATCH] added recursive file reading using --recursive flag. added a feature to scan subdirectory and organize the file structure even further. --- Cargo.lock | 448 ++++++++++++--------------------------------- Cargo.toml | 3 +- README.md | 4 +- src/files.rs | 39 ++-- src/files_tests.rs | 41 ++++- src/main.rs | 4 +- 6 files changed, 187 insertions(+), 352 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b268079..0faab76 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -53,16 +53,16 @@ dependencies = [ ] [[package]] -name = "atomic-waker" -version = "1.1.2" +name = "base64" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] -name = "base64" -version = "0.22.1" +name = "bitflags" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" @@ -282,21 +282,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.2" @@ -430,15 +415,15 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.12" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c0b69cfcb4e1b9f1bf2f53f95f766e4661169728ec61cd3fe5a0166f2d1386" +checksum = "0beca50380b1fc32983fc1cb4587bfa4bb9e78fc259aad4a0032d2080309222d" dependencies = [ - "atomic-waker", "bytes", "fnv", "futures-core", "futures-sink", + "futures-util", "http", "indexmap", "slab", @@ -467,34 +452,23 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "http" -version = "1.4.0" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" dependencies = [ "bytes", + "fnv", "itoa", ] [[package]] name = "http-body" -version = "1.0.1" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", "http", -] - -[[package]] -name = "http-body-util" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" -dependencies = [ - "bytes", - "futures-core", - "http", - "http-body", "pin-project-lite", ] @@ -505,83 +479,47 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" [[package]] -name = "hyper" -version = "1.8.1" +name = "httpdate" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "0.14.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7" dependencies = [ - "atomic-waker", "bytes", "futures-channel", "futures-core", + "futures-util", "h2", "http", "http-body", "httparse", + "httpdate", "itoa", "pin-project-lite", - "pin-utils", - "smallvec", + "socket2 0.5.10", "tokio", + "tower-service", + "tracing", "want", ] [[package]] name = "hyper-rustls" -version = "0.27.7" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" +checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ - "http", - "hyper", - "hyper-util", - "rustls", - "rustls-pki-types", - "tokio", - "tokio-rustls", - "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", -] - -[[package]] -name = "hyper-util" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "727805d60e7938b76b826a6ef209eb70eaa1812794f9424d4a4e2d740662df5f" -dependencies = [ - "base64", - "bytes", - "futures-channel", - "futures-core", "futures-util", "http", - "http-body", "hyper", - "ipnet", - "libc", - "percent-encoding", - "pin-project-lite", - "socket2", - "system-configuration", + "rustls", "tokio", - "tower-service", - "tracing", - "windows-registry", + "tokio-rustls", ] [[package]] @@ -702,16 +640,6 @@ version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" -[[package]] -name = "iri-string" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f867b9d1d896b67beb18518eda36fdb77a32ea590de864f1325b294a6d14397" -dependencies = [ - "memchr", - "serde", -] - [[package]] name = "is_terminal_polyfill" version = "1.70.2" @@ -746,7 +674,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" dependencies = [ - "bitflags", + "bitflags 2.10.0", "libc", ] @@ -791,23 +719,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "native-tls" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "noentropy" version = "0.1.0" @@ -825,6 +736,7 @@ dependencies = [ "thiserror 2.0.17", "tokio", "toml", + "walkdir", ] [[package]] @@ -839,50 +751,6 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" -[[package]] -name = "openssl" -version = "0.10.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08838db121398ad17ab8531ce9de97b244589089e290a384c900cb9ff7434328" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" - -[[package]] -name = "openssl-sys" -version = "0.9.111" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82cab2d520aa75e3c58898289429321eb788c3106963d0dc886ec7a5f4adc321" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "option-ext" version = "0.2.0" @@ -907,12 +775,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" - [[package]] name = "potential_utf" version = "0.1.4" @@ -959,42 +821,43 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.26" +version = "0.11.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b4c14b2d9afca6a60277086b0cc6a6ae0b568f6f7916c943a8cdc79f8be240f" +checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" dependencies = [ "base64", "bytes", "encoding_rs", "futures-core", + "futures-util", "h2", "http", "http-body", - "http-body-util", "hyper", "hyper-rustls", - "hyper-tls", - "hyper-util", + "ipnet", "js-sys", "log", "mime", - "native-tls", + "once_cell", "percent-encoding", "pin-project-lite", - "rustls-pki-types", + "rustls", + "rustls-pemfile", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", + "system-configuration", "tokio", - "tokio-native-tls", - "tower", - "tower-http", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", + "winreg", ] [[package]] @@ -1017,7 +880,7 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" dependencies = [ - "bitflags", + "bitflags 2.10.0", "errno", "libc", "linux-raw-sys", @@ -1026,34 +889,32 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.35" +version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "533f54bc6a7d4f647e46ad909549eda97bf5afc1585190ef692b4286b198bd8f" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ - "once_cell", - "rustls-pki-types", + "log", + "ring", "rustls-webpki", - "subtle", - "zeroize", + "sct", ] [[package]] -name = "rustls-pki-types" -version = "1.13.2" +name = "rustls-pemfile" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21e6f2ab2928ca4291b86736a8bd920a277a399bba1589409d72154ff87c1282" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "zeroize", + "base64", ] [[package]] name = "rustls-webpki" -version = "0.103.8" +version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffdfa2f5286e2247234e03f680868ac2815974dc39e00ea15adc445d0aafe52" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ "ring", - "rustls-pki-types", "untrusted", ] @@ -1070,35 +931,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] -name = "schannel" -version = "0.1.28" +name = "same-file" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" dependencies = [ - "windows-sys 0.61.2", + "winapi-util", ] [[package]] -name = "security-framework" -version = "2.11.1" +name = "sct" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc1f0cbffaac4852523ce30d8bd3c5cdc873501d96ff467ca09b6767bb8cd5c0" -dependencies = [ - "core-foundation-sys", - "libc", + "ring", + "untrusted", ] [[package]] @@ -1194,6 +1042,16 @@ version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +[[package]] +name = "socket2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "socket2" version = "0.6.1" @@ -1216,12 +1074,6 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - [[package]] name = "syn" version = "2.0.111" @@ -1235,12 +1087,9 @@ dependencies = [ [[package]] name = "sync_wrapper" -version = "1.0.2" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" -dependencies = [ - "futures-core", -] +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[package]] name = "synstructure" @@ -1255,20 +1104,20 @@ dependencies = [ [[package]] name = "system-configuration" -version = "0.6.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "system-configuration-sys", ] [[package]] name = "system-configuration-sys" -version = "0.6.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" dependencies = [ "core-foundation-sys", "libc", @@ -1347,7 +1196,7 @@ dependencies = [ "libc", "mio", "pin-project-lite", - "socket2", + "socket2 0.6.1", "tokio-macros", "windows-sys 0.61.2", ] @@ -1363,21 +1212,11 @@ dependencies = [ "syn", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" -version = "0.26.4" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ "rustls", "tokio", @@ -1437,45 +1276,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" -[[package]] -name = "tower" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" -dependencies = [ - "futures-core", - "futures-util", - "pin-project-lite", - "sync_wrapper", - "tokio", - "tower-layer", - "tower-service", -] - -[[package]] -name = "tower-http" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" -dependencies = [ - "bitflags", - "bytes", - "futures-util", - "http", - "http-body", - "iri-string", - "pin-project-lite", - "tower", - "tower-layer", - "tower-service", -] - -[[package]] -name = "tower-layer" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" - [[package]] name = "tower-service" version = "0.3.3" @@ -1549,18 +1349,22 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" @@ -1653,41 +1457,27 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" -[[package]] -name = "windows-registry" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" -dependencies = [ - "windows-link", - "windows-result", - "windows-strings", -] - -[[package]] -name = "windows-result" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-strings" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" -dependencies = [ - "windows-link", -] - [[package]] name = "windows-sys" version = "0.48.0" @@ -1919,6 +1709,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + [[package]] name = "wit-bindgen" version = "0.46.0" @@ -1975,12 +1775,6 @@ dependencies = [ "synstructure", ] -[[package]] -name = "zeroize" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" - [[package]] name = "zerotrie" version = "0.2.3" diff --git a/Cargo.toml b/Cargo.toml index 5063308..a7e385b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,13 +9,14 @@ colored = "3.0.0" directories = "5.0.1" futures = "0.3.31" hex = "0.4.3" -reqwest = { version = "0.12.26", features = ["json"] } +reqwest = { version = "0.11", default-features = false, features = ["rustls-tls", "json"] } serde = { version = "1.0.228", features = ["derive"] } serde_json = "1.0.145" sha2 = "0.10.8" thiserror = "2.0.11" tokio = { version = "1.48.0", features = ["rt-multi-thread", "macros", "sync", "time"] } toml = "0.8.19" +walkdir = "2.5.0" [dev-dependencies] tempfile = "3.15" diff --git a/README.md b/README.md index e3adf61..a2145eb 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ NoEntropy follows a five-step process to organize your files: ``` ┌─────────────────┐ -│ 1. Scan Files │ → Read all files in DOWNLOAD_FOLDER +│ 1. Scan Files │ → Read all files in DOWNLOAD_FOLDER (and subdir if --recursive flag is used) └────────┬────────┘ ▼ ┌─────────────────────────┐ @@ -334,7 +334,7 @@ noentropy/ Based on community feedback, we're planning: - [ ] **Custom Categories** - Define custom categories in `config.toml` -- [ ] **Recursive Mode** - Organize files in subdirectories with `--recursive` flag +- [x] **Recursive Mode** - Organize files in subdirectories with `--recursive` flag - [ ] **Undo Functionality** - Revert file organization changes - [ ] **Custom Models** - Support for other AI providers - [ ] **GUI Version** - Desktop application for non-CLI users diff --git a/src/files.rs b/src/files.rs index e6c2e3d..c647931 100644 --- a/src/files.rs +++ b/src/files.rs @@ -2,6 +2,7 @@ use colored::*; use serde::{Deserialize, Serialize}; use std::io; use std::{ffi::OsStr, fs, path::Path, path::PathBuf}; +use walkdir::WalkDir; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct FileCategory { @@ -21,31 +22,31 @@ pub struct FileBatch { impl FileBatch { /// Reads a directory path and populates lists of all files inside it. /// It skips sub-directories (does not read recursively). - pub fn from_path(root_path: PathBuf) -> Self { + pub fn from_path(root_path: PathBuf, recursive: bool) -> Self { let mut filenames = Vec::new(); let mut paths = Vec::new(); - - let entries = match fs::read_dir(&root_path) { - Ok(entries) => entries, - Err(e) => { - eprintln!("Error reading directory {:?}: {}", root_path, e); - return FileBatch { - filenames: Vec::new(), - paths: Vec::new(), - }; - } + let walker = if recursive { + WalkDir::new(&root_path).min_depth(1).follow_links(false) + } else { + WalkDir::new(&root_path) + .min_depth(1) + .max_depth(1) + .follow_links(false) }; - - for entry in entries.flatten() { + for entry in walker.into_iter().filter_map(|e| e.ok()) { let path = entry.path(); - if path.is_file() - && let Ok(relative_path) = path.strip_prefix(&root_path) - { - filenames.push(relative_path.to_string_lossy().into_owned()); - paths.push(path); + if path.is_file() { + match path.strip_prefix(&root_path) { + Ok(relative_path) => { + filenames.push(relative_path.to_string_lossy().into_owned()); + paths.push(path.to_path_buf()); + } + Err(e) => { + eprintln!("Error getting relative path for {:?}: {}", path, e); + } + } } } - FileBatch { filenames, paths } } diff --git a/src/files_tests.rs b/src/files_tests.rs index 2dfa911..d207b2e 100644 --- a/src/files_tests.rs +++ b/src/files_tests.rs @@ -35,7 +35,7 @@ fn test_file_batch_from_path() { File::create(dir_path.join("file2.rs")).unwrap(); fs::create_dir(dir_path.join("subdir")).unwrap(); - let batch = FileBatch::from_path(dir_path.to_path_buf()); + let batch = FileBatch::from_path(dir_path.to_path_buf(), false); assert_eq!(batch.count(), 2); assert!(batch.filenames.contains(&"file1.txt".to_string())); assert!(batch.filenames.contains(&"file2.rs".to_string())); @@ -43,10 +43,47 @@ fn test_file_batch_from_path() { #[test] fn test_file_batch_from_path_nonexistent() { - let batch = FileBatch::from_path(PathBuf::from("/nonexistent/path")); + let batch = FileBatch::from_path(PathBuf::from("/nonexistent/path"), false); assert_eq!(batch.count(), 0); } +#[test] +fn test_file_batch_from_path_non_recursive() { + let temp_dir = tempfile::tempdir().unwrap(); + let dir_path = temp_dir.path(); + File::create(dir_path.join("file1.txt")).unwrap(); + File::create(dir_path.join("file2.rs")).unwrap(); + fs::create_dir(dir_path.join("subdir")).unwrap(); + File::create(dir_path.join("subdir").join("file3.txt")).unwrap(); + let batch = FileBatch::from_path(dir_path.to_path_buf(), false); + assert_eq!(batch.count(), 2); + assert!(batch.filenames.contains(&"file1.txt".to_string())); + assert!(batch.filenames.contains(&"file2.rs".to_string())); + assert!(!batch.filenames.contains(&"subdir/file3.txt".to_string())); +} + +#[test] +fn test_file_batch_from_path_recursive() { + let temp_dir = tempfile::tempdir().unwrap(); + let dir_path = temp_dir.path(); + File::create(dir_path.join("file1.txt")).unwrap(); + fs::create_dir(dir_path.join("subdir1")).unwrap(); + File::create(dir_path.join("subdir1").join("file2.rs")).unwrap(); + fs::create_dir(dir_path.join("subdir1").join("nested")).unwrap(); + File::create(dir_path.join("subdir1").join("nested").join("file3.md")).unwrap(); + fs::create_dir(dir_path.join("subdir2")).unwrap(); + File::create(dir_path.join("subdir2").join("file4.py")).unwrap(); + let batch = FileBatch::from_path(dir_path.to_path_buf(), true); + assert_eq!(batch.count(), 4); + assert!(batch.filenames.contains(&"file1.txt".to_string())); + assert!(batch.filenames.contains(&"subdir1/file2.rs".to_string())); + assert!( + batch + .filenames + .contains(&"subdir1/nested/file3.md".to_string()) + ); + assert!(batch.filenames.contains(&"subdir2/file4.py".to_string())); +} #[test] fn test_read_file_sample() { let temp_dir = tempfile::tempdir().unwrap(); diff --git a/src/main.rs b/src/main.rs index 1a77809..44c0cd8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,8 @@ struct Args { help = "Maximum concurrent API requests" )] max_concurrent: usize, + #[arg(long, help = "Recursively searches files in subdirectory")] + recursive: bool, } #[tokio::main] @@ -37,7 +39,7 @@ async fn main() -> Result<(), Box> { cache.cleanup_old_entries(7 * 24 * 60 * 60); - let batch = FileBatch::from_path(download_path.clone()); + let batch = FileBatch::from_path(download_path.clone(), args.recursive); if batch.filenames.is_empty() { println!("{}", "No files found to organize!".yellow());