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:
parent
d2510c72aa
commit
e531386095
@ -265,7 +265,7 @@ pub async fn update(
|
|||||||
// unrar failed to extract rar file (e.g. archive has unicode filenames)
|
// unrar failed to extract rar file (e.g. archive has unicode filenames)
|
||||||
// Attempt to uncompress the archive using `7z` unix command instead
|
// 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");
|
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)
|
// 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
|
// 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");
|
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 {
|
} else {
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,10 @@ use anyhow::Result;
|
|||||||
use std::io::{Seek, SeekFrom};
|
use std::io::{Seek, SeekFrom};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
use tracing::{info, info_span};
|
use tracing::{info, info_span, warn};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
use crate::models::file::File;
|
use crate::models::{file, file::File};
|
||||||
use crate::models::game_mod::Mod;
|
use crate::models::game_mod::Mod;
|
||||||
use crate::plugin_processor::process_plugin;
|
use crate::plugin_processor::process_plugin;
|
||||||
|
|
||||||
@ -15,6 +15,7 @@ pub async fn extract_with_7zip(
|
|||||||
db_file: &File,
|
db_file: &File,
|
||||||
db_mod: &Mod,
|
db_mod: &Mod,
|
||||||
game_name: &str,
|
game_name: &str,
|
||||||
|
checked_metadata: bool,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
file.seek(SeekFrom::Start(0))?;
|
file.seek(SeekFrom::Start(0))?;
|
||||||
let temp_dir = tempdir()?;
|
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
|
drop(temp_file); // close handle to temp file so 7zip process can open it
|
||||||
let extracted_path = temp_dir.path().join("extracted");
|
let extracted_path = temp_dir.path().join("extracted");
|
||||||
|
|
||||||
Command::new("7z")
|
let status = Command::new("7z")
|
||||||
.args(&[
|
.args(&[
|
||||||
"x",
|
"x",
|
||||||
&format!("-o{}", &extracted_path.to_string_lossy()),
|
&format!("-o{}", &extracted_path.to_string_lossy()),
|
||||||
@ -32,6 +33,12 @@ pub async fn extract_with_7zip(
|
|||||||
])
|
])
|
||||||
.status()?;
|
.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)
|
for entry in WalkDir::new(&extracted_path)
|
||||||
.contents_first(true)
|
.contents_first(true)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
Loading…
Reference in New Issue
Block a user