diff --git a/crates/edit_prediction/src/license_detection.rs b/crates/edit_prediction/src/license_detection.rs index 6f701d13a9d4d915bbfbc2442ea5643afac30ef4..55635bcfd04cb6288f44907da051fa1f33d41922 100644 --- a/crates/edit_prediction/src/license_detection.rs +++ b/crates/edit_prediction/src/license_detection.rs @@ -21,14 +21,23 @@ use worktree::ChildEntriesOptions; static LICENSE_FILE_NAME_REGEX: LazyLock = LazyLock::new(|| { regex::bytes::RegexBuilder::new( "^ \ - (?: license | licence)? \ - (?: [\\-._]? \ + (?: \ + (?: license | licence) \ + (?: [\\-._]? \ + (?: apache (?: [\\-._] (?: 2.0 | 2 ))? | \ + 0? bsd (?: [\\-._] [0123])? (?: [\\-._] clause)? | \ + isc | \ + mit | \ + upl | \ + zlib))? \ + | \ (?: apache (?: [\\-._] (?: 2.0 | 2 ))? | \ 0? bsd (?: [\\-._] [0123])? (?: [\\-._] clause)? | \ isc | \ mit | \ upl | \ - zlib))? \ + zlib) \ + ) \ (?: [\\-._]? (?: license | licence))? \ (?: \\.txt | \\.md)? \ $", @@ -350,6 +359,9 @@ impl LicenseDetectionWatcher { return None; }; let metadata = fs.metadata(&abs_path).await.log_err()??; + if metadata.is_dir { + return None; + } if metadata.len > LICENSE_PATTERNS.approximate_max_length as u64 { log::debug!( "`{abs_path:?}` license file was skipped \ @@ -697,6 +709,7 @@ mod tests { assert!(LICENSE_FILE_NAME_REGEX.is_match(b"licence-upl.txt")); // Test non-matching patterns + assert!(!LICENSE_FILE_NAME_REGEX.is_match(b"")); assert!(!LICENSE_FILE_NAME_REGEX.is_match(b"COPYING")); assert!(!LICENSE_FILE_NAME_REGEX.is_match(b"LICENSE.html")); assert!(!LICENSE_FILE_NAME_REGEX.is_match(b"MYLICENSE"));