├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── assets └── cargo-clean-all-demo.gif └── src └── main.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 4 4 | 5 | [[package]] 6 | name = "aho-corasick" 7 | version = "0.7.19" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" 10 | dependencies = [ 11 | "memchr", 12 | ] 13 | 14 | [[package]] 15 | name = "aligned" 16 | version = "0.4.1" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "80a21b9440a626c7fc8573a9e3d3a06b75c7c97754c2949bc7857b90353ca655" 19 | dependencies = [ 20 | "as-slice", 21 | ] 22 | 23 | [[package]] 24 | name = "android-tzdata" 25 | version = "0.1.1" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" 28 | 29 | [[package]] 30 | name = "android_system_properties" 31 | version = "0.1.5" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" 34 | dependencies = [ 35 | "libc", 36 | ] 37 | 38 | [[package]] 39 | name = "anstream" 40 | version = "0.6.18" 41 | source = "registry+https://github.com/rust-lang/crates.io-index" 42 | checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" 43 | dependencies = [ 44 | "anstyle", 45 | "anstyle-parse", 46 | "anstyle-query", 47 | "anstyle-wincon", 48 | "colorchoice", 49 | "is_terminal_polyfill", 50 | "utf8parse", 51 | ] 52 | 53 | [[package]] 54 | name = "anstyle" 55 | version = "1.0.10" 56 | source = "registry+https://github.com/rust-lang/crates.io-index" 57 | checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" 58 | 59 | [[package]] 60 | name = "anstyle-parse" 61 | version = "0.2.0" 62 | source = "registry+https://github.com/rust-lang/crates.io-index" 63 | checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" 64 | dependencies = [ 65 | "utf8parse", 66 | ] 67 | 68 | [[package]] 69 | name = "anstyle-query" 70 | version = "1.0.0" 71 | source = "registry+https://github.com/rust-lang/crates.io-index" 72 | checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" 73 | dependencies = [ 74 | "windows-sys 0.48.0", 75 | ] 76 | 77 | [[package]] 78 | name = "anstyle-wincon" 79 | version = "3.0.7" 80 | source = "registry+https://github.com/rust-lang/crates.io-index" 81 | checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" 82 | dependencies = [ 83 | "anstyle", 84 | "once_cell", 85 | "windows-sys 0.59.0", 86 | ] 87 | 88 | [[package]] 89 | name = "as-slice" 90 | version = "0.2.1" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | checksum = "516b6b4f0e40d50dcda9365d53964ec74560ad4284da2e7fc97122cd83174516" 93 | dependencies = [ 94 | "stable_deref_trait", 95 | ] 96 | 97 | [[package]] 98 | name = "autocfg" 99 | version = "1.1.0" 100 | source = "registry+https://github.com/rust-lang/crates.io-index" 101 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 102 | 103 | [[package]] 104 | name = "bitflags" 105 | version = "1.3.2" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 108 | 109 | [[package]] 110 | name = "bitflags" 111 | version = "2.4.1" 112 | source = "registry+https://github.com/rust-lang/crates.io-index" 113 | checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" 114 | 115 | [[package]] 116 | name = "bumpalo" 117 | version = "3.11.1" 118 | source = "registry+https://github.com/rust-lang/crates.io-index" 119 | checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" 120 | 121 | [[package]] 122 | name = "bytefmt" 123 | version = "0.1.7" 124 | source = "registry+https://github.com/rust-lang/crates.io-index" 125 | checksum = "590b1af059a21c47d4da7cd11f05e08b1992b58b5b4acf2a5e10d7e53aed3d74" 126 | dependencies = [ 127 | "regex", 128 | ] 129 | 130 | [[package]] 131 | name = "cargo-clean-all" 132 | version = "0.6.4" 133 | dependencies = [ 134 | "bytefmt", 135 | "chrono", 136 | "clap", 137 | "colored", 138 | "crossbeam-channel", 139 | "ctrlc", 140 | "dialoguer", 141 | "indicatif", 142 | "is_executable", 143 | "num_cpus", 144 | "remove_dir_all 1.0.0", 145 | ] 146 | 147 | [[package]] 148 | name = "cc" 149 | version = "1.0.74" 150 | source = "registry+https://github.com/rust-lang/crates.io-index" 151 | checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574" 152 | 153 | [[package]] 154 | name = "cfg-if" 155 | version = "1.0.0" 156 | source = "registry+https://github.com/rust-lang/crates.io-index" 157 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 158 | 159 | [[package]] 160 | name = "cfg_aliases" 161 | version = "0.2.1" 162 | source = "registry+https://github.com/rust-lang/crates.io-index" 163 | checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" 164 | 165 | [[package]] 166 | name = "chrono" 167 | version = "0.4.40" 168 | source = "registry+https://github.com/rust-lang/crates.io-index" 169 | checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c" 170 | dependencies = [ 171 | "android-tzdata", 172 | "iana-time-zone", 173 | "js-sys", 174 | "num-traits", 175 | "wasm-bindgen", 176 | "windows-link", 177 | ] 178 | 179 | [[package]] 180 | name = "clap" 181 | version = "4.5.37" 182 | source = "registry+https://github.com/rust-lang/crates.io-index" 183 | checksum = "eccb054f56cbd38340b380d4a8e69ef1f02f1af43db2f0cc817a4774d80ae071" 184 | dependencies = [ 185 | "clap_builder", 186 | "clap_derive", 187 | ] 188 | 189 | [[package]] 190 | name = "clap_builder" 191 | version = "4.5.37" 192 | source = "registry+https://github.com/rust-lang/crates.io-index" 193 | checksum = "efd9466fac8543255d3b1fcad4762c5e116ffe808c8a3043d4263cd4fd4862a2" 194 | dependencies = [ 195 | "anstream", 196 | "anstyle", 197 | "clap_lex", 198 | "strsim", 199 | ] 200 | 201 | [[package]] 202 | name = "clap_derive" 203 | version = "4.5.32" 204 | source = "registry+https://github.com/rust-lang/crates.io-index" 205 | checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7" 206 | dependencies = [ 207 | "heck", 208 | "proc-macro2", 209 | "quote", 210 | "syn 2.0.38", 211 | ] 212 | 213 | [[package]] 214 | name = "clap_lex" 215 | version = "0.7.4" 216 | source = "registry+https://github.com/rust-lang/crates.io-index" 217 | checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" 218 | 219 | [[package]] 220 | name = "codespan-reporting" 221 | version = "0.11.1" 222 | source = "registry+https://github.com/rust-lang/crates.io-index" 223 | checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" 224 | dependencies = [ 225 | "termcolor", 226 | "unicode-width 0.1.10", 227 | ] 228 | 229 | [[package]] 230 | name = "colorchoice" 231 | version = "1.0.0" 232 | source = "registry+https://github.com/rust-lang/crates.io-index" 233 | checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" 234 | 235 | [[package]] 236 | name = "colored" 237 | version = "3.0.0" 238 | source = "registry+https://github.com/rust-lang/crates.io-index" 239 | checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e" 240 | dependencies = [ 241 | "windows-sys 0.59.0", 242 | ] 243 | 244 | [[package]] 245 | name = "console" 246 | version = "0.15.2" 247 | source = "registry+https://github.com/rust-lang/crates.io-index" 248 | checksum = "c050367d967ced717c04b65d8c619d863ef9292ce0c5760028655a2fb298718c" 249 | dependencies = [ 250 | "encode_unicode", 251 | "lazy_static", 252 | "libc", 253 | "terminal_size", 254 | "unicode-width 0.1.10", 255 | "winapi", 256 | ] 257 | 258 | [[package]] 259 | name = "core-foundation-sys" 260 | version = "0.8.3" 261 | source = "registry+https://github.com/rust-lang/crates.io-index" 262 | checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" 263 | 264 | [[package]] 265 | name = "crossbeam-channel" 266 | version = "0.5.15" 267 | source = "registry+https://github.com/rust-lang/crates.io-index" 268 | checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2" 269 | dependencies = [ 270 | "crossbeam-utils", 271 | ] 272 | 273 | [[package]] 274 | name = "crossbeam-deque" 275 | version = "0.8.2" 276 | source = "registry+https://github.com/rust-lang/crates.io-index" 277 | checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" 278 | dependencies = [ 279 | "cfg-if", 280 | "crossbeam-epoch", 281 | "crossbeam-utils", 282 | ] 283 | 284 | [[package]] 285 | name = "crossbeam-epoch" 286 | version = "0.9.11" 287 | source = "registry+https://github.com/rust-lang/crates.io-index" 288 | checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348" 289 | dependencies = [ 290 | "autocfg", 291 | "cfg-if", 292 | "crossbeam-utils", 293 | "memoffset", 294 | "scopeguard", 295 | ] 296 | 297 | [[package]] 298 | name = "crossbeam-utils" 299 | version = "0.8.21" 300 | source = "registry+https://github.com/rust-lang/crates.io-index" 301 | checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" 302 | 303 | [[package]] 304 | name = "ctrlc" 305 | version = "3.4.6" 306 | source = "registry+https://github.com/rust-lang/crates.io-index" 307 | checksum = "697b5419f348fd5ae2478e8018cb016c00a5881c7f46c717de98ffd135a5651c" 308 | dependencies = [ 309 | "nix", 310 | "windows-sys 0.59.0", 311 | ] 312 | 313 | [[package]] 314 | name = "cvt" 315 | version = "0.1.2" 316 | source = "registry+https://github.com/rust-lang/crates.io-index" 317 | checksum = "d2ae9bf77fbf2d39ef573205d554d87e86c12f1994e9ea335b0651b9b278bcf1" 318 | dependencies = [ 319 | "cfg-if", 320 | ] 321 | 322 | [[package]] 323 | name = "cxx" 324 | version = "1.0.80" 325 | source = "registry+https://github.com/rust-lang/crates.io-index" 326 | checksum = "6b7d4e43b25d3c994662706a1d4fcfc32aaa6afd287502c111b237093bb23f3a" 327 | dependencies = [ 328 | "cc", 329 | "cxxbridge-flags", 330 | "cxxbridge-macro", 331 | "link-cplusplus", 332 | ] 333 | 334 | [[package]] 335 | name = "cxx-build" 336 | version = "1.0.80" 337 | source = "registry+https://github.com/rust-lang/crates.io-index" 338 | checksum = "84f8829ddc213e2c1368e51a2564c552b65a8cb6a28f31e576270ac81d5e5827" 339 | dependencies = [ 340 | "cc", 341 | "codespan-reporting", 342 | "once_cell", 343 | "proc-macro2", 344 | "quote", 345 | "scratch", 346 | "syn 1.0.103", 347 | ] 348 | 349 | [[package]] 350 | name = "cxxbridge-flags" 351 | version = "1.0.80" 352 | source = "registry+https://github.com/rust-lang/crates.io-index" 353 | checksum = "e72537424b474af1460806647c41d4b6d35d09ef7fe031c5c2fa5766047cc56a" 354 | 355 | [[package]] 356 | name = "cxxbridge-macro" 357 | version = "1.0.80" 358 | source = "registry+https://github.com/rust-lang/crates.io-index" 359 | checksum = "309e4fb93eed90e1e14bea0da16b209f81813ba9fc7830c20ed151dd7bc0a4d7" 360 | dependencies = [ 361 | "proc-macro2", 362 | "quote", 363 | "syn 1.0.103", 364 | ] 365 | 366 | [[package]] 367 | name = "dialoguer" 368 | version = "0.11.0" 369 | source = "registry+https://github.com/rust-lang/crates.io-index" 370 | checksum = "658bce805d770f407bc62102fca7c2c64ceef2fbcb2b8bd19d2765ce093980de" 371 | dependencies = [ 372 | "console", 373 | "shell-words", 374 | "tempfile", 375 | "thiserror", 376 | "zeroize", 377 | ] 378 | 379 | [[package]] 380 | name = "either" 381 | version = "1.8.0" 382 | source = "registry+https://github.com/rust-lang/crates.io-index" 383 | checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" 384 | 385 | [[package]] 386 | name = "encode_unicode" 387 | version = "0.3.6" 388 | source = "registry+https://github.com/rust-lang/crates.io-index" 389 | checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" 390 | 391 | [[package]] 392 | name = "fastrand" 393 | version = "1.8.0" 394 | source = "registry+https://github.com/rust-lang/crates.io-index" 395 | checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" 396 | dependencies = [ 397 | "instant", 398 | ] 399 | 400 | [[package]] 401 | name = "fs_at" 402 | version = "0.2.1" 403 | source = "registry+https://github.com/rust-lang/crates.io-index" 404 | checksum = "14af6c9694ea25db25baa2a1788703b9e7c6648dcaeeebeb98f7561b5384c036" 405 | dependencies = [ 406 | "aligned", 407 | "cfg-if", 408 | "cvt", 409 | "libc", 410 | "nix", 411 | "windows-sys 0.52.0", 412 | ] 413 | 414 | [[package]] 415 | name = "heck" 416 | version = "0.5.0" 417 | source = "registry+https://github.com/rust-lang/crates.io-index" 418 | checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 419 | 420 | [[package]] 421 | name = "hermit-abi" 422 | version = "0.3.3" 423 | source = "registry+https://github.com/rust-lang/crates.io-index" 424 | checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" 425 | 426 | [[package]] 427 | name = "iana-time-zone" 428 | version = "0.1.53" 429 | source = "registry+https://github.com/rust-lang/crates.io-index" 430 | checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" 431 | dependencies = [ 432 | "android_system_properties", 433 | "core-foundation-sys", 434 | "iana-time-zone-haiku", 435 | "js-sys", 436 | "wasm-bindgen", 437 | "winapi", 438 | ] 439 | 440 | [[package]] 441 | name = "iana-time-zone-haiku" 442 | version = "0.1.1" 443 | source = "registry+https://github.com/rust-lang/crates.io-index" 444 | checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" 445 | dependencies = [ 446 | "cxx", 447 | "cxx-build", 448 | ] 449 | 450 | [[package]] 451 | name = "indicatif" 452 | version = "0.17.11" 453 | source = "registry+https://github.com/rust-lang/crates.io-index" 454 | checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235" 455 | dependencies = [ 456 | "console", 457 | "number_prefix", 458 | "portable-atomic", 459 | "unicode-width 0.2.0", 460 | "web-time", 461 | ] 462 | 463 | [[package]] 464 | name = "instant" 465 | version = "0.1.12" 466 | source = "registry+https://github.com/rust-lang/crates.io-index" 467 | checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" 468 | dependencies = [ 469 | "cfg-if", 470 | ] 471 | 472 | [[package]] 473 | name = "is_executable" 474 | version = "1.0.4" 475 | source = "registry+https://github.com/rust-lang/crates.io-index" 476 | checksum = "d4a1b5bad6f9072935961dfbf1cced2f3d129963d091b6f69f007fe04e758ae2" 477 | dependencies = [ 478 | "winapi", 479 | ] 480 | 481 | [[package]] 482 | name = "is_terminal_polyfill" 483 | version = "1.70.1" 484 | source = "registry+https://github.com/rust-lang/crates.io-index" 485 | checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" 486 | 487 | [[package]] 488 | name = "js-sys" 489 | version = "0.3.60" 490 | source = "registry+https://github.com/rust-lang/crates.io-index" 491 | checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" 492 | dependencies = [ 493 | "wasm-bindgen", 494 | ] 495 | 496 | [[package]] 497 | name = "lazy_static" 498 | version = "1.4.0" 499 | source = "registry+https://github.com/rust-lang/crates.io-index" 500 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 501 | 502 | [[package]] 503 | name = "libc" 504 | version = "0.2.171" 505 | source = "registry+https://github.com/rust-lang/crates.io-index" 506 | checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" 507 | 508 | [[package]] 509 | name = "link-cplusplus" 510 | version = "1.0.7" 511 | source = "registry+https://github.com/rust-lang/crates.io-index" 512 | checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" 513 | dependencies = [ 514 | "cc", 515 | ] 516 | 517 | [[package]] 518 | name = "log" 519 | version = "0.4.17" 520 | source = "registry+https://github.com/rust-lang/crates.io-index" 521 | checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" 522 | dependencies = [ 523 | "cfg-if", 524 | ] 525 | 526 | [[package]] 527 | name = "memchr" 528 | version = "2.5.0" 529 | source = "registry+https://github.com/rust-lang/crates.io-index" 530 | checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" 531 | 532 | [[package]] 533 | name = "memoffset" 534 | version = "0.6.5" 535 | source = "registry+https://github.com/rust-lang/crates.io-index" 536 | checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" 537 | dependencies = [ 538 | "autocfg", 539 | ] 540 | 541 | [[package]] 542 | name = "nix" 543 | version = "0.29.0" 544 | source = "registry+https://github.com/rust-lang/crates.io-index" 545 | checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" 546 | dependencies = [ 547 | "bitflags 2.4.1", 548 | "cfg-if", 549 | "cfg_aliases", 550 | "libc", 551 | ] 552 | 553 | [[package]] 554 | name = "normpath" 555 | version = "1.1.1" 556 | source = "registry+https://github.com/rust-lang/crates.io-index" 557 | checksum = "ec60c60a693226186f5d6edf073232bfb6464ed97eb22cf3b01c1e8198fd97f5" 558 | dependencies = [ 559 | "windows-sys 0.48.0", 560 | ] 561 | 562 | [[package]] 563 | name = "num-traits" 564 | version = "0.2.15" 565 | source = "registry+https://github.com/rust-lang/crates.io-index" 566 | checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" 567 | dependencies = [ 568 | "autocfg", 569 | ] 570 | 571 | [[package]] 572 | name = "num_cpus" 573 | version = "1.16.0" 574 | source = "registry+https://github.com/rust-lang/crates.io-index" 575 | checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" 576 | dependencies = [ 577 | "hermit-abi", 578 | "libc", 579 | ] 580 | 581 | [[package]] 582 | name = "number_prefix" 583 | version = "0.4.0" 584 | source = "registry+https://github.com/rust-lang/crates.io-index" 585 | checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" 586 | 587 | [[package]] 588 | name = "once_cell" 589 | version = "1.21.1" 590 | source = "registry+https://github.com/rust-lang/crates.io-index" 591 | checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc" 592 | 593 | [[package]] 594 | name = "portable-atomic" 595 | version = "1.3.2" 596 | source = "registry+https://github.com/rust-lang/crates.io-index" 597 | checksum = "dc59d1bcc64fc5d021d67521f818db868368028108d37f0e98d74e33f68297b5" 598 | 599 | [[package]] 600 | name = "proc-macro2" 601 | version = "1.0.69" 602 | source = "registry+https://github.com/rust-lang/crates.io-index" 603 | checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" 604 | dependencies = [ 605 | "unicode-ident", 606 | ] 607 | 608 | [[package]] 609 | name = "quote" 610 | version = "1.0.33" 611 | source = "registry+https://github.com/rust-lang/crates.io-index" 612 | checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" 613 | dependencies = [ 614 | "proc-macro2", 615 | ] 616 | 617 | [[package]] 618 | name = "rayon" 619 | version = "1.5.3" 620 | source = "registry+https://github.com/rust-lang/crates.io-index" 621 | checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" 622 | dependencies = [ 623 | "autocfg", 624 | "crossbeam-deque", 625 | "either", 626 | "rayon-core", 627 | ] 628 | 629 | [[package]] 630 | name = "rayon-core" 631 | version = "1.9.3" 632 | source = "registry+https://github.com/rust-lang/crates.io-index" 633 | checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" 634 | dependencies = [ 635 | "crossbeam-channel", 636 | "crossbeam-deque", 637 | "crossbeam-utils", 638 | "num_cpus", 639 | ] 640 | 641 | [[package]] 642 | name = "redox_syscall" 643 | version = "0.2.16" 644 | source = "registry+https://github.com/rust-lang/crates.io-index" 645 | checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" 646 | dependencies = [ 647 | "bitflags 1.3.2", 648 | ] 649 | 650 | [[package]] 651 | name = "regex" 652 | version = "1.7.0" 653 | source = "registry+https://github.com/rust-lang/crates.io-index" 654 | checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" 655 | dependencies = [ 656 | "aho-corasick", 657 | "memchr", 658 | "regex-syntax", 659 | ] 660 | 661 | [[package]] 662 | name = "regex-syntax" 663 | version = "0.6.28" 664 | source = "registry+https://github.com/rust-lang/crates.io-index" 665 | checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" 666 | 667 | [[package]] 668 | name = "remove_dir_all" 669 | version = "0.5.3" 670 | source = "registry+https://github.com/rust-lang/crates.io-index" 671 | checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" 672 | dependencies = [ 673 | "winapi", 674 | ] 675 | 676 | [[package]] 677 | name = "remove_dir_all" 678 | version = "1.0.0" 679 | source = "registry+https://github.com/rust-lang/crates.io-index" 680 | checksum = "808cc0b475acf76adf36f08ca49429b12aad9f678cb56143d5b3cb49b9a1dd08" 681 | dependencies = [ 682 | "cfg-if", 683 | "cvt", 684 | "fs_at", 685 | "libc", 686 | "normpath", 687 | "rayon", 688 | "windows-sys 0.59.0", 689 | ] 690 | 691 | [[package]] 692 | name = "scopeguard" 693 | version = "1.1.0" 694 | source = "registry+https://github.com/rust-lang/crates.io-index" 695 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" 696 | 697 | [[package]] 698 | name = "scratch" 699 | version = "1.0.2" 700 | source = "registry+https://github.com/rust-lang/crates.io-index" 701 | checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" 702 | 703 | [[package]] 704 | name = "shell-words" 705 | version = "1.1.0" 706 | source = "registry+https://github.com/rust-lang/crates.io-index" 707 | checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" 708 | 709 | [[package]] 710 | name = "stable_deref_trait" 711 | version = "1.2.0" 712 | source = "registry+https://github.com/rust-lang/crates.io-index" 713 | checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" 714 | 715 | [[package]] 716 | name = "strsim" 717 | version = "0.11.1" 718 | source = "registry+https://github.com/rust-lang/crates.io-index" 719 | checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 720 | 721 | [[package]] 722 | name = "syn" 723 | version = "1.0.103" 724 | source = "registry+https://github.com/rust-lang/crates.io-index" 725 | checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" 726 | dependencies = [ 727 | "proc-macro2", 728 | "quote", 729 | "unicode-ident", 730 | ] 731 | 732 | [[package]] 733 | name = "syn" 734 | version = "2.0.38" 735 | source = "registry+https://github.com/rust-lang/crates.io-index" 736 | checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" 737 | dependencies = [ 738 | "proc-macro2", 739 | "quote", 740 | "unicode-ident", 741 | ] 742 | 743 | [[package]] 744 | name = "tempfile" 745 | version = "3.3.0" 746 | source = "registry+https://github.com/rust-lang/crates.io-index" 747 | checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" 748 | dependencies = [ 749 | "cfg-if", 750 | "fastrand", 751 | "libc", 752 | "redox_syscall", 753 | "remove_dir_all 0.5.3", 754 | "winapi", 755 | ] 756 | 757 | [[package]] 758 | name = "termcolor" 759 | version = "1.1.3" 760 | source = "registry+https://github.com/rust-lang/crates.io-index" 761 | checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" 762 | dependencies = [ 763 | "winapi-util", 764 | ] 765 | 766 | [[package]] 767 | name = "terminal_size" 768 | version = "0.1.17" 769 | source = "registry+https://github.com/rust-lang/crates.io-index" 770 | checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" 771 | dependencies = [ 772 | "libc", 773 | "winapi", 774 | ] 775 | 776 | [[package]] 777 | name = "thiserror" 778 | version = "1.0.50" 779 | source = "registry+https://github.com/rust-lang/crates.io-index" 780 | checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" 781 | dependencies = [ 782 | "thiserror-impl", 783 | ] 784 | 785 | [[package]] 786 | name = "thiserror-impl" 787 | version = "1.0.50" 788 | source = "registry+https://github.com/rust-lang/crates.io-index" 789 | checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" 790 | dependencies = [ 791 | "proc-macro2", 792 | "quote", 793 | "syn 2.0.38", 794 | ] 795 | 796 | [[package]] 797 | name = "unicode-ident" 798 | version = "1.0.5" 799 | source = "registry+https://github.com/rust-lang/crates.io-index" 800 | checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" 801 | 802 | [[package]] 803 | name = "unicode-width" 804 | version = "0.1.10" 805 | source = "registry+https://github.com/rust-lang/crates.io-index" 806 | checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" 807 | 808 | [[package]] 809 | name = "unicode-width" 810 | version = "0.2.0" 811 | source = "registry+https://github.com/rust-lang/crates.io-index" 812 | checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" 813 | 814 | [[package]] 815 | name = "utf8parse" 816 | version = "0.2.1" 817 | source = "registry+https://github.com/rust-lang/crates.io-index" 818 | checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" 819 | 820 | [[package]] 821 | name = "wasm-bindgen" 822 | version = "0.2.83" 823 | source = "registry+https://github.com/rust-lang/crates.io-index" 824 | checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" 825 | dependencies = [ 826 | "cfg-if", 827 | "wasm-bindgen-macro", 828 | ] 829 | 830 | [[package]] 831 | name = "wasm-bindgen-backend" 832 | version = "0.2.83" 833 | source = "registry+https://github.com/rust-lang/crates.io-index" 834 | checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" 835 | dependencies = [ 836 | "bumpalo", 837 | "log", 838 | "once_cell", 839 | "proc-macro2", 840 | "quote", 841 | "syn 1.0.103", 842 | "wasm-bindgen-shared", 843 | ] 844 | 845 | [[package]] 846 | name = "wasm-bindgen-macro" 847 | version = "0.2.83" 848 | source = "registry+https://github.com/rust-lang/crates.io-index" 849 | checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" 850 | dependencies = [ 851 | "quote", 852 | "wasm-bindgen-macro-support", 853 | ] 854 | 855 | [[package]] 856 | name = "wasm-bindgen-macro-support" 857 | version = "0.2.83" 858 | source = "registry+https://github.com/rust-lang/crates.io-index" 859 | checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" 860 | dependencies = [ 861 | "proc-macro2", 862 | "quote", 863 | "syn 1.0.103", 864 | "wasm-bindgen-backend", 865 | "wasm-bindgen-shared", 866 | ] 867 | 868 | [[package]] 869 | name = "wasm-bindgen-shared" 870 | version = "0.2.83" 871 | source = "registry+https://github.com/rust-lang/crates.io-index" 872 | checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" 873 | 874 | [[package]] 875 | name = "web-time" 876 | version = "1.1.0" 877 | source = "registry+https://github.com/rust-lang/crates.io-index" 878 | checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" 879 | dependencies = [ 880 | "js-sys", 881 | "wasm-bindgen", 882 | ] 883 | 884 | [[package]] 885 | name = "winapi" 886 | version = "0.3.9" 887 | source = "registry+https://github.com/rust-lang/crates.io-index" 888 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 889 | dependencies = [ 890 | "winapi-i686-pc-windows-gnu", 891 | "winapi-x86_64-pc-windows-gnu", 892 | ] 893 | 894 | [[package]] 895 | name = "winapi-i686-pc-windows-gnu" 896 | version = "0.4.0" 897 | source = "registry+https://github.com/rust-lang/crates.io-index" 898 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 899 | 900 | [[package]] 901 | name = "winapi-util" 902 | version = "0.1.5" 903 | source = "registry+https://github.com/rust-lang/crates.io-index" 904 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 905 | dependencies = [ 906 | "winapi", 907 | ] 908 | 909 | [[package]] 910 | name = "winapi-x86_64-pc-windows-gnu" 911 | version = "0.4.0" 912 | source = "registry+https://github.com/rust-lang/crates.io-index" 913 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 914 | 915 | [[package]] 916 | name = "windows-link" 917 | version = "0.1.1" 918 | source = "registry+https://github.com/rust-lang/crates.io-index" 919 | checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" 920 | 921 | [[package]] 922 | name = "windows-sys" 923 | version = "0.48.0" 924 | source = "registry+https://github.com/rust-lang/crates.io-index" 925 | checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" 926 | dependencies = [ 927 | "windows-targets 0.48.0", 928 | ] 929 | 930 | [[package]] 931 | name = "windows-sys" 932 | version = "0.52.0" 933 | source = "registry+https://github.com/rust-lang/crates.io-index" 934 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" 935 | dependencies = [ 936 | "windows-targets 0.52.6", 937 | ] 938 | 939 | [[package]] 940 | name = "windows-sys" 941 | version = "0.59.0" 942 | source = "registry+https://github.com/rust-lang/crates.io-index" 943 | checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" 944 | dependencies = [ 945 | "windows-targets 0.52.6", 946 | ] 947 | 948 | [[package]] 949 | name = "windows-targets" 950 | version = "0.48.0" 951 | source = "registry+https://github.com/rust-lang/crates.io-index" 952 | checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" 953 | dependencies = [ 954 | "windows_aarch64_gnullvm 0.48.0", 955 | "windows_aarch64_msvc 0.48.0", 956 | "windows_i686_gnu 0.48.0", 957 | "windows_i686_msvc 0.48.0", 958 | "windows_x86_64_gnu 0.48.0", 959 | "windows_x86_64_gnullvm 0.48.0", 960 | "windows_x86_64_msvc 0.48.0", 961 | ] 962 | 963 | [[package]] 964 | name = "windows-targets" 965 | version = "0.52.6" 966 | source = "registry+https://github.com/rust-lang/crates.io-index" 967 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 968 | dependencies = [ 969 | "windows_aarch64_gnullvm 0.52.6", 970 | "windows_aarch64_msvc 0.52.6", 971 | "windows_i686_gnu 0.52.6", 972 | "windows_i686_gnullvm", 973 | "windows_i686_msvc 0.52.6", 974 | "windows_x86_64_gnu 0.52.6", 975 | "windows_x86_64_gnullvm 0.52.6", 976 | "windows_x86_64_msvc 0.52.6", 977 | ] 978 | 979 | [[package]] 980 | name = "windows_aarch64_gnullvm" 981 | version = "0.48.0" 982 | source = "registry+https://github.com/rust-lang/crates.io-index" 983 | checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" 984 | 985 | [[package]] 986 | name = "windows_aarch64_gnullvm" 987 | version = "0.52.6" 988 | source = "registry+https://github.com/rust-lang/crates.io-index" 989 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 990 | 991 | [[package]] 992 | name = "windows_aarch64_msvc" 993 | version = "0.48.0" 994 | source = "registry+https://github.com/rust-lang/crates.io-index" 995 | checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" 996 | 997 | [[package]] 998 | name = "windows_aarch64_msvc" 999 | version = "0.52.6" 1000 | source = "registry+https://github.com/rust-lang/crates.io-index" 1001 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 1002 | 1003 | [[package]] 1004 | name = "windows_i686_gnu" 1005 | version = "0.48.0" 1006 | source = "registry+https://github.com/rust-lang/crates.io-index" 1007 | checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" 1008 | 1009 | [[package]] 1010 | name = "windows_i686_gnu" 1011 | version = "0.52.6" 1012 | source = "registry+https://github.com/rust-lang/crates.io-index" 1013 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" 1014 | 1015 | [[package]] 1016 | name = "windows_i686_gnullvm" 1017 | version = "0.52.6" 1018 | source = "registry+https://github.com/rust-lang/crates.io-index" 1019 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 1020 | 1021 | [[package]] 1022 | name = "windows_i686_msvc" 1023 | version = "0.48.0" 1024 | source = "registry+https://github.com/rust-lang/crates.io-index" 1025 | checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" 1026 | 1027 | [[package]] 1028 | name = "windows_i686_msvc" 1029 | version = "0.52.6" 1030 | source = "registry+https://github.com/rust-lang/crates.io-index" 1031 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 1032 | 1033 | [[package]] 1034 | name = "windows_x86_64_gnu" 1035 | version = "0.48.0" 1036 | source = "registry+https://github.com/rust-lang/crates.io-index" 1037 | checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" 1038 | 1039 | [[package]] 1040 | name = "windows_x86_64_gnu" 1041 | version = "0.52.6" 1042 | source = "registry+https://github.com/rust-lang/crates.io-index" 1043 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 1044 | 1045 | [[package]] 1046 | name = "windows_x86_64_gnullvm" 1047 | version = "0.48.0" 1048 | source = "registry+https://github.com/rust-lang/crates.io-index" 1049 | checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" 1050 | 1051 | [[package]] 1052 | name = "windows_x86_64_gnullvm" 1053 | version = "0.52.6" 1054 | source = "registry+https://github.com/rust-lang/crates.io-index" 1055 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 1056 | 1057 | [[package]] 1058 | name = "windows_x86_64_msvc" 1059 | version = "0.48.0" 1060 | source = "registry+https://github.com/rust-lang/crates.io-index" 1061 | checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" 1062 | 1063 | [[package]] 1064 | name = "windows_x86_64_msvc" 1065 | version = "0.52.6" 1066 | source = "registry+https://github.com/rust-lang/crates.io-index" 1067 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 1068 | 1069 | [[package]] 1070 | name = "zeroize" 1071 | version = "1.5.7" 1072 | source = "registry+https://github.com/rust-lang/crates.io-index" 1073 | checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" 1074 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cargo-clean-all" 3 | version = "0.6.4" 4 | authors = ["Daniel M "] 5 | license = "MIT" 6 | repository = "https://github.com/dnlmlr/cargo-clean-all" 7 | homepage = "https://github.com/dnlmlr/cargo-clean-all" 8 | readme = "README.md" 9 | description = "Recursively clean all cargo projects in a given directory that match the specified criteria" 10 | categories = ["development-tools::cargo-plugins", "command-line-utilities"] 11 | keywords = ["cargo-plugins", "cargo-clean", "cargo", "clean", "recursive"] 12 | edition = "2021" 13 | 14 | [dependencies] 15 | chrono = "0.4.40" 16 | bytefmt = "0.1.7" 17 | clap = { version = "4.5.37", features = ["derive"] } 18 | crossbeam-channel = "0.5.15" 19 | num_cpus = "1.16.0" 20 | remove_dir_all = { version = "1.0.0", features = ["parallel"] } 21 | dialoguer = "0.11.0" 22 | colored = "3.0.0" 23 | indicatif = "0.17.11" 24 | ctrlc = "3.4.6" 25 | is_executable = "1.0.4" 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 dnlmlr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cargo-clean-all 2 | 3 | [![Crates.io](https://img.shields.io/crates/v/cargo-clean-all?style=flat-square)](https://crates.io/crates/cargo-clean-all) 4 | [![Crates.io](https://img.shields.io/crates/l/cargo-clean-all?style=flat-square)](https://crates.io/crates/cargo-clean-all) 5 | 6 | ![cargo clean-all demo](assets/cargo-clean-all-demo.gif) 7 | 8 | ## Why does it exist 9 | 10 | I was a bit shocked when I realized that my rust target directories took up a total of over 50gb, 11 | so I developed this tool to help me clean up all the project target dirs. There is already 12 | [cargo-clean-recursive](https://github.com/IgaguriMK/cargo-clean-recursive) which unfortunately 13 | doesn't support interactive selections or keeping recent files in order to not slow down the 14 | projects I'm currently working on. 15 | 16 | ## What does it do 17 | 18 | This is a custom `cargo` subcommand that searches all rust cargo projects in a given parent 19 | directory and deletes the build artifacts (aka target directories). Before cleanup it shows the 20 | amount of disk space that can be freed up. Specific projects can be excluded from cleaning using 21 | an interactive selection, and/or CLI filters. The CLI filters can exclude projects that have been 22 | compiled in the last X days, have a target directory that is smaller than X, or are specifically 23 | ignored. 24 | 25 | **The actual cleaning consists of simply deleting the target directories from the detected projects, 26 | which seems to be what `cargo clean` does by default**. 27 | 28 | ## Installation 29 | 30 | Install using cargo: 31 | 32 | ```sh 33 | cargo install cargo-clean-all 34 | ``` 35 | 36 | ## Usage 37 | 38 | Clean all projects in the current working directory with the possibility to 39 | interactively deselect projects 40 | 41 | ```sh 42 | cargo clean-all -i 43 | ``` 44 | 45 | Clean all projects in the home directory (and subdirectories) that haven't been compiled in the 46 | last 7 days without interactive mode. This will still show the projects and ask for confirmation, 47 | but won't show the manual selection dialog 48 | 49 | ```sh 50 | cargo clean-all --keep-days 7 ~ 51 | ``` 52 | 53 | Clean all projects in the home directory (and subdirectories) that take up more than 10MB with 54 | interactive mode. 55 | 56 | ```sh 57 | cargo clean-all -i --keep-size 10MB ~ 58 | ``` 59 | 60 | Clean all projects in the home directory (and subdirectories), excluding the Download and Documents 61 | directories. Since interactive mode is used, the projects in the ignored directories may still be 62 | manually added to the cleanup run. 63 | 64 | ```sh 65 | cargo clean-all -i --ignore ~/Downloads --ignore ~/Documents ~ 66 | ``` 67 | 68 | ## Alternatives 69 | 70 | ## [cargo-clean-recursive](https://github.com/IgaguriMK/cargo-clean-recursive) 71 | 72 | | Feature | `cargo-clean-all` | `cargo-clean-recursive` | 73 | |-------------------------------------------------|:-----------------:|:-----------------------:| 74 | | Clean projects under current dir | yes | yes | 75 | | Clean projects under any dir | yes | no | 76 | | Display freed up / reclaimable disk space | yes | no | 77 | | Keep target dirs below a size threshold | yes | no | 78 | | Keep target dirs with a last modified threshold | yes | no | 79 | | Ask before cleaning | yes | no | 80 | | Interactive selection of projects | yes | no | 81 | | Clean only `release`, `debug` or `docs` | no (not yet) | yes | 82 | | Real `cargo clean` command under the hood | no | yes | 83 | | Keep executables in an extra directory | yes | no | 84 | 85 | Note that `cargo-clean-recursive` uses the actual `cargo clean` command under the hood instead of 86 | simply deleting the target directories. This makes the cleaning work exactly as intended by 87 | the installed version of cargo, which can certainly be desirable in some cases. 88 | 89 | --- 90 | 91 | ## Manual 92 | 93 | ```text 94 | Recursively clean all cargo projects in a given directory that match the specified criteria 95 | 96 | Usage: cargo clean-all [OPTIONS] [DIR] 97 | 98 | Arguments: 99 | [DIR] The directory in which the projects will be searched [default: .] 100 | 101 | Options: 102 | -y, --yes Don't ask for confirmation; Just clean all detected projects that are not excluded by other constraints 103 | -s, --keep-size Ignore projects with a target dir size smaller than the specified value. The size can be specified using binary prefixes like "10MB" for 10_000_000 bytes, or "1KiB" for 1_024 bytes [default: 0] 104 | -d, --keep-days Ignore projects that have been compiled in the last [DAYS] days. The last compilation time is inferred by the last modified time of the contents of target directory [default: 0] 105 | --dry-run Just collect the cleanable projects and list the reclaimable space, but don't delete anything 106 | -t, --threads The number of threads to use for directory scanning. 0 automatically selects the number of threads [default: 0] 107 | -v, --verbose Show access errors that occur while scanning. By default those errors are hidden 108 | -i, --interactive Use the interactive project selection. This will show a selection of all cleanable projects with the possibility to manually select or deselect 109 | --ignore Directories that should be ignored by default, including subdirectories. This will still detect the projects in those directories, but mark them to not be cleaned. To actually skip scanning directories, use --skip instead. The directories can be specified as absolute paths or relative to the workdir 110 | -e, --keep-executable Keeping compiled executables in release, debug and cross-compilation directories. Moves the executable to a new folder outside of target 111 | --skip Directories that should be fully skipped during scanning, including subdirectories. This will speed up the scanning time by not doing any reads for the specified directories. The directories can be specified as absolute paths or relative to the workdir 112 | --keep-empty-target Keep the empty target dir and remove only the files and subdirectories inside instead of removing the directory itself 113 | -h, --help Print help information 114 | -V, --version Print version information 115 | ``` 116 | -------------------------------------------------------------------------------- /assets/cargo-clean-all-demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnlmlr/cargo-clean-all/70610d5afa0e11200ef96d23ea642eb05c98282e/assets/cargo-clean-all-demo.gif -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use clap::Parser; 2 | use colored::{Color, Colorize}; 3 | use crossbeam_channel::{SendError, Sender}; 4 | use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle}; 5 | use is_executable::is_executable; 6 | use std::{ 7 | fmt::Display, 8 | path::{Path, PathBuf}, 9 | thread, 10 | time::{Duration, SystemTime}, 11 | }; 12 | 13 | const SPINNER_TICK_STRS: &[&'static str] = &[ 14 | "[=---------]", 15 | "[-=--------]", 16 | "[--=-------]", 17 | "[---=------]", 18 | "[----=-----]", 19 | "[-----=----]", 20 | "[------=---]", 21 | "[-------=--]", 22 | "[--------=-]", 23 | "[---------=]", 24 | "[--------=-]", 25 | "[-------=--]", 26 | "[------=---]", 27 | "[-----=----]", 28 | "[----=-----]", 29 | "[---=------]", 30 | "[--=-------]", 31 | "[-=--------]", 32 | "[=---------]", 33 | ]; 34 | 35 | #[derive(Debug, Parser)] 36 | #[clap(author, version, about, bin_name = "cargo clean-all", long_about = None)] 37 | struct AppArgs { 38 | /// The directory in which the projects will be searched 39 | #[arg(default_value_t = String::from("."), value_name = "DIR")] 40 | root_dir: String, 41 | 42 | /// Don't ask for confirmation; Just clean all detected projects that are not excluded by other 43 | /// constraints 44 | #[arg(short = 'y', long = "yes")] 45 | yes: bool, 46 | 47 | /// Ignore projects with a target dir size smaller than the specified value. The size can be 48 | /// specified using binary prefixes like "10MB" for 10_000_000 bytes, or "1KiB" for 1_024 bytes 49 | #[arg( 50 | short = 's', 51 | long = "keep-size", 52 | value_name = "SIZE", 53 | default_value_t = 0, 54 | value_parser = parse_bytes_from_str 55 | )] 56 | keep_size: u64, 57 | 58 | /// Ignore projects that have been compiled in the last [DAYS] days. The last compilation time 59 | /// is inferred by the last modified time of the contents of target directory. 60 | #[arg( 61 | short = 'd', 62 | long = "keep-days", 63 | value_name = "DAYS", 64 | default_value_t = 0 65 | )] 66 | keep_last_modified: u32, 67 | 68 | /// Just collect the cleanable projects and list the reclaimable space, but don't delete anything 69 | #[arg(long = "dry-run")] 70 | dry_run: bool, 71 | 72 | /// The number of threads to use for directory scanning. 0 automatically selects the number of 73 | /// threads 74 | #[arg( 75 | short = 't', 76 | long = "threads", 77 | value_name = "THREADS", 78 | default_value_t = 0 79 | )] 80 | number_of_threads: usize, 81 | 82 | /// Show access errors that occur while scanning. By default those errors are hidden 83 | #[arg(short = 'v', long = "verbose")] 84 | verbose: bool, 85 | 86 | /// Use the interactive project selection. This will show a selection of all cleanable projects 87 | /// with the possibility to manually select or deselect 88 | #[arg(short = 'i', long = "interactive")] 89 | interactive: bool, 90 | 91 | /// Directories that should be ignored by default, including subdirectories. This will still 92 | /// detect the projects in those directories, but mark them to not be cleaned. To actually skip 93 | /// scanning directories, use --skip instead. 94 | /// The directories can be specified as absolute paths or relative to the workdir. 95 | #[arg(long = "ignore")] 96 | ignore: Vec, 97 | 98 | /// Keeping compiled executables in release, debug and cross-compilation directories. 99 | /// Moves the executable to a new folder outside of target. 100 | #[arg(short = 'e', long = "keep-executable")] 101 | executable: bool, 102 | 103 | /// Directories that should be fully skipped during scanning, including subdirectories. This 104 | /// will speed up the scanning time by not doing any reads for the specified directories. 105 | /// The directories can be specified as absolute paths or relative to the workdir. 106 | #[arg(long = "skip")] 107 | skip: Vec, 108 | 109 | /// Maximum depth of subdirectories that should be scanned looking for the **`target/`**. This will speed up the scanning 110 | /// The option is for target/ dir, NOT for the project dir 111 | /// 0 means no limit 112 | #[arg(long = "depth", default_value_t = 0)] 113 | depth: usize, 114 | 115 | /// Keep the empty target dir and remove only the files and subdirectories inside instead of 116 | /// removing the directory itself 117 | #[arg(long = "keep-empty-target")] 118 | keep_empty_target: bool, 119 | } 120 | 121 | /// Wrap the bytefmt::parse function to return the error as an owned String 122 | fn parse_bytes_from_str(byte_str: &str) -> Result { 123 | bytefmt::parse(byte_str).map_err(|e| e.to_string()) 124 | } 125 | 126 | /// Try to get the canonicalized path and return the non canonicalized path if it doesn't work 127 | fn canonicalize_or_not(p: impl AsRef) -> PathBuf { 128 | std::fs::canonicalize(p.as_ref()).unwrap_or_else(|_| p.as_ref().to_path_buf()) 129 | } 130 | 131 | fn starts_with_canonicalized(a: impl AsRef, b: impl AsRef) -> bool { 132 | canonicalize_or_not(a).starts_with(canonicalize_or_not(b)) 133 | } 134 | 135 | fn main() { 136 | // If the program is interrupted while in a dialog the cursor stays hidden. This makes sure 137 | // that the cursor is shown when interrupting the program 138 | ctrlc::set_handler(|| { 139 | let _ = dialoguer::console::Term::stdout().show_cursor(); 140 | std::process::exit(1); 141 | }) 142 | .unwrap(); 143 | 144 | // Enable ANSI escape codes on window 10. This always returns `Ok(())`, so unwrap is fine 145 | #[cfg(windows)] 146 | colored::control::set_virtual_terminal(true).unwrap(); 147 | 148 | let mut args = std::env::args(); 149 | 150 | // When called using `cargo clean-all`, the argument `clean-all` is inserted. To fix the arg 151 | // alignment, one argument is dropped. 152 | if let Some("clean-all") = std::env::args().nth(1).as_deref() { 153 | args.next(); 154 | } 155 | 156 | let args = AppArgs::parse_from(args); 157 | 158 | let scan_path = Path::new(&args.root_dir); 159 | 160 | let multi_progress = if args.verbose { 161 | println!("Scanning for projects in {}", args.root_dir); 162 | MultiProgress::with_draw_target(ProgressDrawTarget::stderr_with_hz(10)) 163 | } else { 164 | MultiProgress::with_draw_target(ProgressDrawTarget::hidden()) 165 | }; 166 | 167 | let spinner = ProgressBar::new_spinner() 168 | .with_message(format!("Scanning for projects in {}", args.root_dir)) 169 | .with_style(ProgressStyle::default_spinner().tick_strings(SPINNER_TICK_STRS)); 170 | 171 | if !args.verbose { 172 | spinner.enable_steady_tick(Duration::from_millis(100)); 173 | } 174 | 175 | // Find project dirs and analyze them 176 | let cargo_projects: Vec<_> = 177 | find_cargo_projects(scan_path, &multi_progress, args.number_of_threads, &args) 178 | .filter(|d| d.1) 179 | .collect(); 180 | 181 | multi_progress.clear().unwrap(); 182 | spinner.finish_and_clear(); 183 | 184 | println!("Computing size of target/ for project"); 185 | let pb = ProgressBar::new(cargo_projects.len() as u64).with_style( 186 | ProgressStyle::with_template("[{elapsed}] [{bar:.cyan/blue}] {pos}/{len}: {msg}") 187 | .expect("Invalid template syntax") 188 | .progress_chars("#>-"), 189 | ); 190 | 191 | let mut projects: Vec<_> = cargo_projects 192 | .into_iter() 193 | .filter_map(|proj| { 194 | proj.1.then(|| { 195 | pb.set_message(format!("{}", proj.0.display())); 196 | let analysis = ProjectTargetAnalysis::analyze(&proj.0); 197 | pb.inc(1); 198 | analysis 199 | }) 200 | }) 201 | .collect(); 202 | 203 | pb.finish_and_clear(); 204 | 205 | projects.sort_by_key(|proj| proj.size); 206 | 207 | // Determin what projects are selected by the restrictions 208 | let preselected_projects = projects 209 | .iter_mut() 210 | .map(|tgt| { 211 | let secs_elapsed = tgt 212 | .last_modified 213 | .elapsed() 214 | .unwrap_or_default() 215 | .as_secs_f32(); 216 | let days_elapsed = secs_elapsed / (60.0 * 60.0 * 24.0); 217 | let ignored = args 218 | .ignore 219 | .iter() 220 | .any(|p| starts_with_canonicalized(&tgt.project_path, p)); 221 | 222 | days_elapsed >= args.keep_last_modified as f32 && tgt.size > args.keep_size && !ignored 223 | }) 224 | .collect::>(); 225 | 226 | if args.interactive { 227 | let Ok(Some(prompt)) = dialoguer::MultiSelect::new() 228 | .items(&projects) 229 | .with_prompt("Select projects to clean") 230 | .report(false) 231 | .defaults(&preselected_projects) 232 | .interact_opt() 233 | else { 234 | println!("Nothing selected"); 235 | return; 236 | }; 237 | 238 | for idx in prompt { 239 | projects[idx].selected_for_cleanup = true; 240 | } 241 | } else { 242 | for i in 0..preselected_projects.len() { 243 | projects[i].selected_for_cleanup = preselected_projects[i]; 244 | } 245 | } 246 | 247 | let (selected, ignored): (Vec<_>, Vec<_>) = projects 248 | .into_iter() 249 | .partition(|proj| proj.selected_for_cleanup); 250 | 251 | let will_free_size: u64 = selected.iter().map(|it| it.size).sum(); 252 | let ignored_free_size: u64 = ignored.iter().map(|it| it.size).sum(); 253 | 254 | println!("Ignoring the following project directories:"); 255 | ignored.iter().for_each(|p| println!("{}", p)); 256 | 257 | println!("\nSelected the following project directories for cleaning:"); 258 | selected.iter().for_each(|p| println!("{}", p)); 259 | 260 | println!( 261 | "\nSelected {}/{} projects, cleaning will free: {}. Keeping: {}", 262 | selected.len(), 263 | selected.len() + ignored.len(), 264 | bytefmt::format(will_free_size).bold(), 265 | bytefmt::format(ignored_free_size) 266 | ); 267 | 268 | if args.dry_run { 269 | println!("Dry run. Not doing any cleanup"); 270 | return; 271 | } 272 | 273 | // Confirm cleanup if --yes is not present in the args 274 | if !args.yes { 275 | if !dialoguer::Confirm::new() 276 | .with_prompt("Clean the project directories shown above?") 277 | .wait_for_newline(true) 278 | .interact() 279 | .unwrap_or(false) 280 | { 281 | println!("Cleanup cancelled"); 282 | return; 283 | } 284 | } 285 | 286 | println!("Starting cleanup..."); 287 | 288 | // Saves the executables in another folder before cleaning the target folder 289 | if args.executable { 290 | for project in selected.iter() { 291 | let project_target_path = &project.project_path.join("target"); 292 | let project_executables_path = project.project_path.join("executables"); 293 | 294 | let target_rd = match project_target_path.read_dir() { 295 | Ok(it) => it, 296 | Err(e) => { 297 | args.verbose 298 | .then(|| eprintln!("Error reading target dir of: '{}' {}", project, e)); 299 | continue; 300 | } 301 | }; 302 | 303 | let target_rd = target_rd 304 | .filter_map(|it| it.ok()) 305 | .filter_map(|it| it.file_type().is_ok_and(|t| t.is_dir()).then(|| it.path())); 306 | 307 | for target_subdir in target_rd { 308 | let files = match target_subdir.read_dir() { 309 | Ok(it) => it, 310 | Err(e) => { 311 | args.verbose.then(|| { 312 | eprintln!("Error reading target dir of: '{}' {}", project, e) 313 | }); 314 | continue; 315 | } 316 | }; 317 | 318 | let files = files 319 | .filter_map(|it| it.ok()) 320 | .filter_map(|it| it.file_type().is_ok_and(|t| t.is_file()).then(|| it.path())); 321 | 322 | for exe_file_path in files.filter(|file| is_executable(file)) { 323 | let new_exe_file_path = project_executables_path 324 | .join(target_subdir.file_name().expect("Path Error")) 325 | .join(exe_file_path.file_name().expect("Path Error")); 326 | 327 | if let Err(e) = 328 | std::fs::create_dir_all(new_exe_file_path.parent().expect("Path Error")) 329 | { 330 | eprintln!( 331 | "Error createing executable dir: '{}' {}", 332 | new_exe_file_path.parent().expect("Path Error").display(), 333 | e 334 | ); 335 | continue; 336 | } 337 | 338 | if let Err(e) = std::fs::rename(exe_file_path, &new_exe_file_path) { 339 | eprintln!( 340 | "Error moving executable: '{}' {}", 341 | new_exe_file_path.display(), 342 | e 343 | ); 344 | continue; 345 | } 346 | } 347 | } 348 | } 349 | } 350 | 351 | let clean_progress = ProgressBar::new(selected.len() as u64).with_style( 352 | ProgressStyle::with_template("[{elapsed}] [{bar:}] {pos}/{len}: {msg}") 353 | .expect("Invalid template syntax") 354 | .progress_chars("#>-"), 355 | ); 356 | 357 | let failed_cleanups = selected.iter().filter_map(|tgt| { 358 | clean_progress.set_message(format!("{}", tgt.project_path.display())); 359 | let res = remove_dir_all(&tgt.project_path.join("target"), args.keep_empty_target) 360 | .err() 361 | .map(|e| (tgt.clone(), e)); 362 | clean_progress.inc(1); 363 | res 364 | }); 365 | 366 | clean_progress.finish_and_clear(); 367 | println!(""); 368 | 369 | // The current leftover size calculation assumes that a failed deletion didn't delete anything. 370 | // This will not be true in most cases as a recursive deletion might delet stuff before failing. 371 | let mut leftover_size = 0; 372 | for (tgt, e) in failed_cleanups { 373 | leftover_size += tgt.size; 374 | println!("Failed to clean {}", pretty_format_path(&tgt.project_path)); 375 | println!("Error: {}", e); 376 | } 377 | 378 | println!( 379 | "\nProjects cleaned. Reclaimed {} of disk space", 380 | bytefmt::format(will_free_size - leftover_size).bold() 381 | ); 382 | } 383 | 384 | fn remove_dir_all(path: &Path, keep_empty_dir: bool) -> std::io::Result<()> { 385 | if !keep_empty_dir { 386 | remove_dir_all::remove_dir_all(path) 387 | } else { 388 | for rd in path.read_dir()? { 389 | let rd = rd?; 390 | let md = rd.metadata()?; 391 | if md.is_dir() { 392 | remove_dir_all::remove_dir_all(&rd.path())?; 393 | } else { 394 | std::fs::remove_file(&rd.path())?; 395 | } 396 | } 397 | Ok(()) 398 | } 399 | } 400 | 401 | /// Job for the threaded project finder. First the path to be searched, second the sender to create 402 | /// new jobs for recursively searching the dirs 403 | struct Job { 404 | path: PathBuf, 405 | sender: Sender, 406 | depth: Option, 407 | } 408 | 409 | impl Job { 410 | pub fn new(path: PathBuf, sender: Sender, depth: Option) -> Self { 411 | Self { 412 | path, 413 | sender, 414 | depth, 415 | } 416 | } 417 | 418 | pub fn explore_recursive(&self, path: PathBuf) -> Result<(), SendError> { 419 | self.sender.send(Job { 420 | path, 421 | sender: self.sender.clone(), 422 | depth: self.depth.map(|d| d - 1), 423 | }) 424 | } 425 | } 426 | 427 | /// Directory of the project and bool that is true if the target directory exists 428 | struct ProjectDir(PathBuf, bool); 429 | 430 | fn progress_bar(multi_progress: &MultiProgress, spinner_style: ProgressStyle) -> ProgressBar { 431 | let pb = multi_progress.add(ProgressBar::new(u64::MAX)); // unbounded 432 | pb.set_style(spinner_style); 433 | pb 434 | } 435 | 436 | /// Recursively scan the given path for cargo projects using the specified number of threads. 437 | /// 438 | /// When the number of threads is 0, use as many threads as virtual CPU cores. 439 | fn find_cargo_projects( 440 | path: &Path, 441 | multi_progress: &MultiProgress, 442 | mut num_threads: usize, 443 | args: &AppArgs, 444 | ) -> impl Iterator { 445 | if num_threads == 0 { 446 | num_threads = num_cpus::get(); 447 | } 448 | let depth = (args.depth > 0).then(|| args.depth); 449 | 450 | thread::scope(|scope| { 451 | { 452 | let (job_tx, job_rx) = crossbeam_channel::unbounded::(); 453 | let (result_tx, result_rx) = crossbeam_channel::unbounded::(); 454 | 455 | (0..num_threads) 456 | .map(|_| (job_rx.clone(), result_tx.clone())) 457 | .for_each(|(job_rx, result_tx)| { 458 | scope.spawn(move || { 459 | let spinner_style = ProgressStyle::with_template("{wide_msg}") 460 | .expect("Invalid template syntax"); 461 | let pb = progress_bar(multi_progress, spinner_style.clone()); 462 | job_rx.into_iter().for_each(|job| { 463 | find_cargo_projects_task(job, &pb, result_tx.clone(), &args) 464 | }); 465 | pb.finish_with_message("waiting..."); 466 | }); 467 | }); 468 | 469 | job_tx 470 | .clone() 471 | .send(Job::new(path.to_path_buf(), job_tx, depth)) 472 | .unwrap(); 473 | 474 | result_rx 475 | } 476 | .into_iter() 477 | }) 478 | } 479 | 480 | /// Scan the given directory and report to the results Sender if the directory contains a 481 | /// Cargo.toml . Detected subdirectories should be queued as a new job in with the job_sender. 482 | /// 483 | /// This function is supposed to be called by the threadpool in find_cargo_projects 484 | fn find_cargo_projects_task( 485 | job: Job, 486 | pb: &ProgressBar, 487 | results: Sender, 488 | args: &AppArgs, 489 | ) { 490 | if let Some(0) = job.depth { 491 | return; 492 | } 493 | let mut has_target = false; 494 | 495 | if args.verbose { 496 | pb.set_message(format!("looking at: {}", job.path.display())); 497 | } 498 | 499 | let read_dir = match job.path.read_dir() { 500 | Ok(it) => it, 501 | Err(e) => { 502 | pb.suspend(|| { 503 | args.verbose 504 | .then(|| eprintln!("Error reading directory: '{}' {}", job.path.display(), e)); 505 | }); 506 | return; 507 | } 508 | }; 509 | let (dirs, files): (Vec<_>, Vec<_>) = read_dir 510 | .filter_map(|it| it.ok()) 511 | .partition(|it| it.file_type().is_ok_and(|t| t.is_dir())); 512 | let dirs = dirs.iter().map(|it| it.path()); 513 | let has_cargo_toml = files 514 | .iter() 515 | .any(|it| it.file_name().to_string_lossy() == "Cargo.toml"); 516 | // Iterate through the subdirectories of path, ignoring entries that caused errors 517 | for it in dirs { 518 | if args.skip.iter().any(|p| starts_with_canonicalized(&it, p)) { 519 | continue; 520 | } 521 | 522 | let filename = it.file_name().unwrap_or_default().to_string_lossy(); 523 | match filename.as_ref() { 524 | // No need to search .git directories for cargo projects. Also skip .cargo directories 525 | // as there shouldn't be any target dirs in there. Even if there are valid target dirs, 526 | // they should probably not be deleted. See issue #2 (https://github.com/dnlmlr/cargo-clean-all/issues/2) 527 | ".git" | ".cargo" => (), 528 | "target" if has_cargo_toml => has_target = true, 529 | // For directories queue a new job to search it with the threadpool 530 | _ => job.explore_recursive(it.to_path_buf()).unwrap(), 531 | } 532 | } 533 | 534 | // If path contains a Cargo.toml, it is a project directory 535 | if has_cargo_toml { 536 | results.send(ProjectDir(job.path, has_target)).unwrap(); 537 | } 538 | if args.verbose { 539 | pb.set_message("waiting..."); 540 | } 541 | } 542 | 543 | #[derive(Clone, Debug)] 544 | struct ProjectTargetAnalysis { 545 | /// The path of the project without the `target` directory suffix 546 | project_path: PathBuf, 547 | /// The size in bytes that the target directory takes up 548 | size: u64, 549 | /// The timestamp of the last recently modified file in the target directory 550 | last_modified: SystemTime, 551 | /// Indicate that this target directory should be cleaned 552 | selected_for_cleanup: bool, 553 | } 554 | 555 | impl ProjectTargetAnalysis { 556 | /// Analyze a given project directories target directory 557 | pub fn analyze(path: &Path) -> Self { 558 | let (size, last_modified) = Self::recursive_scan_target(&path.join("target")); 559 | Self { 560 | project_path: path.to_owned(), 561 | size, 562 | last_modified, 563 | selected_for_cleanup: false, 564 | } 565 | } 566 | 567 | // Recursively sum up the file sizes and find the last modified timestamp 568 | fn recursive_scan_target>(path: T) -> (u64, SystemTime) { 569 | let path = path.as_ref(); 570 | 571 | let default = (0, SystemTime::UNIX_EPOCH); 572 | 573 | if !path.exists() || path.is_symlink() { 574 | return default; 575 | } 576 | 577 | match (path.is_file(), path.metadata()) { 578 | (true, Ok(md)) => (md.len(), md.modified().unwrap_or(default.1)), 579 | _ => path 580 | .read_dir() 581 | .map(|rd| { 582 | rd.filter_map(|it| it.ok().map(|it| it.path())) 583 | .map(Self::recursive_scan_target) 584 | .fold(default, |a, b| (a.0 + b.0, a.1.max(b.1))) 585 | }) 586 | .unwrap_or(default), 587 | } 588 | } 589 | } 590 | 591 | /// Remove the `\\?\` prefix from canonicalized windows paths and replace all `\` path separators 592 | /// with `/`. This could make paths non-copyable in some special cases but those paths are mainly 593 | /// intended for identifying the projects, so this is fine. 594 | fn pretty_format_path(p: &Path) -> String { 595 | p.display() 596 | .to_string() 597 | .replace("\\\\?\\", "") 598 | .replace('\\', "/") 599 | } 600 | 601 | impl Display for ProjectTargetAnalysis { 602 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 603 | let project_name = self 604 | .project_path 605 | .file_name() 606 | .unwrap_or_default() 607 | .to_string_lossy(); 608 | let path = pretty_format_path(&canonicalize_or_not(&self.project_path)); 609 | 610 | let last_modified: chrono::DateTime = self.last_modified.into(); 611 | write!( 612 | f, 613 | "{}: {} ({}), {}", 614 | project_name.bold().color(Color::Green), 615 | bytefmt::format(self.size), 616 | last_modified.format("%Y-%m-%d %H:%M"), 617 | path, 618 | ) 619 | } 620 | } 621 | --------------------------------------------------------------------------------