Detect failed extract with 7zip

And skip the file if the metadata on the server is also missing (high probability that the archive is just corrupt if this is the case).
This commit is contained in:
Tyler Hallada 2022-09-04 17:39:05 -04:00
parent d2510c72aa
commit e531386095
2 changed files with 12 additions and 5 deletions

View File

@ -265,7 +265,7 @@ pub async fn update(
// unrar failed to extract rar file (e.g. archive has unicode filenames)
// Attempt to uncompress the archive using `7z` unix command instead
warn!(error = %err, "failed to extract file with unrar, extracting whole archive with 7z instead");
extract_with_7zip(&mut file, &pool, &db_file, &db_mod, game_name).await
extract_with_7zip(&mut file, &pool, &db_file, &db_mod, game_name, checked_metadata).await
}
}?;
}
@ -288,7 +288,7 @@ pub async fn update(
// compress_tools or libarchive failed to extract zip/7z file (e.g. archive is deflate64 compressed)
// Attempt to uncompress the archive using `7z` unix command instead
warn!(error = %err, "failed to extract file with compress_tools, extracting whole archive with 7z instead");
extract_with_7zip(&mut file, &pool, &db_file, &db_mod, game_name).await
extract_with_7zip(&mut file, &pool, &db_file, &db_mod, game_name, checked_metadata).await
} else {
Err(err)
}

View File

@ -2,10 +2,10 @@ use anyhow::Result;
use std::io::{Seek, SeekFrom};
use std::process::Command;
use tempfile::tempdir;
use tracing::{info, info_span};
use tracing::{info, info_span, warn};
use walkdir::WalkDir;
use crate::models::file::File;
use crate::models::{file, file::File};
use crate::models::game_mod::Mod;
use crate::plugin_processor::process_plugin;
@ -15,6 +15,7 @@ pub async fn extract_with_7zip(
db_file: &File,
db_mod: &Mod,
game_name: &str,
checked_metadata: bool,
) -> Result<()> {
file.seek(SeekFrom::Start(0))?;
let temp_dir = tempdir()?;
@ -24,7 +25,7 @@ pub async fn extract_with_7zip(
drop(temp_file); // close handle to temp file so 7zip process can open it
let extracted_path = temp_dir.path().join("extracted");
Command::new("7z")
let status = Command::new("7z")
.args(&[
"x",
&format!("-o{}", &extracted_path.to_string_lossy()),
@ -32,6 +33,12 @@ pub async fn extract_with_7zip(
])
.status()?;
if !status.success() && !checked_metadata {
warn!("failed to extract archive and server has no metadata, skipping file");
file::update_unable_to_extract_plugins(&pool, db_file.id, true).await?;
return Ok(());
}
for entry in WalkDir::new(&extracted_path)
.contents_first(true)
.into_iter()