mirror of
https://github.com/modrinth/code.git
synced 2026-09-04 05:48:57 +00:00
fix: file scan fix v2 (#6504)
* fix: file attribution scanning not marking completed files * prepare * Handle file scan failures gracefully with tracking * conditional * add more logging * remove leftover files
This commit is contained in:
@@ -147,20 +147,28 @@ async fn scan_pending_files_batch(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut scanned_count = 0;
|
let mut scanned_count = 0;
|
||||||
let mut first_err = None;
|
let mut errors = Vec::new();
|
||||||
for task in tasks {
|
for task in tasks {
|
||||||
match task.await.wrap_err("joining file scan task")? {
|
match task.await.wrap_err("joining file scan task")? {
|
||||||
Ok(count) => scanned_count += count,
|
Ok(count) => scanned_count += count,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if first_err.is_none() {
|
errors.push(err);
|
||||||
first_err = Some(err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(err) = first_err {
|
if !errors.is_empty() {
|
||||||
return Err(err).wrap_err("scanning pending file chunk");
|
let error_count = errors.len();
|
||||||
|
let error_messages = errors
|
||||||
|
.into_iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(index, err)| format!("chunk {}: {err:?}", index + 1))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("\n\n");
|
||||||
|
|
||||||
|
return Err(eyre!(
|
||||||
|
"failed to scan {error_count} pending file chunks:\n\n{error_messages}"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if fetched_count > 0 && scanned_count == 0 {
|
if fetched_count > 0 && scanned_count == 0 {
|
||||||
@@ -235,6 +243,7 @@ async fn scan_pending_files_chunk(
|
|||||||
txn.commit()
|
txn.commit()
|
||||||
.await
|
.await
|
||||||
.wrap_err("committing file scan transaction")?;
|
.wrap_err("committing file scan transaction")?;
|
||||||
|
log_marked_override_projects(&resolved);
|
||||||
|
|
||||||
eyre::Ok(())
|
eyre::Ok(())
|
||||||
}
|
}
|
||||||
@@ -309,6 +318,7 @@ async fn scan_file_inner(
|
|||||||
.wrap_err_with(|| {
|
.wrap_err_with(|| {
|
||||||
eyre!("persisting attribution results for file {file_id:?}")
|
eyre!("persisting attribution results for file {file_id:?}")
|
||||||
})?;
|
})?;
|
||||||
|
log_marked_override_projects(&resolved);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -432,6 +442,33 @@ pub enum OverrideResolution {
|
|||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn log_marked_override_projects(
|
||||||
|
resolved: &HashMap<String, OverrideResolution>,
|
||||||
|
) {
|
||||||
|
let mut projects = resolved
|
||||||
|
.values()
|
||||||
|
.filter_map(|resolution| match resolution {
|
||||||
|
OverrideResolution::ExternalLicense {
|
||||||
|
flame_project: Some(flame_project),
|
||||||
|
..
|
||||||
|
}
|
||||||
|
| OverrideResolution::Flame(flame_project) => {
|
||||||
|
Some(format!("{} ({})", flame_project.title, flame_project.id))
|
||||||
|
}
|
||||||
|
OverrideResolution::OnModrinth
|
||||||
|
| OverrideResolution::ExternalLicense { .. }
|
||||||
|
| OverrideResolution::Unknown => None,
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
projects.sort();
|
||||||
|
projects.dedup();
|
||||||
|
|
||||||
|
if !projects.is_empty() {
|
||||||
|
info!(override_projects = ?projects, "Marked projects as overrides");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const OVERRIDE_PREFIXES: &[&str] = &[
|
const OVERRIDE_PREFIXES: &[&str] = &[
|
||||||
"overrides/mods",
|
"overrides/mods",
|
||||||
"client-overrides/mods",
|
"client-overrides/mods",
|
||||||
@@ -442,6 +479,23 @@ const OVERRIDE_PREFIXES: &[&str] = &[
|
|||||||
"client-overrides/resourcepacks",
|
"client-overrides/resourcepacks",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
fn should_scan(name: &str) -> bool {
|
||||||
|
let should_skip = name.starts_with("mods/.connector/")
|
||||||
|
|| name.starts_with(".sable/natives/")
|
||||||
|
|| name.starts_with("local/crash_assistant/")
|
||||||
|
|| name.starts_with("mods/mcef-libraries/")
|
||||||
|
|| name.starts_with("mods/mcef-cache/")
|
||||||
|
|| name.starts_with("config/super_resolution/libraries/")
|
||||||
|
|| name.starts_with("config/Veinminer/update/")
|
||||||
|
|| name.starts_with("config/epicfight/native/")
|
||||||
|
|| name.starts_with("essential/")
|
||||||
|
|| name.ends_with(".rpo")
|
||||||
|
|| name.ends_with(".txt");
|
||||||
|
let is_archive = name.contains(".jar") || name.contains(".zip");
|
||||||
|
|
||||||
|
is_archive && !should_skip
|
||||||
|
}
|
||||||
|
|
||||||
fn extract_override_files(data: &[u8]) -> Result<Vec<OverrideFile>> {
|
fn extract_override_files(data: &[u8]) -> Result<Vec<OverrideFile>> {
|
||||||
let reader = Cursor::new(data);
|
let reader = Cursor::new(data);
|
||||||
let mut zip =
|
let mut zip =
|
||||||
@@ -466,19 +520,7 @@ fn extract_override_files(data: &[u8]) -> Result<Vec<OverrideFile>> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let should_skip = name.starts_with("mods/.connector/")
|
if !should_scan(&name) {
|
||||||
|| name.starts_with(".sable/natives/")
|
|
||||||
|| name.starts_with("local/crash_assistant/")
|
|
||||||
|| name.starts_with("mods/mcef-libraries/")
|
|
||||||
|| name.starts_with("mods/mcef-cache/")
|
|
||||||
|| name.starts_with("config/super_resolution/libraries/")
|
|
||||||
|| name.starts_with("config/Veinminer/update/")
|
|
||||||
|| name.starts_with("config/epicfight/native/")
|
|
||||||
|| name.starts_with("essential/")
|
|
||||||
|| name.ends_with(".rpo")
|
|
||||||
|| name.ends_with(".txt");
|
|
||||||
let should_scan = name.contains(".jar") || name.contains(".zip");
|
|
||||||
if should_scan && !should_skip {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user