Zeta: Skip opening files redundantly if a license was found (#24357)
Release Notes: - N/A
This commit is contained in:
parent
1cdfbe2d5f
commit
c61f12dd22
1 changed files with 21 additions and 11 deletions
|
@ -957,21 +957,31 @@ impl LicenseDetectionWatcher {
|
||||||
let task = if worktree.abs_path().is_file() {
|
let task = if worktree.abs_path().is_file() {
|
||||||
Task::ready(())
|
Task::ready(())
|
||||||
} else {
|
} else {
|
||||||
let loaded_files_task = futures::future::join_all(
|
let loaded_files = LICENSE_FILES_TO_CHECK
|
||||||
LICENSE_FILES_TO_CHECK
|
.iter()
|
||||||
.iter()
|
.map(Path::new)
|
||||||
.map(|file| worktree.load_file(Path::new(file), cx)),
|
.map(|file| worktree.load_file(file, cx))
|
||||||
);
|
.collect::<ArrayVec<_, { LICENSE_FILES_TO_CHECK.len() }>>();
|
||||||
|
|
||||||
cx.background_executor().spawn(async move {
|
cx.background_executor().spawn(async move {
|
||||||
for loaded_file in loaded_files_task.await {
|
for loaded_file in loaded_files.into_iter() {
|
||||||
if let Some(content) = loaded_file.log_err() {
|
let Ok(loaded_file) = loaded_file.await else {
|
||||||
if is_license_eligible_for_data_collection(&content.text) {
|
continue;
|
||||||
*is_open_source_tx.borrow_mut() = true;
|
};
|
||||||
break;
|
|
||||||
}
|
let path = &loaded_file.file.path;
|
||||||
|
if is_license_eligible_for_data_collection(&loaded_file.text) {
|
||||||
|
log::info!("detected '{path:?}' as open source license");
|
||||||
|
*is_open_source_tx.borrow_mut() = true;
|
||||||
|
} else {
|
||||||
|
log::info!("didn't detect '{path:?}' as open source license");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stop on the first license that successfully read
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log::debug!("didn't find a license file to check, assuming closed source");
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue