├── .gitignore ├── .travis.yml ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── LICENSE-MPL2 ├── README.md ├── rustfmt.toml ├── src └── lib.rs └── tests └── sanity.rs /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | cache: 3 | - cargo 4 | rust: 5 | - stable 6 | - beta 7 | - nightly 8 | os: 9 | - linux 10 | - osx 11 | - windows 12 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | edition = "2021" 3 | name = "crev-recursive-digest" 4 | version = "0.6.0" 5 | description = "Library implementing recursive digest for filesystem directories" 6 | authors = ["Dawid Ciężarkiewicz "] 7 | documentation = "https://docs.rs/crev-recursive-digest" 8 | repository = "https://github.com/crev-dev/cargo-crev/tree/master/recursive-digest" 9 | homepage = "https://github.com/crev-dev/cargo-crev/tree/master/recursive-digest" 10 | keywords = ["data", "filesystem", "digest", "hash"] 11 | license = "MPL-2.0 OR MIT OR Apache-2.0" 12 | readme = "README.md" 13 | 14 | [dependencies] 15 | digest = "0.10.6" 16 | thiserror = "1.0.40" 17 | walkdir = "2.3.3" 18 | 19 | [dev-dependencies] 20 | hex = "0.4.3" 21 | tempdir = "0.3.7" 22 | blake2 = "0.10.6" 23 | 24 | [workspace] 25 | -------------------------------------------------------------------------------- /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 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 The Rust Project Developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /LICENSE-MPL2: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Recursive file-system digest 2 | 3 | This library implements a simple but efficient recursive file-system digest 4 | algorithm. You have a directory with some content in it, and you'd like 5 | a cryptographical digest (hash) of its content. 6 | 7 | It was created for the purpose of checksuming source code packages 8 | in `crev`, but it is generic and can be used for any other purpose. 9 | 10 | ## Algorithm 11 | 12 | Given any digest algorithm `H` (a Hash function algorithm), 13 | a `RecursiveDigest(H, path)` is: 14 | 15 | * for a file: `H("F" || file_content)` 16 | * for a symlink: `H("L" || symlink_content)` 17 | * for a directory: `H("D" || directory_content)` 18 | 19 | As you can see a one-letter ASCII prefix is used to make it impossible 20 | to create a file that has the same digest as a directory, 21 | etc. The drawback of this approach is that `RecursiveDigest(H, path)` of 22 | a simple file is not the same as just a normal digest of it (`H(file_content)`) . 23 | 24 | `file_content` is just the byte content of a file. 25 | 26 | `symlink_content` is just the path the symlink is pointing to, as bytes. 27 | 28 | `directory_content` is created by: 29 | 30 | * sorting all entries of a directory by name, in ascending order, 31 | using a simple byte-sequence comparison 32 | * for all entries concatenating pairs of: 33 | * `H(entry_name)` 34 | * `RecursiveDigest(H, entry_path)` 35 | 36 | If optional additional data extensions is used, the `H(entry_name)` above becomes 37 | `H(entry_name || 0 || additional data)`. The format and meaning of additional 38 | data is unspecified, but was intendet for fielsystem metadata like file system 39 | permissions and ownership. 40 | 41 | 42 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | edition = "2018" 2 | merge_imports = true 3 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Recursive digest for filesystem path content 2 | use std::marker::PhantomData; 3 | use std::{ 4 | collections::HashSet, 5 | ffi::OsStr, 6 | fs, 7 | io::BufRead, 8 | path::{Path, PathBuf}, 9 | }; 10 | use thiserror::Error; 11 | 12 | /// Re-export `walkdir` 13 | pub use walkdir; 14 | 15 | /// Read file content into a `digest::Digest` 16 | fn read_file_to_digest_input(path: &Path, input: &mut impl digest::Digest) -> std::io::Result<()> { 17 | let file = fs::File::open(path)?; 18 | 19 | let mut reader = std::io::BufReader::new(file); 20 | 21 | loop { 22 | let length = { 23 | let buffer = reader.fill_buf()?; 24 | input.update(buffer); 25 | buffer.len() 26 | }; 27 | if length == 0 { 28 | break; 29 | } 30 | reader.consume(length); 31 | } 32 | 33 | Ok(()) 34 | } 35 | 36 | #[derive(Debug, Error)] 37 | pub enum DigestError { 38 | #[error("could not convert OsStr string to utf8")] 39 | OsStrConversionError, 40 | #[error("io Error: {}", _0)] 41 | IoError(std::io::Error), 42 | #[error("walkdir Error: {}", _0)] 43 | WalkdirError(walkdir::Error), 44 | #[error("an entry that was supposed to be a file, contains sub-entries")] 45 | FileWithSubentriesError, 46 | #[error("file not supported: {}", _0)] 47 | FileNotSupported(String), 48 | } 49 | 50 | impl From for DigestError { 51 | fn from(err: std::io::Error) -> Self { 52 | DigestError::IoError(err) 53 | } 54 | } 55 | 56 | impl From for DigestError { 57 | fn from(err: walkdir::Error) -> Self { 58 | DigestError::WalkdirError(err) 59 | } 60 | } 61 | 62 | /// Handle passed to the user to add optional path data 63 | pub struct AdditionalDataWriter<'a, D> { 64 | used: bool, 65 | hasher: &'a mut D, 66 | } 67 | 68 | impl<'a, D> AdditionalDataWriter<'a, D> 69 | where 70 | D: digest::Digest, 71 | { 72 | pub fn input(&mut self, bytes: &[u8]) { 73 | if !bytes.is_empty() { 74 | if !self.used { 75 | self.hasher.update([0]); 76 | self.used = true; 77 | } 78 | self.hasher.update(bytes); 79 | } 80 | } 81 | } 82 | 83 | pub struct RecursiveDigestBuilder { 84 | filter: FFilter, 85 | additional_data: FAData, 86 | digest: std::marker::PhantomData, 87 | } 88 | 89 | impl RecursiveDigestBuilder 90 | where 91 | FFilter: Fn(&walkdir::DirEntry) -> bool, 92 | FAData: Fn(&walkdir::DirEntry, &mut AdditionalDataWriter<'_, D>) -> Result<(), DigestError>, 93 | { 94 | /// Set filter function just like [`walkdir::IntoIterator::filter_entry`] 95 | pub fn filter bool>( 96 | self, 97 | filter: F, 98 | ) -> RecursiveDigestBuilder { 99 | RecursiveDigestBuilder { 100 | filter, 101 | additional_data: self.additional_data, 102 | digest: self.digest, 103 | } 104 | } 105 | 106 | pub fn additional_data< 107 | F: Fn(&walkdir::DirEntry, &mut AdditionalDataWriter<'_, D>) -> Result<(), DigestError>, 108 | >( 109 | self, 110 | f: F, 111 | ) -> RecursiveDigestBuilder { 112 | RecursiveDigestBuilder { 113 | filter: self.filter, 114 | additional_data: f, 115 | digest: self.digest, 116 | } 117 | } 118 | 119 | pub fn build(self) -> RecursiveDigest { 120 | RecursiveDigest { 121 | digest: self.digest, 122 | filter: self.filter, 123 | additional_data: self.additional_data, 124 | } 125 | } 126 | } 127 | 128 | /// Recursive Digest 129 | /// 130 | /// Can calculate a recursive digest for a path 131 | pub struct RecursiveDigest { 132 | digest: PhantomData, 133 | filter: FFilter, 134 | additional_data: FAData, 135 | } 136 | 137 | impl 138 | RecursiveDigest< 139 | D, 140 | Box bool>, 141 | Box< 142 | dyn Fn(&walkdir::DirEntry, &mut AdditionalDataWriter<'_, D>) -> Result<(), DigestError>, 143 | >, 144 | > 145 | where 146 | D: digest::Digest + digest::FixedOutput, 147 | { 148 | /// Create `RecursiveDigest` by configuring `RecursiveDigestBuilder` 149 | #[must_use] 150 | pub fn new() -> RecursiveDigestBuilder< 151 | D, 152 | Box bool>, 153 | Box< 154 | dyn Fn(&walkdir::DirEntry, &mut AdditionalDataWriter<'_, D>) -> Result<(), DigestError>, 155 | >, 156 | > { 157 | RecursiveDigestBuilder { 158 | filter: Box::new(|_| true), 159 | additional_data: Box::new(|_, _| Ok(())), 160 | digest: PhantomData, 161 | } 162 | } 163 | } 164 | 165 | #[cfg(unix)] 166 | fn hash_osstr(digest: &mut D, s: &OsStr) { 167 | use std::os::unix::ffi::OsStrExt; 168 | digest.update(s.as_bytes()); 169 | } 170 | 171 | #[cfg(not(unix))] 172 | fn hash_osstr(digest: &mut D, s: &OsStr) { 173 | digest.update(s.to_string_lossy().as_bytes()); 174 | } 175 | 176 | impl RecursiveDigest 177 | where 178 | FFilter: Fn(&walkdir::DirEntry) -> bool, 179 | FAData: Fn(&walkdir::DirEntry, &mut AdditionalDataWriter<'_, D>) -> Result<(), DigestError>, 180 | D: digest::Digest + digest::FixedOutput, 181 | { 182 | pub fn get_digest_of(&self, root_path: &Path) -> Result, DigestError> { 183 | let mut hashers = vec![]; 184 | 185 | // pop the top hasher and output it to the one just above it 186 | fn flush_up_one_level(hashers: &mut Vec) { 187 | let hasher = hashers.pop().expect("must not be empty yet"); 188 | let h2 = hashers 189 | .last_mut() 190 | .expect("must not happen"); 191 | ::update(h2, hasher.finalize_fixed().as_slice()); 192 | } 193 | 194 | let base_depth = root_path.components().count(); 195 | 196 | let mut first = true; 197 | for entry in walkdir::WalkDir::new(root_path) 198 | .follow_links(false) 199 | .sort_by(|a, b| a.path().cmp(b.path())) 200 | .into_iter() 201 | .filter_entry(|entry| { 202 | // can't skip the `root_path` 203 | if first { 204 | debug_assert_eq!(root_path, entry.path()); 205 | first = false; 206 | return true; 207 | } 208 | 209 | (self.filter)(entry) 210 | }) 211 | { 212 | let entry = entry?; 213 | let entry_depth = entry.path().components().count(); 214 | 215 | debug_assert!(base_depth <= entry_depth); 216 | let depth = entry_depth - base_depth; 217 | let hasher_size_required = depth + 1; 218 | 219 | // we finished with (potentially multiple levels of) recursive content 220 | // in the previous iterations, now: 221 | // we flush it upwards, and replace the top one with a fresh one 222 | while hasher_size_required <= hashers.len() { 223 | flush_up_one_level(&mut hashers); 224 | } 225 | hashers.push(D::new()); 226 | 227 | debug_assert_eq!(hashers.len(), hasher_size_required); 228 | 229 | let file_type = entry.file_type(); 230 | 231 | // top level directory includes only content, no name or additional_data 232 | // names and additional data go the hasher above the one we just prepared 233 | if 0 < depth { 234 | let hasher = hashers.get_mut(depth - 1).expect("must not happen"); 235 | 236 | let mut name_hasher = D::new(); 237 | // name 238 | hash_osstr( 239 | &mut name_hasher, 240 | entry.path().file_name().expect("must have a file_name"), 241 | ); 242 | // additional data (optional) 243 | (self.additional_data)( 244 | &entry, 245 | &mut AdditionalDataWriter { 246 | hasher, 247 | used: false, 248 | }, 249 | )?; 250 | ::update(hasher, name_hasher.finalize_fixed().as_slice()); 251 | } 252 | 253 | // content 254 | if file_type.is_file() { 255 | self.read_content_of_file( 256 | entry.path(), 257 | hashers.last_mut().expect("must not happen"), 258 | )?; 259 | } else if file_type.is_symlink() { 260 | self.read_content_of_symlink( 261 | entry.path(), 262 | hashers.last_mut().expect("must not happen"), 263 | )?; 264 | } else if file_type.is_dir() { 265 | let hasher = hashers.last_mut().expect("must not happen"); 266 | ::update(hasher, b"D"); 267 | } else { 268 | return Err(DigestError::FileNotSupported( 269 | entry.path().display().to_string(), 270 | )); 271 | } 272 | } 273 | 274 | loop { 275 | if hashers.len() == 1 { 276 | return Ok(hashers 277 | .pop() 278 | .expect("must not fail") 279 | .finalize_fixed() 280 | .to_vec()); 281 | } 282 | flush_up_one_level(&mut hashers); 283 | } 284 | } 285 | 286 | fn read_content_of_file( 287 | &self, 288 | full_path: &Path, 289 | parent_hasher: &mut D, 290 | ) -> Result<(), DigestError> { 291 | ::update(parent_hasher, b"F"); 292 | read_file_to_digest_input(full_path, parent_hasher)?; 293 | Ok(()) 294 | } 295 | 296 | fn read_content_of_symlink( 297 | &self, 298 | full_path: &Path, 299 | parent_hasher: &mut D, 300 | ) -> Result<(), DigestError> { 301 | ::update(parent_hasher, b"L"); 302 | ::update(parent_hasher, 303 | full_path 304 | .read_link()? 305 | .to_str() 306 | .ok_or(DigestError::OsStrConversionError)? 307 | .as_bytes(), 308 | ); 309 | Ok(()) 310 | } 311 | } 312 | 313 | #[deprecated] 314 | pub fn get_recursive_digest_for_paths( 315 | root_path: &Path, 316 | paths: HashSet, 317 | ) -> Result, DigestError> 318 | where 319 | H: std::hash::BuildHasher, 320 | { 321 | let h = RecursiveDigest::::new() 322 | .filter(|entry| { 323 | let rel_path = entry 324 | .path() 325 | .strip_prefix(root_path) 326 | .expect("must be prefix"); 327 | paths.contains(rel_path) 328 | }) 329 | .build(); 330 | 331 | h.get_digest_of(root_path) 332 | } 333 | 334 | #[deprecated] 335 | pub fn get_recursive_digest_for_dir< 336 | Digest: digest::Digest + digest::FixedOutput, 337 | H: std::hash::BuildHasher, 338 | >( 339 | root_path: &Path, 340 | rel_path_ignore_list: &HashSet, 341 | ) -> Result, DigestError> { 342 | let h = RecursiveDigest::::new() 343 | .filter(|entry| { 344 | let rel_path = entry 345 | .path() 346 | .strip_prefix(root_path) 347 | .expect("must be prefix"); 348 | !rel_path_ignore_list.contains(rel_path) 349 | }) 350 | .build(); 351 | 352 | h.get_digest_of(root_path) 353 | } 354 | -------------------------------------------------------------------------------- /tests/sanity.rs: -------------------------------------------------------------------------------- 1 | #![allow(deprecated)] 2 | 3 | use digest::consts::U64; 4 | use crev_recursive_digest::DigestError; 5 | use digest::Digest; 6 | use std::{ 7 | collections::HashSet, 8 | fs, 9 | io::Write, 10 | path::{Path, PathBuf}, 11 | }; 12 | use tempdir::TempDir; 13 | 14 | #[test] 15 | fn sanity() -> Result<(), DigestError> { 16 | let tmp_dir = TempDir::new("recursive-digest-test")?; 17 | 18 | let msg = b"foo"; 19 | 20 | // Directory "recursive-digest-test/a/" 21 | let dir_path = tmp_dir.path().join("a"); 22 | fs::create_dir_all(&dir_path)?; 23 | 24 | // File "recursive-digest-test/a/foo" 25 | let file_in_dir_path = dir_path.join("foo"); 26 | let mut file_in_dir = fs::File::create(file_in_dir_path)?; 27 | file_in_dir.write_all(msg)?; 28 | drop(file_in_dir); 29 | 30 | // File "recursive-digest-test/b" 31 | let file_path = tmp_dir.path().join("b"); 32 | let mut file = fs::File::create(&file_path)?; 33 | file.write_all(msg)?; 34 | drop(file); 35 | 36 | let empty = HashSet::new(); 37 | 38 | let file_digest = crev_recursive_digest::get_recursive_digest_for_dir::, _>( 39 | &file_path, // "recursive-digest-test/b" 40 | &empty, // Exclude no files 41 | )?; 42 | 43 | let mut hasher = blake2::Blake2b::::new(); 44 | hasher.update(b"F"); 45 | hasher.update(msg); 46 | 47 | let standalone_file_digest = hasher.finalize().to_vec(); 48 | 49 | assert_eq!(&file_digest, &standalone_file_digest); 50 | // captured by `echo -ne "Ffoo" | b2sum` 51 | assert_eq!( 52 | hex::encode(&standalone_file_digest), 53 | "e41c3b6ac2b512af3a14eb11faed1486f693ce3bd3606afbe458e183ae4e1080a4209f44ada1c186920f541d41a192eaa654fee6792a6ac008f44f783a59176d" 54 | ); 55 | 56 | let dir_digest = crev_recursive_digest::get_recursive_digest_for_dir::, _>( 57 | &dir_path, // "recursive-digest-test/a/" 58 | &empty, // Exclude no files 59 | )?; 60 | assert_ne!(&dir_digest, &standalone_file_digest); 61 | let mut hasher = blake2::Blake2b::::new(); 62 | hasher.update(b"D"); 63 | hasher.update( 64 | &hex::decode( 65 | "ca002330e69d3e6b84a46a56a6533fd79d51d97a3bb7cad6c2ff43b354185d6dc1e723fb3db4ae0737e120378424c714bb982d9dc5bbd7a0ab318240ddd18f8d" 66 | ).unwrap() 67 | ); 68 | 69 | hasher.update(&file_digest); 70 | 71 | let manual_dir_digest = hasher.finalize().to_vec(); 72 | assert_eq!(&dir_digest, &manual_dir_digest); 73 | 74 | Ok(()) 75 | } 76 | 77 | #[cfg(target_family = "windows")] 78 | pub fn symlink_file, Q: AsRef>(src: P, dst: Q) -> std::io::Result<()> { 79 | std::os::windows::fs::symlink_file(src, dst) 80 | } 81 | 82 | #[cfg(target_family = "unix")] 83 | pub fn symlink_file, Q: AsRef>(src: P, dst: Q) -> std::io::Result<()> { 84 | std::os::unix::fs::symlink(src, dst) 85 | } 86 | 87 | /// Captured by: 88 | /// 89 | /// ``` 90 | /// mkdir -p /tmp/a/b/c/d/e/f/g 91 | /// ln -sf /tmp/a/b/c/d/e/f/g/h "../../a" 92 | /// rblake2sum /tmp/a 93 | /// ``` 94 | /// 95 | /// Ignored by default on Windows, as users typically cannot create symlinks 96 | /// without running as admin. 97 | #[test] 98 | #[cfg_attr(target_family = "windows", ignore)] 99 | fn backward_comp() -> Result<(), DigestError> { 100 | let tmp_dir = TempDir::new("recursive-digest-test2")?; 101 | 102 | let dir_path = tmp_dir.path().join("a"); 103 | let path = dir_path.clone(); 104 | let path = path.join("b"); 105 | let path = path.join("c"); 106 | let path = path.join("d"); 107 | let path = path.join("e"); 108 | let path = path.join("f"); 109 | let path = path.join("g"); 110 | fs::create_dir_all(&path)?; 111 | 112 | symlink_file(std::path::PathBuf::from("../../a"), path.join("h"))?; 113 | 114 | let dir_digest = crev_recursive_digest::get_recursive_digest_for_dir::, _>( 115 | &dir_path, 116 | &HashSet::new(), 117 | )?; 118 | 119 | assert_eq!( 120 | hex::encode(dir_digest), 121 | "bc97399633e1228a563d57adecf98810364526a8e7bfc24b89985c5607e77605575d10989d5954b762af45c498129854dca603688fd63bd580bbf952c650b735" 122 | ); 123 | tmp_dir.into_path(); 124 | Ok(()) 125 | } 126 | 127 | #[test] 128 | fn test_file_digest() -> Result<(), DigestError> { 129 | let tmp_dir = TempDir::new("recursive-digest-test3")?; 130 | let foo_content = b"foo_content"; 131 | let file_in_dir_path = tmp_dir.path().join("foo"); 132 | let mut file_in_dir = fs::File::create(&file_in_dir_path)?; 133 | file_in_dir.write_all(foo_content)?; 134 | 135 | let empty = HashSet::new(); 136 | 137 | let expected = { 138 | let mut hasher = blake2::Blake2b::::new(); 139 | hasher.update(b"F"); 140 | hasher.update(foo_content); 141 | hasher.finalize().to_vec() 142 | }; 143 | 144 | assert_eq!( 145 | crev_recursive_digest::get_recursive_digest_for_dir::, _>( 146 | &file_in_dir_path, 147 | &empty 148 | )?, 149 | expected 150 | ); 151 | 152 | Ok(()) 153 | } 154 | 155 | #[test] 156 | // Tests the inclusion and exclusing of paths. 157 | fn test_exclude_include_path() -> Result<(), DigestError> { 158 | let tmp_dir = TempDir::new("recursive-digest-test3")?; 159 | 160 | let foo_content = b"foo_content"; 161 | let file_in_dir_path = tmp_dir.path().join("foo"); 162 | let mut file_in_dir = fs::File::create(file_in_dir_path)?; 163 | file_in_dir.write_all(foo_content)?; 164 | 165 | let bar_content = b"bar_content"; 166 | let file_in_dir_path_2 = tmp_dir.path().join("bar"); 167 | let mut file_in_dir_2 = fs::File::create(file_in_dir_path_2)?; 168 | file_in_dir_2.write_all(bar_content)?; 169 | 170 | let expected = { 171 | let mut hasher = blake2::Blake2b::::new(); 172 | hasher.update(b"F"); 173 | hasher.update(bar_content); 174 | let file_sum = hasher.finalize().to_vec(); 175 | 176 | let mut hasher = blake2::Blake2b::::new(); 177 | hasher.update(b"bar"); 178 | let dir_sum = hasher.finalize().to_vec(); 179 | 180 | let mut hasher = blake2::Blake2b::::new(); 181 | hasher.update(b"D"); 182 | hasher.update(dir_sum); 183 | hasher.update(file_sum); 184 | hasher.finalize().to_vec() 185 | }; 186 | 187 | let mut excluded = HashSet::new(); 188 | excluded.insert(Path::new("foo").to_path_buf()); 189 | assert_eq!( 190 | crev_recursive_digest::get_recursive_digest_for_dir::, _>( 191 | tmp_dir.path(), 192 | &excluded 193 | )?, 194 | expected 195 | ); 196 | 197 | let mut included = HashSet::new(); 198 | included.insert(Path::new("bar").to_path_buf()); 199 | assert_eq!( 200 | crev_recursive_digest::get_recursive_digest_for_paths::, _>( 201 | tmp_dir.path(), 202 | included 203 | )?, 204 | expected 205 | ); 206 | 207 | Ok(()) 208 | } 209 | 210 | #[test] 211 | fn ignore_dir() -> Result<(), DigestError> { 212 | let tmp_dir = TempDir::new("recursive-digest-test-ignore-dir")?; 213 | 214 | let d1 = tmp_dir.path().join("d1"); 215 | let d2 = tmp_dir.path().join("d2"); 216 | 217 | fs::create_dir_all(d1.join("a/b1/c/d"))?; 218 | fs::create_dir_all(d1.join("a/b2/c/d"))?; 219 | fs::create_dir_all(&d2)?; 220 | 221 | let excluded_empty = HashSet::new(); 222 | let mut excluded_a = HashSet::new(); 223 | excluded_a.insert(PathBuf::from("a")); 224 | 225 | assert_eq!( 226 | crev_recursive_digest::get_recursive_digest_for_dir::, _>( 227 | &d1, 228 | &excluded_a 229 | )?, 230 | crev_recursive_digest::get_recursive_digest_for_dir::, _>( 231 | &d2, 232 | &excluded_empty 233 | )?, 234 | ); 235 | Ok(()) 236 | } 237 | --------------------------------------------------------------------------------