remove_dir_all-0.8.2/.cargo_vcs_info.json0000644000000001360000000000100140260ustar { "git": { "sha1": "2f0329e74ae8df37d21c6c917f75c7c8e81d774b" }, "path_in_vcs": "" }remove_dir_all-0.8.2/Cargo.lock0000644000000415730000000000100120130ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "aho-corasick" version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ "memchr", ] [[package]] name = "aligned" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80a21b9440a626c7fc8573a9e3d3a06b75c7c97754c2949bc7857b90353ca655" dependencies = [ "as-slice", ] [[package]] name = "as-slice" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "516b6b4f0e40d50dcda9365d53964ec74560ad4284da2e7fc97122cd83174516" dependencies = [ "stable_deref_trait", ] [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cc" version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" version = "4.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c911b090850d79fc64fe9ea01e28e465f65e821e08813ced95bced72f7a8a9b" dependencies = [ "bitflags", "clap_derive", "clap_lex", "is-terminal", "once_cell", "strsim", "termcolor", ] [[package]] name = "clap_derive" version = "4.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a932373bab67b984c790ddf2c9ca295d8e3af3b7ef92de5a5bacdccdee4b09b" dependencies = [ "heck", "proc-macro2", "quote", "syn 2.0.9", ] [[package]] name = "clap_lex" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "033f6b7a4acb1f358c742aaca805c939ee73b4c6209ae4318ec7aca81c42e646" dependencies = [ "os_str_bytes", ] [[package]] name = "crossbeam-channel" version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" dependencies = [ "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-deque" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" dependencies = [ "cfg-if", "crossbeam-epoch", "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" version = "0.9.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" dependencies = [ "autocfg", "cfg-if", "crossbeam-utils", "memoffset", "scopeguard", ] [[package]] name = "crossbeam-utils" version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" dependencies = [ "cfg-if", ] [[package]] name = "cvt" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2ae9bf77fbf2d39ef573205d554d87e86c12f1994e9ea335b0651b9b278bcf1" dependencies = [ "cfg-if", ] [[package]] name = "doc-comment" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] name = "either" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "env_logger" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" dependencies = [ "humantime", "is-terminal", "log", "regex", "termcolor", ] [[package]] name = "errno" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" dependencies = [ "errno-dragonfly", "libc", "winapi", ] [[package]] name = "errno-dragonfly" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" dependencies = [ "cc", "libc", ] [[package]] name = "fastrand" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" dependencies = [ "instant", ] [[package]] name = "fs_at" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37047c0d530b3aefc64e4c4d7c6b1e23030c65973661b70e12c826f426f3f675" dependencies = [ "aligned", "cfg-if", "cvt", "libc", "nix", "smart-default", "windows-sys 0.45.0", ] [[package]] name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" dependencies = [ "libc", ] [[package]] name = "hermit-abi" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "instant" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if", ] [[package]] name = "io-lifetimes" version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09270fd4fa1111bc614ed2246c7ef56239a3063d5be0d1ec3b589c505d400aeb" dependencies = [ "hermit-abi 0.3.1", "libc", "windows-sys 0.45.0", ] [[package]] name = "is-terminal" version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8687c819457e979cc940d09cb16e42a1bf70aa6b60a549de6d3a62a0ee90c69e" dependencies = [ "hermit-abi 0.3.1", "io-lifetimes", "rustix", "windows-sys 0.45.0", ] [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" [[package]] name = "linux-raw-sys" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "log" version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] [[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memoffset" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" dependencies = [ "autocfg", ] [[package]] name = "nix" version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" dependencies = [ "bitflags", "cfg-if", "libc", "static_assertions", ] [[package]] name = "normpath" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "972dec05f98e7c787ede35d7a9ea4735eb7788c299287352757b3def6cc1f7b5" dependencies = [ "windows-sys 0.45.0", ] [[package]] name = "num_cpus" version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ "hermit-abi 0.2.6", "libc", ] [[package]] name = "once_cell" version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "os_str_bytes" version = "6.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" [[package]] name = "proc-macro2" version = "1.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba466839c78239c09faf015484e5cc04860f88242cff4d03eb038f04b4699b73" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] [[package]] name = "rayon" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" dependencies = [ "either", "rayon-core", ] [[package]] name = "rayon-core" version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" dependencies = [ "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", "num_cpus", ] [[package]] name = "redox_syscall" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] [[package]] name = "regex" version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cce168fea28d3e05f158bda4576cf0c844d5045bc2cc3620fa0292ed5bb5814c" dependencies = [ "aho-corasick", "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "remove_dir_all" version = "0.8.2" dependencies = [ "aligned", "cfg-if", "clap", "cvt", "doc-comment", "env_logger", "fs_at", "lazy_static", "libc", "log", "normpath", "rayon", "tempfile", "test-log", "windows-sys 0.45.0", ] [[package]] name = "rustix" version = "0.36.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db4165c9963ab29e422d6c26fbc1d37f15bace6b2810221f9d925023480fcf0e" dependencies = [ "bitflags", "errno", "io-lifetimes", "libc", "linux-raw-sys", "windows-sys 0.45.0", ] [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "smart-default" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6" dependencies = [ "proc-macro2", "quote", "syn 1.0.109", ] [[package]] name = "stable_deref_trait" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "strsim" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "syn" version = "2.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0da4a3c17e109f700685ec577c0f85efd9b19bcf15c913985f14dc1ac01775aa" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "tempfile" version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" dependencies = [ "cfg-if", "fastrand", "redox_syscall", "rustix", "windows-sys 0.42.0", ] [[package]] name = "termcolor" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ "winapi-util", ] [[package]] name = "test-log" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38f0c854faeb68a048f0f2dc410c5ddae3bf83854ef0e4977d58306a5edef50e" dependencies = [ "proc-macro2", "quote", "syn 1.0.109", ] [[package]] name = "unicode-ident" version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ "winapi", ] [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows-sys" version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" [[package]] name = "windows_aarch64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_i686_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] name = "windows_i686_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] name = "windows_x86_64_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] name = "windows_x86_64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" remove_dir_all-0.8.2/Cargo.toml0000644000000044460000000000100120340ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "remove_dir_all" version = "0.8.2" authors = [ "Erin P. ", "Robert C. ", ] include = [ "Cargo.toml", "LICENCE-APACHE", "LICENCE-MIT", "src/**/*", "README.md", ] description = "A safe, reliable implementation of remove_dir_all for Windows" readme = "README.md" keywords = [ "utility", "filesystem", "remove_dir", "windows", ] categories = ["filesystem"] license = "MIT OR Apache-2.0" repository = "https://github.com/XAMPPRocky/remove_dir_all.git" [[bin]] name = "remove-dir-all" required-features = ["cli"] [dependencies.cfg-if] version = "1.0.0" [dependencies.clap] version = "4.1.11" features = ["derive"] optional = true [dependencies.env_logger] version = "0.10.0" optional = true [dependencies.fs_at] version = "0.1.4" [dependencies.lazy_static] version = "1.4.0" [dependencies.log] version = "0.4.11" optional = true [dependencies.normpath] version = "1.0.1" [dependencies.rayon] version = "1.4" optional = true [dev-dependencies.doc-comment] version = "0.3" [dev-dependencies.env_logger] version = "0.10.0" [dev-dependencies.log] version = "0.4.11" [dev-dependencies.tempfile] version = "3.1" [dev-dependencies.test-log] version = "0.2" [features] cli = [ "dep:clap", "dep:env_logger", "log", "parallel", ] default = [] log = ["dep:log"] parallel = ["dep:rayon"] [target."cfg(not(windows))".dependencies.cvt] version = "0.1.1" [target."cfg(not(windows))".dependencies.libc] version = "0.2" [target."cfg(windows)".dependencies.aligned] version = "0.4.1" [target."cfg(windows)".dependencies.windows-sys] version = "0.45.0" features = [ "Win32_Foundation", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_Ioctl", "Win32_System_SystemServices", "Win32_System_Threading", ] remove_dir_all-0.8.2/Cargo.toml.orig000064400000000000000000000030161046102023000155050ustar 00000000000000[package] authors = [ "Erin P. ", "Robert C. ", ] categories = ["filesystem"] description = "A safe, reliable implementation of remove_dir_all for Windows" edition = "2018" include = [ "Cargo.toml", "LICENCE-APACHE", "LICENCE-MIT", "src/**/*", "README.md", ] keywords = ["utility", "filesystem", "remove_dir", "windows"] license = "MIT OR Apache-2.0" name = "remove_dir_all" readme = "README.md" repository = "https://github.com/XAMPPRocky/remove_dir_all.git" version = "0.8.2" [features] cli = ["dep:clap", "dep:env_logger", "log", "parallel"] default = [] log = ["dep:log"] parallel = ["dep:rayon"] [[bin]] name = "remove-dir-all" required-features = ["cli"] [dependencies] cfg-if = "1.0.0" clap = { version = "4.1.11", optional = true, features = ["derive"] } env_logger = { version = "0.10.0", optional = true } fs_at = { version = "0.1.4" } lazy_static = "1.4.0" log = { version = "0.4.11", optional = true } normpath = "1.0.1" rayon = { version = "1.4", optional = true } [target.'cfg(windows)'.dependencies] aligned = "0.4.1" [target.'cfg(windows)'.dependencies.windows-sys] features = [ "Win32_Foundation", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_Ioctl", "Win32_System_SystemServices", "Win32_System_Threading", ] version = "0.45.0" [target.'cfg(not(windows))'.dependencies] cvt = "0.1.1" libc = "0.2" [dev-dependencies] doc-comment = "0.3" env_logger = "0.10.0" log = "0.4.11" tempfile = "3.1" test-log = "0.2" remove_dir_all-0.8.2/LICENCE-APACHE000064400000000000000000000240421046102023000145240ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS Copyright 2017 Aaron Power Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. remove_dir_all-0.8.2/LICENCE-MIT000064400000000000000000000020401046102023000142260ustar 00000000000000Copyright (c) 2017 Aaron Power Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. remove_dir_all-0.8.2/README.md000064400000000000000000000024071046102023000141000ustar 00000000000000# remove_dir_all [![Latest Version](https://img.shields.io/crates/v/remove_dir_all.svg)](https://crates.io/crates/remove_dir_all) [![Docs](https://docs.rs/remove_dir_all/badge.svg)](https://docs.rs/remove_dir_all) [![License](https://img.shields.io/crates/l/remove_dir_all.svg)](https://github.com/XAMPPRocky/remove_dir_all) ## Description Reliable and fast directory removal functions. * `remove_dir_all` - on non-Windows this is a re-export of `std::fs::remove_dir_all`. For Windows an implementation that handles the locking of directories that occurs when deleting directory trees rapidly. * `remove_dir_contents` - as for `remove_dir_all` but does not delete the supplied root directory. * `ensure_empty_dir` - as for `remove_dir_contents` but will create the directory if it does not exist. ```rust,no_run extern crate remove_dir_all; use remove_dir_all::*; fn main() { remove_dir_all("./temp/").unwrap(); remove_dir_contents("./cache/").unwrap(); } ``` ## Minimum Rust Version The minimum rust version for `remove_dir_all` is the latest stable release, and the minimum version may be bumped through patch releases. You can pin to a specific version by setting by add `=` to your version (e.g. `=0.6.0`), or commiting a `Cargo.lock` file to your project. remove_dir_all-0.8.2/src/_impl/io.rs000064400000000000000000000005771046102023000154730ustar 00000000000000//! Private trait to deal with OS variance use std::{fmt::Debug, fs::File, io, path::Path}; pub(crate) trait Io { type UniqueIdentifier: PartialEq + Debug; fn duplicate_fd(f: &mut File) -> io::Result; fn open_dir(p: &Path) -> io::Result; fn unique_identifier(d: &File) -> io::Result; fn is_eloop(e: &io::Error) -> bool; } remove_dir_all-0.8.2/src/_impl/path_components.rs000064400000000000000000000012401046102023000202510ustar 00000000000000use std::{fmt::Display, path::Path}; /// Print a path that is broken into segments. // explicitly typed to avoid type recursion. 'a is the smallest lifetime present // : that of the child. pub(crate) enum PathComponents<'a> { Path(&'a Path), Component(&'a PathComponents<'a>, &'a Path), } impl<'p> Display for PathComponents<'p> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { PathComponents::Path(p) => p.display().fmt(f), PathComponents::Component(p, c) => { p.fmt(f)?; f.write_str("/")?; c.display().fmt(f) } } } } remove_dir_all-0.8.2/src/_impl/unix.rs000064400000000000000000000021151046102023000160350ustar 00000000000000use std::fs::{File, OpenOptions}; use std::io; use std::os::unix::fs::OpenOptionsExt; use std::os::unix::prelude::FromRawFd; use std::path::Path; use std::{fs, os::unix::prelude::AsRawFd}; use cvt::cvt; use libc::{self, fcntl, F_DUPFD_CLOEXEC}; use super::io::Io; pub(crate) struct UnixIo; impl Io for UnixIo { type UniqueIdentifier = (); fn duplicate_fd(f: &mut fs::File) -> io::Result { let source_fd = f.as_raw_fd(); // F_DUPFD_CLOEXEC seems to be quite portable, but we should be prepared // to add in more codepaths here. let fd = cvt(unsafe { fcntl(source_fd, F_DUPFD_CLOEXEC, 0) })?; Ok(unsafe { File::from_raw_fd(fd) }) } fn open_dir(p: &Path) -> io::Result { let mut options = OpenOptions::new(); options.read(true); options.custom_flags(libc::O_NOFOLLOW); options.open(p) } fn unique_identifier(_d: &fs::File) -> io::Result { todo!() } fn is_eloop(e: &io::Error) -> bool { e.raw_os_error() == Some(libc::ELOOP) } } remove_dir_all-0.8.2/src/_impl/win.rs000064400000000000000000000054301046102023000156520ustar 00000000000000use std::{ ffi::c_void, fs::{File, OpenOptions}, io::{self, Result}, mem::{size_of, MaybeUninit}, os::windows::fs::OpenOptionsExt, os::windows::prelude::AsRawHandle, os::windows::prelude::*, path::Path, }; use windows_sys::Win32::{ Foundation::{DuplicateHandle, DUPLICATE_SAME_ACCESS, ERROR_CANT_RESOLVE_FILENAME, HANDLE}, Storage::FileSystem::{ FileIdInfo, GetFileInformationByHandleEx, FILE_FLAG_BACKUP_SEMANTICS, FILE_FLAG_OPEN_REPARSE_POINT, FILE_ID_INFO, }, System::Threading::GetCurrentProcess, }; use super::io::Io; pub(crate) struct WindowsIo; // basically FILE_ID_INFO but declared primitives to permit derives. #[derive(Debug, PartialEq)] pub(crate) struct VSNFileId { vsn: u64, file_id: [u8; 16], } impl Io for WindowsIo { fn duplicate_fd(f: &mut File) -> io::Result { let mut new_handle: MaybeUninit<*mut c_void> = MaybeUninit::uninit(); let result = unsafe { DuplicateHandle( GetCurrentProcess(), f.as_raw_handle() as HANDLE, GetCurrentProcess(), new_handle.as_mut_ptr() as *mut HANDLE, 0, false as i32, DUPLICATE_SAME_ACCESS, ) }; if result == 0 { return Err(std::io::Error::last_os_error()); } let new_handle = unsafe { new_handle.assume_init() }; Ok(unsafe { File::from_raw_handle(new_handle) }) } fn open_dir(p: &Path) -> Result { let mut options = OpenOptions::new(); options.read(true); options.custom_flags(FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT); let maybe_dir = options.open(p)?; if maybe_dir.metadata()?.is_symlink() { return Err(io::Error::new( io::ErrorKind::Other, "Path is a directory link, not directory", )); } Ok(maybe_dir) } type UniqueIdentifier = VSNFileId; fn unique_identifier(d: &File) -> io::Result { let mut info = MaybeUninit::::uninit(); let bool_result = unsafe { GetFileInformationByHandleEx( d.as_raw_handle() as HANDLE, FileIdInfo, info.as_mut_ptr() as *mut c_void, size_of::() as u32, ) }; if bool_result == 0 { return Err(io::Error::last_os_error()); } let info = unsafe { info.assume_init() }; Ok(VSNFileId { vsn: info.VolumeSerialNumber, file_id: info.FileId.Identifier, }) } fn is_eloop(e: &io::Error) -> bool { e.raw_os_error() == Some(ERROR_CANT_RESOLVE_FILENAME as i32) } } remove_dir_all-0.8.2/src/_impl.rs000064400000000000000000000156761046102023000150720ustar 00000000000000use std::{ ffi::OsStr, fs::File, io::{ErrorKind, Result}, path::Path, }; #[cfg(windows)] use fs_at::os::windows::{FileExt, OpenOptionsExt}; #[cfg(feature = "parallel")] use rayon::prelude::*; #[cfg(windows)] use windows_sys::Win32::Storage::FileSystem::{DELETE, FILE_LIST_DIRECTORY, FILE_READ_ATTRIBUTES}; mod io; mod path_components; cfg_if::cfg_if! { if #[cfg(windows)] { mod win; pub(crate) use win::WindowsIo as OsIo; } else { mod unix; pub(crate) use unix::UnixIo as OsIo; } } impl super::RemoveDir for std::fs::File { fn remove_dir_contents(&mut self, debug_root: Option<&Path>) -> Result<()> { // thunk over to the free version adding in the os-specific IO trait impl let debug_root = match debug_root { None => PathComponents::Path(Path::new("")), Some(debug_root) => PathComponents::Path(debug_root), }; _remove_dir_contents::(self, &debug_root) } } /// Entry point for deprecated function pub(crate) fn _ensure_empty_dir_path>(path: P) -> Result<()> { // This is as TOCTOU safe as we can make it. Attacks via link replacements // in interior components of the path is still possible. if the create // succeeds, mission accomplished. if the create fails, open the dir // (subject to races again), and then proceed to delete the contents via the // descriptor. match std::fs::create_dir(&path) { Err(e) if e.kind() == ErrorKind::AlreadyExists => { // Exists and is a dir. Open it let mut existing_dir = I::open_dir(path.as_ref())?; existing_dir.remove_dir_contents(Some(path.as_ref())) } otherwise => otherwise, } } // Deprecated entry point pub(crate) fn _remove_dir_contents_path>(path: P) -> Result<()> { let mut d = I::open_dir(path.as_ref())?; _remove_dir_contents::(&mut d, &PathComponents::Path(path.as_ref())) } /// exterior lifetime interface to dir removal fn _remove_dir_contents(d: &mut File, debug_root: &PathComponents<'_>) -> Result<()> { let owned_handle = I::duplicate_fd(d)?; remove_dir_contents_recursive::(owned_handle, debug_root)?; Ok(()) } /// deprecated interface pub(crate) fn remove_dir_all_path>(path: P) -> Result<()> { let p = path.as_ref(); // Opportunity 1 for races let d = I::open_dir(p)?; let debug_root = PathComponents::Path(if p.has_root() { p } else { Path::new(".") }); remove_dir_contents_recursive::(d, &debug_root)?; // Opportunity 2 for races std::fs::remove_dir(&path)?; #[cfg(feature = "log")] log::trace!("removed {}", &debug_root); Ok(()) } use crate::RemoveDir; use self::path_components::PathComponents; // Core workhorse, heading towards this being able to be tasks. #[allow(clippy::map_identity)] fn remove_dir_contents_recursive( mut d: File, debug_root: &PathComponents<'_>, ) -> Result { #[cfg(feature = "log")] log::trace!("scanning {}", &debug_root); // We take a os level clone of the FD so that there are no lifetime // concerns. It would *not* be ok to do readdir on one file twice // concurrently because of shared kernel state. let dirfd = I::duplicate_fd(&mut d)?; cfg_if::cfg_if! { if #[cfg(feature = "parallel")] { let iter = fs_at::read_dir(&mut d)?; let iter = iter.par_bridge(); } else { let mut iter = fs_at::read_dir(&mut d)?; } } iter.try_for_each(|dir_entry| -> Result<()> { let dir_entry = dir_entry?; let name = dir_entry.name(); if name == OsStr::new(".") || name == OsStr::new("..") { return Ok(()); } let dir_path = Path::new(name); let dir_debug_root = PathComponents::Component(debug_root, dir_path); #[cfg(windows)] { // On windows: open the file and then decide what to do with it. let mut opts = fs_at::OpenOptions::default(); // Could possibly drop a syscall by dropping FILE_READ_ATTRIBUTES // and trusting read_dir metadata more. OTOH that would introduce a // race :/. opts.desired_access(DELETE | FILE_LIST_DIRECTORY | FILE_READ_ATTRIBUTES); let mut child_file = opts.open_path_at(&dirfd, name)?; let metadata = child_file.metadata()?; let is_dir = metadata.is_dir(); let is_symlink = metadata.is_symlink(); if is_dir && !is_symlink { remove_dir_contents_recursive::( I::duplicate_fd(&mut child_file)?, &dir_debug_root, )?; } #[cfg(feature = "log")] log::trace!("delete: {}", &dir_debug_root); child_file.delete_by_handle().map_err(|(_f, e)| { #[cfg(feature = "log")] log::debug!("error removing {}", dir_debug_root); e })?; } #[cfg(not(windows))] { // Otherwise, open the path safely but normally, fstat to see if its // a dir, then either unlink or recursively delete let mut opts = fs_at::OpenOptions::default(); opts.read(true) .write(fs_at::OpenOptionsWriteMode::Write) .follow(false); let child_result = opts.open_dir_at(&dirfd, name); let is_dir = match child_result { // We expect is_eloop to be the only error Err(e) if !I::is_eloop(&e) => return Err(e), Err(_) => false, Ok(child_file) => { let metadata = child_file.metadata()?; let is_dir = metadata.is_dir(); if is_dir { remove_dir_contents_recursive::(child_file, &dir_debug_root)?; #[cfg(feature = "log")] log::trace!("rmdir: {}", &dir_debug_root); let opts = fs_at::OpenOptions::default(); opts.rmdir_at(&dirfd, name).map_err(|e| { #[cfg(feature = "log")] log::debug!("error removing {}", dir_debug_root); e })?; } is_dir } }; if !is_dir { #[cfg(feature = "log")] log::trace!("unlink: {}", &dir_debug_root); opts.unlink_at(&dirfd, name).map_err(|e| { #[cfg(feature = "log")] log::debug!("error removing {}", dir_debug_root); e })?; } } #[cfg(feature = "log")] log::trace!("removed {}", dir_debug_root); Ok(()) })?; #[cfg(feature = "log")] log::trace!("scanned {}", &debug_root); Ok(dirfd) } remove_dir_all-0.8.2/src/bin/remove-dir-all.rs000064400000000000000000000007351046102023000173470ustar 00000000000000use std::{io::Result, path::PathBuf}; use clap::Parser; /// Simple CLI to use remove-dir-alls recursive deletion logic from the command /// line. #[derive(Parser)] #[command(author, version, long_about = None)] struct Cli { /// Paths to delete #[arg(value_name = "FILE")] names: Vec, } fn main() -> Result<()> { env_logger::init(); let cli = Cli::parse(); for p in cli.names { remove_dir_all::remove_dir_all(p)?; } Ok(()) } remove_dir_all-0.8.2/src/lib.rs000064400000000000000000000303241046102023000145230ustar 00000000000000//! Reliably remove a directory and all of its children. //! //! This library provides an alternative implementation of //! [`std::fs::remove_dir_all`] from the Rust std library. It varies in the //! following ways: //! - the `parallel` feature parallelises the deletion. This is useful when high //! syscall latency is occurring, such as on Windows (deletion IO accrues to //! the process), or network file systems of any kind. This is off by default. //! - It tolerates files not being deleted atomically (this is a Windows //! specific behaviour). //! - It resets the readonly flag on Windows as needed. //! //! Like `remove_dir_all` it assumes both that the caller has permission to //! delete the files, and that they don't have permission to change permissions //! to be able to delete the files: no ACL or chmod changes are made during //! deletion. This is because hardlinks can cause such changes to show up and //! affect the filesystem outside of the directory tree being deleted. //! //! The extension trait [`RemoveDir`] can be used to invoke `remove_dir_all` on //! an open [`File`](std::fs::File), where it will error if the file is not a directory, //! and otherwise delete the contents. This allows callers to be more confident that //! what is deleted is what was requested even in the presence of malicious //! actors changing the filesystem concurrently. //! //! The functions [`remove_dir_all`], [`remove_dir_contents`], and [`ensure_empty_dir`] //! are intrinsically sensitive to file system races, as the path to the //! directory to delete can be substituted by an attacker inserting a symlink //! along that path. Relative paths with one path component are the least //! fragile, but using [`RemoveDir::remove_dir_contents`] is recommended. //! //! ## Features //! //! - parallel: When enabled, deletion of directories is parallised. (#parallel)[more details] //! - log: Include some log messages about the deletion taking place. //! //! About the implementation. The implementation prioritises security, then //! robustness (e.g. low resource situations), and then finally performance. //! //! ## Security //! //! On all platforms directory related race conditions are avoided by opening //! paths and then iterating directory contents and deleting names in the //! directory with _at style syscalls. This does not entirely address possible //! races on unix style operating systems (but see the funlinkat call on //! FreeBSD, which could if more widely adopted). It does prevent attackers from //! replacing intermediary directories with symlinks in order to fool privileged //! code into traversing outside the intended directory tree. This is the same //! as the standard library implementation. //! //! This function is not designed to succeed in the presence of concurrent //! actors in the tree being deleted - for instance, adding files to a directory //! being deleted can prevent the directory being deleted for an arbitrary //! period by extending the directory iterator indefinitely. //! //! Directory traversal only ever happens downwards. In future, to accommodate //! very large directory trees (greater than file descriptor limits deep) the //! same path may be traversed multiple times, and the quadratic nature of that //! will be mitigated by a cache of open directories. See [#future-plans](Future //! Plans) //! //! ## Robustness //! //! Every opened file has its type checked through the file handle, and then //! unlinked or scanned as appropriate. Syscall overheads are minimised by //! trust-but-verify of the node type metadata returned from directory scanning: //! only names that appear to be directories get their contents scanned. The //! consequence is that if an attacker replaces a non-directory with a //! directory, or vice versa, an error will occur - but the `remove_dir_all` will //! not escape from the directory tree. On Windows file deletion requires //! obtaining a handle to the file, but again the kind metadata from the //! directory scan is used to avoid re-querying the metadata. Symlinks are //! detected by a failure to open a path with `O_NOFOLLOW`, they are unlinked with //! no further processing. //! //! ## Serial deletion //! //! Serial deletion occurs recursively - open, read, delete //! contents-except-for-directories, repeat. //! //! Parallel deletion builds on serial deletion by utilising a thread pool for //! IO which can block: //! - directory scanning //! - calls to unlink and fstat //! - file handle closing (yes, that can block) //! //! Parallel is usually a win, but some users may value compile time or size of //! compiled code more, so the `parallel` feature is opt-in. //! //! We suggest permitting the end user to control this choice: when adding //! remove-dir-all as a dependency to a library crate, expose a feature //! "parallel" that sets `remove-dir-all/parallel`. This will permit the user of //! your library to control the parallel feature inside `remove_dir_all` //! //! e.g. //! //! ```Cargo.toml //! [features] //! default = [] //! parallel = ["remove_dir_all/parallel"] //! ... //! [dependencies] //! remove_dir_all = {version = "0.8"} //! //! ## Future Plans //! Open directory handles are kept in //! a lg-spaced cache after the first 10 levels: //! level10/skipped1/level12/skipped2/skipped3/skipped4/level16. If EMFILE is //! encountered, no more handles are cached, and directories are opened by //! re-traversing from the closest previously opened handle. Deletion should //! succeed even only 4 file descriptors are available: one to hold the root, //! two to iterate individual directories, and one to open-and-delete individual //! files, though that will be quadratic in the depth of the tree, successfully //! deleting leaves only on each iteration. //! //! IO Prioritisation: //! 1) directory scanning when few paths are queued for deletion (to avoid //! ending up accidentally serial) - allowing keeping the other queues full. //! 4) close/CloseHandle (free up file descriptors) //! 2) rmdir (free up file descriptors) //! 3) unlink/SetFileInformationByHandle (to free up directories so they can be //! rmdir'd) //! //! Scanning/unlinking/rmdiring is further biased by depth and lexicographic //! order: this minimises the number of directories being worked on in parallel, //! so very branchy trees are less likely to exhaust kernel resources or //! application memory or thrash the open directory cache. //! ``` #![deny(missing_debug_implementations)] #![deny(missing_docs)] #![deny(rust_2018_idioms)] // See under "known problems" https://rust-lang.github.io/rust-clippy/master/index.html#mutex_atomic #![allow(clippy::mutex_atomic)] use std::{io::Result, path::Path}; use normpath::PathExt; #[cfg(doctest)] #[macro_use] extern crate doc_comment; #[cfg(doctest)] doctest!("../README.md"); mod _impl; /// Extension trait adding `remove_dir_all` support to [`std::fs::File`]. pub trait RemoveDir { /// Remove the contents of the dir. /// /// `debug_root`: identifies the directory contents being removed fn remove_dir_contents(&mut self, debug_root: Option<&Path>) -> Result<()>; } /// Makes `path` an empty directory: if it does not exist, it is created it as /// an empty directory (as if with [`std::fs::create_dir`]); if it does exist, its /// contents are deleted (as if with [`remove_dir_contents`]). /// /// It is an error if `path` exists but is not a directory, including a symlink /// to a directory. /// /// This is subject to file system races: a privileged process could be attacked /// by replacing parent directories of the supplied path with a link (e.g. to /// /etc). Consider using [`RemoveDir::remove_dir_contents`] instead. pub fn ensure_empty_dir>(path: P) -> Result<()> { _impl::_ensure_empty_dir_path::<_impl::OsIo, _>(path) } /// Deletes the contents of `path`, but not the directory itself. It is an error /// if `path` is not a directory. /// /// This is subject to file system races: a privileged process could be attacked /// by replacing parent directories of the supplied path with a link (e.g. to /// /etc). Consider using [`RemoveDir::remove_dir_contents`] instead. pub fn remove_dir_contents>(path: P) -> Result<()> { _impl::_remove_dir_contents_path::<_impl::OsIo, P>(path) } /// Reliably removes a directory and all of its children. /// /// ```rust /// use std::fs; /// use remove_dir_all::*; /// /// fs::create_dir("./temp/").unwrap(); /// remove_dir_all("./temp/").unwrap(); /// ``` /// /// Note: calling this on a non-directory (e.g. a symlink to a directory) will /// error. /// /// [`RemoveDir::remove_dir_contents`] is somewhat safer and /// recommended as the path based version is subject to file system races /// determining what to delete: a privileged process could be attacked by /// replacing parent directories of the supplied path with a link (e.g. to /// /etc). Consider using [`RemoveDir::remove_dir_contents`] instead. pub fn remove_dir_all>(path: P) -> Result<()> { let path = path.as_ref().normalize()?; _impl::remove_dir_all_path::<_impl::OsIo, _>(path) } #[allow(deprecated)] #[cfg(test)] mod tests { //! functional tests for all platforms //! //! A note on safety: races are notoriously hard to secure merely via tests: //! these tests use a dedicated trait to allow sequencing attack operations, //! much the same as the test clock in Tokio programs. So these 'safe' tests //! are not actually attempting scheduling races, rather they are showing //! that the known attacks don't work. A fuzz based heuristic functional //! test would be a good addition to complement these tests. use super::Result; use std::fs::{self, File}; use std::io; use std::path::PathBuf; use tempfile::TempDir; use test_log::test; use crate::ensure_empty_dir; use crate::remove_dir_all; use crate::remove_dir_contents; cfg_if::cfg_if! { if #[cfg(windows)] { const ENOTDIR:i32 = windows_sys::Win32::Foundation::ERROR_DIRECTORY as i32; const ENOENT:i32 = windows_sys::Win32::Foundation::ERROR_FILE_NOT_FOUND as i32; const INVALID_INPUT:i32 = windows_sys::Win32::Foundation::ERROR_INVALID_PARAMETER as i32; } else { const ENOTDIR:i32 = libc::ENOTDIR; const ENOENT:i32 = libc::ENOENT; const INVALID_INPUT:i32 = libc::EINVAL; } } /// Expect a particular sort of failure fn expect_failure(n: &[i32], r: io::Result) -> io::Result<()> { match r { Err(e) if n.iter() .map(|n| Option::Some(*n)) .any(|n| n == e.raw_os_error()) => { Ok(()) } Err(e) => { println!("{e} {:?}, {:?}, {:?}", e.raw_os_error(), e.kind(), n); Err(e) } Ok(_) => Err(io::Error::new( io::ErrorKind::Other, "unexpected success".to_string(), )), } } struct Prep { _tmp: TempDir, ours: PathBuf, file: PathBuf, } /// Create test setup: t.mkdir/file all in a tempdir. fn prep() -> Result { let tmp = TempDir::new()?; let ours = tmp.path().join("t.mkdir"); let file = ours.join("file"); let nested = ours.join("another_dir"); fs::create_dir(&ours)?; fs::create_dir(nested)?; File::create(&file)?; File::open(&file)?; Ok(Prep { _tmp: tmp, ours, file, }) } #[test] fn mkdir_rm() -> Result<()> { let p = prep()?; expect_failure(&[ENOTDIR, INVALID_INPUT], remove_dir_contents(&p.file))?; remove_dir_contents(&p.ours)?; expect_failure(&[ENOENT], File::open(&p.file))?; remove_dir_contents(&p.ours)?; remove_dir_all(&p.ours)?; expect_failure(&[ENOENT], remove_dir_contents(&p.ours))?; Ok(()) } #[test] fn ensure_rm() -> Result<()> { let p = prep()?; expect_failure(&[ENOTDIR, INVALID_INPUT], ensure_empty_dir(&p.file))?; ensure_empty_dir(&p.ours)?; expect_failure(&[ENOENT], File::open(&p.file))?; ensure_empty_dir(&p.ours)?; remove_dir_all(&p.ours)?; ensure_empty_dir(&p.ours)?; File::create(&p.file)?; Ok(()) } }