├── .github ├── FUNDING.yml └── workflows │ ├── ci.yml │ └── install.yml ├── .gitignore ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md └── src └── main.rs /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: dtolnay 2 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | pull_request: 6 | workflow_dispatch: 7 | schedule: [cron: "40 1 * * *"] 8 | 9 | permissions: 10 | contents: read 11 | 12 | env: 13 | RUSTFLAGS: -Dwarnings 14 | 15 | jobs: 16 | pre_ci: 17 | uses: dtolnay/.github/.github/workflows/pre_ci.yml@master 18 | 19 | test: 20 | name: Rust ${{matrix.rust}} 21 | needs: pre_ci 22 | if: needs.pre_ci.outputs.continue 23 | runs-on: ubuntu-latest 24 | strategy: 25 | fail-fast: false 26 | matrix: 27 | rust: [nightly, beta, stable, 1.74.0] 28 | timeout-minutes: 45 29 | steps: 30 | - uses: actions/checkout@v4 31 | - uses: dtolnay/rust-toolchain@master 32 | with: 33 | toolchain: ${{matrix.rust}} 34 | - name: Enable type layout randomization 35 | run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV 36 | if: matrix.rust == 'nightly' 37 | - run: cargo check 38 | - run: cargo test 39 | - uses: actions/upload-artifact@v4 40 | if: matrix.rust == 'nightly' && always() 41 | with: 42 | name: Cargo.lock 43 | path: Cargo.lock 44 | continue-on-error: true 45 | 46 | clippy: 47 | name: Clippy 48 | runs-on: ubuntu-latest 49 | if: github.event_name != 'pull_request' 50 | timeout-minutes: 45 51 | steps: 52 | - uses: actions/checkout@v4 53 | - uses: dtolnay/rust-toolchain@clippy 54 | - run: cargo clippy -- -Dclippy::all -Dclippy::pedantic 55 | 56 | outdated: 57 | name: Outdated 58 | runs-on: ubuntu-latest 59 | if: github.event_name != 'pull_request' 60 | timeout-minutes: 45 61 | steps: 62 | - uses: actions/checkout@v4 63 | - uses: dtolnay/rust-toolchain@stable 64 | - uses: dtolnay/install@cargo-outdated 65 | - run: cargo outdated --workspace --exit-code 1 66 | -------------------------------------------------------------------------------- /.github/workflows/install.yml: -------------------------------------------------------------------------------- 1 | name: Install 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: [cron: "40 1 * * *"] 6 | push: {tags: ['*']} 7 | 8 | permissions: {} 9 | 10 | env: 11 | RUSTFLAGS: -Dwarnings 12 | 13 | jobs: 14 | install: 15 | name: Install 16 | uses: dtolnay/.github/.github/workflows/check_install.yml@master 17 | with: 18 | crate: sha1dir 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /Cargo.lock 2 | /target/ 3 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sha1dir" 3 | version = "1.0.10" 4 | authors = ["David Tolnay "] 5 | categories = ["command-line-utilities"] 6 | description = "Checksum of a directory tree" 7 | edition = "2021" 8 | license = "MIT OR Apache-2.0" 9 | repository = "https://github.com/dtolnay/sha1dir" 10 | 11 | [dependencies] 12 | clap = { version = "4", features = ["deprecated", "derive"] } 13 | memmap = "0.7" 14 | num_cpus = "1.0" 15 | parking_lot = "0.12" 16 | rayon = "1.0" 17 | sha1 = "0.10" 18 | 19 | [profile.release] 20 | panic = "abort" 21 | 22 | [package.metadata.docs.rs] 23 | targets = ["x86_64-unknown-linux-gnu"] 24 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any 2 | person obtaining a copy of this software and associated 3 | documentation files (the "Software"), to deal in the 4 | Software without restriction, including without 5 | limitation the rights to use, copy, modify, merge, 6 | publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software 8 | is furnished to do so, subject to the following 9 | conditions: 10 | 11 | The above copyright notice and this permission notice 12 | shall be included in all copies or substantial portions 13 | of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 16 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 17 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 18 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 19 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | sha1dir 2 | ======= 3 | 4 | [github](https://github.com/dtolnay/sha1dir) 5 | [crates.io](https://crates.io/crates/sha1dir) 6 | [build status](https://github.com/dtolnay/sha1dir/actions?query=branch%3Amaster) 7 | 8 | Compute a checksum of a directory tree, for example to validate that a directory 9 | was copied successfully to a different machine. 10 | 11 | ## Installation 12 | 13 | ```console 14 | $ RUSTFLAGS='-C target-cpu=native' cargo install sha1dir 15 | ``` 16 | 17 | ## Usage 18 | 19 | Run `sha1dir` to checksum the current directory, or run `sha1dir path/to/dir1 20 | path/to/dir2 ...` to checksum one or more other directories. 21 | 22 | ## Behavior 23 | 24 | The checksum is computed as the bitwise XOR of SHA-1 hashes one per directory 25 | entry. The hash for each directory entry is the hash of the following body: 26 | 27 | - For regular files — the one byte `'f'`, 4 little endian bytes for the path 28 | length, the bytes of the path, 4 little endian bytes for the Unix file mode 29 | as given by st\_mode, and finally the file contents. 30 | 31 | - For symbolic links — the one byte `'l'`, the path length / path / mode as for 32 | regular files, and then the path of the link target. 33 | 34 | - For directories — the one byte `'d'`, and the path length / path / mode. 35 | 36 | The resulting checksum is 160 bits wide like SHA-1. 37 | 38 |
39 | 40 | #### License 41 | 42 | 43 | Licensed under either of Apache License, Version 44 | 2.0 or MIT license at your option. 45 | 46 | 47 |
48 | 49 | 50 | Unless you explicitly state otherwise, any contribution intentionally submitted 51 | for inclusion in this crate by you, as defined in the Apache-2.0 license, shall 52 | be dual licensed as above, without any additional terms or conditions. 53 | 54 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | //! [![github]](https://github.com/dtolnay/sha1dir) [![crates-io]](https://crates.io/crates/sha1dir) [![docs-rs]](https://docs.rs/sha1dir) 2 | //! 3 | //! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github 4 | //! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust 5 | //! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs 6 | 7 | #![allow( 8 | clippy::cast_possible_truncation, 9 | clippy::let_underscore_untyped, 10 | clippy::needless_collect, 11 | clippy::needless_pass_by_value, 12 | clippy::uninlined_format_args, 13 | clippy::unnecessary_wraps, 14 | clippy::unseparated_literal_suffix 15 | )] 16 | 17 | use clap::Parser; 18 | use memmap::Mmap; 19 | use parking_lot::Mutex; 20 | use rayon::{Scope, ThreadPoolBuilder}; 21 | use sha1::{Digest, Sha1}; 22 | use std::cmp; 23 | use std::env; 24 | use std::error::Error; 25 | use std::fmt::{self, Display}; 26 | use std::fs::{self, File, Metadata}; 27 | use std::io::{self, Write}; 28 | use std::os::unix::ffi::OsStrExt; 29 | use std::os::unix::fs::{FileTypeExt, MetadataExt}; 30 | use std::path::{Path, PathBuf}; 31 | use std::process; 32 | use std::sync::Once; 33 | 34 | type Result = std::result::Result>; 35 | 36 | fn die, E: Display>(path: P, error: E) -> ! { 37 | static DIE: Once = Once::new(); 38 | 39 | DIE.call_once(|| { 40 | let path = path.as_ref().display(); 41 | let _ = writeln!( 42 | io::stderr(), 43 | "{}: {}: {}", 44 | env!("CARGO_BIN_NAME"), 45 | path, 46 | error, 47 | ); 48 | process::exit(1); 49 | }); 50 | 51 | unreachable!() 52 | } 53 | 54 | #[derive(Debug, Parser)] 55 | #[command(about = "Compute checksum of directory.", version, author)] 56 | struct Opt { 57 | /// Number of hashes to compute in parallel 58 | #[arg(short)] 59 | jobs: Option, 60 | 61 | /// Directories to hash 62 | #[arg(value_name = "DIR")] 63 | dirs: Vec, 64 | 65 | /// Whether to ignore unknown filetypes (otherwise fatal) 66 | #[arg(long)] 67 | ignore_unknown_filetypes: bool, 68 | } 69 | 70 | fn main() { 71 | let opt = Opt::parse(); 72 | 73 | configure_thread_pool(&opt); 74 | 75 | if opt.dirs.is_empty() { 76 | let path = Path::new("."); 77 | let checksum = checksum_current_dir(path, opt.ignore_unknown_filetypes); 78 | let _ = writeln!(io::stdout(), "{}", checksum); 79 | return; 80 | } 81 | 82 | let absolute_dirs: Vec<_> = opt.dirs.iter().map(canonicalize).collect(); 83 | for (canonical, label) in absolute_dirs.into_iter().zip(opt.dirs) { 84 | debug_assert!(canonical.is_absolute()); 85 | if let Err(error) = env::set_current_dir(canonical) { 86 | die(label, error); 87 | } 88 | let checksum = checksum_current_dir(&label, opt.ignore_unknown_filetypes); 89 | let _ = writeln!(io::stdout(), "{} {}", checksum, label.display()); 90 | } 91 | } 92 | 93 | fn configure_thread_pool(opt: &Opt) { 94 | let threads = if let Some(jobs) = opt.jobs { 95 | jobs 96 | } else { 97 | // Limit to 8 threads by default to avoid thrashing disk. 98 | cmp::min(num_cpus::get(), 8) 99 | }; 100 | 101 | let result = ThreadPoolBuilder::new().num_threads(threads).build_global(); 102 | 103 | // This is the only time the thread pool is initialized. 104 | result.unwrap(); 105 | } 106 | 107 | fn canonicalize>(path: P) -> PathBuf { 108 | match fs::canonicalize(&path) { 109 | Ok(canonical) => canonical, 110 | Err(error) => die(path, error), 111 | } 112 | } 113 | 114 | struct Checksum { 115 | bytes: Mutex<[u8; 20]>, 116 | } 117 | 118 | impl Checksum { 119 | fn new() -> Self { 120 | Checksum { 121 | bytes: Mutex::new([0u8; 20]), 122 | } 123 | } 124 | } 125 | 126 | impl Display for Checksum { 127 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 128 | for i in self.bytes.lock().as_ref() { 129 | write!(f, "{:02x}", i)?; 130 | } 131 | Ok(()) 132 | } 133 | } 134 | 135 | impl Checksum { 136 | fn put(&self, rhs: Sha1) { 137 | for (lhs, rhs) in self.bytes.lock().iter_mut().zip(rhs.finalize()) { 138 | *lhs ^= rhs; 139 | } 140 | } 141 | } 142 | 143 | fn checksum_current_dir(label: &Path, ignore_unknown_filetypes: bool) -> Checksum { 144 | let checksum = Checksum::new(); 145 | rayon::scope(|scope| { 146 | if let Err(error) = (|| -> Result<()> { 147 | for child in Path::new(".").read_dir()? { 148 | let child = child?; 149 | scope.spawn({ 150 | let checksum = &checksum; 151 | move |scope| { 152 | entry( 153 | scope, 154 | label, 155 | checksum, 156 | Path::new(&child.file_name()), 157 | ignore_unknown_filetypes, 158 | ); 159 | } 160 | }); 161 | } 162 | Ok(()) 163 | })() { 164 | die(label, error); 165 | } 166 | }); 167 | checksum 168 | } 169 | 170 | fn entry<'scope>( 171 | scope: &Scope<'scope>, 172 | base: &'scope Path, 173 | checksum: &'scope Checksum, 174 | path: &Path, 175 | ignore_unknown_filetypes: bool, 176 | ) { 177 | let metadata = match path.symlink_metadata() { 178 | Ok(metadata) => metadata, 179 | Err(error) => die(base.join(path), error), 180 | }; 181 | 182 | let file_type = metadata.file_type(); 183 | let result = if file_type.is_file() { 184 | file(checksum, path, metadata) 185 | } else if file_type.is_symlink() { 186 | symlink(checksum, path, metadata) 187 | } else if file_type.is_dir() { 188 | dir( 189 | scope, 190 | base, 191 | checksum, 192 | path, 193 | ignore_unknown_filetypes, 194 | metadata, 195 | ) 196 | } else if file_type.is_socket() { 197 | socket(checksum, path, metadata) 198 | } else if ignore_unknown_filetypes { 199 | Ok(()) 200 | } else { 201 | die(base.join(path), "Unsupported file type"); 202 | }; 203 | 204 | if let Err(error) = result { 205 | die(base.join(path), error); 206 | } 207 | } 208 | 209 | fn file(checksum: &Checksum, path: &Path, metadata: Metadata) -> Result<()> { 210 | let mut sha = begin(path, &metadata, b'f'); 211 | 212 | // Enforced by memmap: "memory map must have a non-zero length" 213 | if metadata.len() > 0 { 214 | let file = File::open(path)?; 215 | let mmap = unsafe { Mmap::map(&file)? }; 216 | sha.update(&mmap); 217 | } 218 | 219 | checksum.put(sha); 220 | 221 | Ok(()) 222 | } 223 | 224 | fn symlink(checksum: &Checksum, path: &Path, metadata: Metadata) -> Result<()> { 225 | let mut sha = begin(path, &metadata, b'l'); 226 | sha.update(path.read_link()?.as_os_str().as_bytes()); 227 | checksum.put(sha); 228 | 229 | Ok(()) 230 | } 231 | 232 | fn dir<'scope>( 233 | scope: &Scope<'scope>, 234 | base: &'scope Path, 235 | checksum: &'scope Checksum, 236 | path: &Path, 237 | ignore_unknown_filetypes: bool, 238 | metadata: Metadata, 239 | ) -> Result<()> { 240 | let sha = begin(path, &metadata, b'd'); 241 | checksum.put(sha); 242 | 243 | for child in path.read_dir()? { 244 | let child = child?.path(); 245 | scope.spawn(move |scope| entry(scope, base, checksum, &child, ignore_unknown_filetypes)); 246 | } 247 | 248 | Ok(()) 249 | } 250 | 251 | fn socket(checksum: &Checksum, path: &Path, metadata: Metadata) -> Result<()> { 252 | let sha = begin(path, &metadata, b's'); 253 | checksum.put(sha); 254 | 255 | Ok(()) 256 | } 257 | 258 | fn begin(path: &Path, metadata: &Metadata, kind: u8) -> Sha1 { 259 | let mut sha = Sha1::new(); 260 | let path_bytes = path.as_os_str().as_bytes(); 261 | sha.update([kind]); 262 | sha.update((path_bytes.len() as u32).to_le_bytes()); 263 | sha.update(path_bytes); 264 | sha.update(metadata.mode().to_le_bytes()); 265 | sha 266 | } 267 | 268 | #[test] 269 | fn test_cli() { 270 | ::command().debug_assert(); 271 | } 272 | --------------------------------------------------------------------------------