fix: fallback for fake cbr

This commit is contained in:
2026-03-12 14:17:21 +01:00
parent 4aafed3d31
commit 8d98056375
2 changed files with 38 additions and 2 deletions

View File

@@ -165,6 +165,13 @@ pub async fn scan_library_discovery(
continue; continue;
} }
// Skip macOS Apple Double resource fork files (._*)
let file_name_raw = entry.file_name().to_string_lossy();
if file_name_raw.starts_with("._") {
trace!("[SCAN] Skipping macOS resource fork: {}", path.display());
continue;
}
// Check if this file is under a skipped dir // Check if this file is under a skipped dir
let under_skipped = skipped_dir_prefixes let under_skipped = skipped_dir_prefixes
.iter() .iter()

View File

@@ -190,7 +190,25 @@ fn analyze_cbr(path: &Path) -> Result<(i32, Vec<u8>)> {
let mut image_names: Vec<String> = { let mut image_names: Vec<String> = {
let archive = unrar::Archive::new(path) let archive = unrar::Archive::new(path)
.open_for_listing() .open_for_listing()
.map_err(|e| anyhow::anyhow!("unrar listing failed for {}: {}", path.display(), e))?; .map_err(|e| anyhow::anyhow!("unrar listing failed for {}: {}", path.display(), e));
// Some .cbr files are actually ZIP archives with wrong extension — fallback to CBZ parser
let archive = match archive {
Ok(a) => a,
Err(e) => {
let e_str = e.to_string();
if e_str.contains("Not a RAR archive") || e_str.contains("bad archive") {
return analyze_cbz(path).map_err(|zip_err| {
anyhow::anyhow!(
"not a RAR archive and ZIP fallback also failed for {}: RAR={}, ZIP={}",
path.display(),
e_str,
zip_err
)
});
}
return Err(e);
}
};
let mut names = Vec::new(); let mut names = Vec::new();
for entry in archive { for entry in archive {
let entry = entry.map_err(|e| anyhow::anyhow!("unrar entry error: {}", e))?; let entry = entry.map_err(|e| anyhow::anyhow!("unrar entry error: {}", e))?;
@@ -297,7 +315,18 @@ fn parse_cbz_page_count(path: &Path) -> Result<i32> {
fn parse_cbr_page_count(path: &Path) -> Result<i32> { fn parse_cbr_page_count(path: &Path) -> Result<i32> {
let archive = unrar::Archive::new(path) let archive = unrar::Archive::new(path)
.open_for_listing() .open_for_listing()
.map_err(|e| anyhow::anyhow!("unrar listing failed for {}: {}", path.display(), e))?; .map_err(|e| anyhow::anyhow!("unrar listing failed for {}: {}", path.display(), e));
// Some .cbr files are actually ZIP archives with wrong extension — fallback to CBZ parser
let archive = match archive {
Ok(a) => a,
Err(e) => {
let e_str = e.to_string();
if e_str.contains("Not a RAR archive") || e_str.contains("bad archive") {
return parse_cbz_page_count(path);
}
return Err(e);
}
};
let count = archive let count = archive
.filter(|r| { .filter(|r| {
r.as_ref() r.as_ref()