mirror of
https://github.com/Belphemur/CBZOptimizer.git
synced 2026-07-22 03:15:41 +02:00
fix(converter): preserve OriginalName through conversion and fix race
- Fix critical bug: convertPageFile and splitAndConvert now copy OriginalName to the output PageFile so --keep-filenames works end-to-end on actually-converted pages. - Fix concurrency race: ExtractChapter deduplicates OriginalName when source archive has same base filename in different subdirectories. - Fix collision fallback: resolvePageName loops until an unused indexed name is found instead of single-shot assignment. - Fix gofmt indentation in optimize_command.go.
This commit is contained in:
@@ -42,9 +42,16 @@ func resolvePageName(page *manga.PageFile, usedNames map[string]struct{}) string
|
||||
}
|
||||
// Collision: fall back to the indexed form so the entry still gets
|
||||
// written, but make it visibly distinct from the preserved one.
|
||||
fallback := fmt.Sprintf("%s_%04d%s", stem, page.Index, page.Extension)
|
||||
usedNames[fallback] = struct{}{}
|
||||
return fallback
|
||||
// Loop in case the fallback name is itself already taken (e.g. a
|
||||
// source file literally named "cover_0001.png" colliding with a
|
||||
// page-index 1 fallback "cover_0001.webp").
|
||||
for suffix := page.Index; ; suffix++ {
|
||||
fallback := fmt.Sprintf("%s_%04d%s", stem, suffix, page.Extension)
|
||||
if _, taken := usedNames[fallback]; !taken {
|
||||
usedNames[fallback] = struct{}{}
|
||||
return fallback
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if page.IsSplitted {
|
||||
|
||||
Reference in New Issue
Block a user