@@ -158,6 +158,15 @@ struct PackFile {
158158 data : PackFileData ,
159159}
160160
161+ enum MismatchReason < ' a > {
162+ /// The specified file was not found when gathering license files
163+ FileNotFound ,
164+ /// Encountered an I/O error trying to read the file contents
165+ Error ( & ' a std:: io:: Error ) ,
166+ /// The hash of the license file doesn't match the expected hash
167+ HashDiffers ,
168+ }
169+
161170struct LicensePack {
162171 license_files : Vec < PackFile > ,
163172 err : Option < std:: io:: Error > ,
@@ -199,29 +208,26 @@ impl LicensePack {
199208 }
200209 }
201210
202- fn matches ( & self , hashes : & [ FileSource ] ) -> bool {
203- if self . license_files . len ( ) != hashes. len ( ) {
204- return false ;
205- }
206-
207- for ( expected, actual) in self . license_files . iter ( ) . zip ( hashes. iter ( ) ) {
208- if !expected. path . ends_with ( & actual. path ) {
209- return false ;
210- }
211-
212- match & expected. data {
213- PackFileData :: Bad ( _) => {
214- return false ;
215- }
216- PackFileData :: Good ( lf) => {
217- if lf. hash != actual. hash {
218- return false ;
211+ fn license_files_match ( & self , expected : & FileSource ) -> Result < ( ) , MismatchReason < ' _ > > {
212+ let err = match self
213+ . license_files
214+ . iter ( )
215+ . find ( |lf| lf. path . ends_with ( & expected. path . value ) )
216+ {
217+ Some ( lf) => match & lf. data {
218+ PackFileData :: Bad ( e) => MismatchReason :: Error ( e) ,
219+ PackFileData :: Good ( file_data) => {
220+ if file_data. hash != expected. hash {
221+ MismatchReason :: HashDiffers
222+ } else {
223+ return Ok ( ( ) ) ;
219224 }
220225 }
221- }
222- }
226+ } ,
227+ None => MismatchReason :: FileNotFound ,
228+ } ;
223229
224- true
230+ Err ( err )
225231 }
226232
227233 fn get_expression (
@@ -591,14 +597,27 @@ impl Gatherer {
591597 }
592598 } ;
593599
594- // pub name: String,
595- // pub version: VersionReq,
596- // pub expression: spdx::Expression,
597- // pub license_files: Vec<FileSource>,
598600 // Check to see if the clarification provided exactly matches
599601 // the set of detected licenses, if they do, we use the clarification's
600- // license expression as the license requirement's for this crate
601- if lp. matches ( & clarification. license_files ) {
602+ // license expression as the license requirements for this crate
603+ if clarification. license_files . iter ( ) . all ( |clf| {
604+ match lp. license_files_match ( & clf) {
605+ Ok ( _) => true ,
606+ Err ( reason) => {
607+ if let MismatchReason :: FileNotFound = reason {
608+ labels. push (
609+ super :: diags:: MissingClarificationFile {
610+ expected : & clf. path ,
611+ cfg_file_id : cfg. file_id ,
612+ }
613+ . into ( ) ,
614+ ) ;
615+ }
616+
617+ false
618+ }
619+ }
620+ } ) {
602621 return KrateLicense {
603622 krate,
604623 lic_info : LicenseInfo :: SPDXExpression {
0 commit comments