backup per defecte
covertir arregla extensions incorrectes
This commit is contained in:
+31
-7
@@ -7,6 +7,7 @@ import shutil
|
||||
import rarfile
|
||||
|
||||
from core.archive import detect_real_format, extract_archive, repack_as_cbz, ArchiveError, list_archive_names
|
||||
from core.backup import move_to_backup
|
||||
from core.collision import CollisionPolicy, resolve_collision
|
||||
from core.result import ComicResult, StepResult
|
||||
from processors.validator import validate_archive
|
||||
@@ -69,12 +70,16 @@ class Pipeline:
|
||||
|
||||
return {}
|
||||
|
||||
def _needs_extraction(self, step_results: list, real_format: str) -> bool:
|
||||
def _needs_extraction(self, step_results: list, real_format: str, path: str) -> bool:
|
||||
for step in self.steps:
|
||||
if step in ("normalize_pages", "normalize_images", "convert_images"):
|
||||
return True
|
||||
if step == "convert" and needs_conversion(real_format, self.desired_format):
|
||||
return True
|
||||
if step == "convert":
|
||||
if needs_conversion(real_format, self.desired_format):
|
||||
return True
|
||||
ext = os.path.splitext(path)[1].lower().lstrip(".")
|
||||
if ext != self.desired_format:
|
||||
return True
|
||||
if step == "clean":
|
||||
trash = next((r for r in step_results if r.step == "check_trash"), None)
|
||||
if trash and trash.warnings:
|
||||
@@ -108,7 +113,7 @@ class Pipeline:
|
||||
]
|
||||
|
||||
# 4. Pre-flight: si ningún step necesita extracción, salir sin tocar el archivo
|
||||
if not self._needs_extraction(step_results, real_format):
|
||||
if not self._needs_extraction(step_results, real_format, path):
|
||||
return ComicResult(original_path=path, final_path=path, steps=step_results)
|
||||
|
||||
# 5. Extraer una sola vez
|
||||
@@ -167,6 +172,18 @@ class Pipeline:
|
||||
preview = self._compute_preview("convert", temp_dir, step_results)
|
||||
if confirm_fn is None or confirm_fn("convert", preview):
|
||||
conv_result = conversion_step_result(real_format, self.desired_format)
|
||||
# Extensión incorrecta aunque el formato real ya sea correcto
|
||||
file_ext = os.path.splitext(path)[1].lower().lstrip(".")
|
||||
if (
|
||||
not conv_result.errors
|
||||
and not conv_result.changed
|
||||
and file_ext != self.desired_format
|
||||
):
|
||||
conv_result = StepResult(
|
||||
step="convert",
|
||||
changed=True,
|
||||
details=[f"Extensión incorrecta corregida: .{file_ext} → .{self.desired_format}"],
|
||||
)
|
||||
step_results.append(conv_result)
|
||||
if conv_result.errors:
|
||||
return ComicResult(
|
||||
@@ -176,9 +193,13 @@ class Pipeline:
|
||||
any_changed = True
|
||||
|
||||
# 7. Reempaquetar si hubo cambios o conversión de formato
|
||||
ext = os.path.splitext(path)[1].lower().lstrip(".")
|
||||
needs_repack = any_changed or (
|
||||
"convert" in self.steps
|
||||
and needs_conversion(real_format, self.desired_format)
|
||||
and (
|
||||
needs_conversion(real_format, self.desired_format)
|
||||
or ext != self.desired_format
|
||||
)
|
||||
)
|
||||
|
||||
if not needs_repack:
|
||||
@@ -192,9 +213,12 @@ class Pipeline:
|
||||
if not self.dry_run:
|
||||
safe_target = resolve_collision(target_path, self.collision_policy)
|
||||
repack_as_cbz(temp_dir, safe_target)
|
||||
# Eliminar original si el nombre cambió
|
||||
# Eliminar o mover a backup el original si el nombre cambió
|
||||
if safe_target != path and os.path.exists(path):
|
||||
os.remove(path)
|
||||
if self.collision_policy == CollisionPolicy.BACKUP:
|
||||
move_to_backup(path)
|
||||
else:
|
||||
os.remove(path)
|
||||
else:
|
||||
safe_target = target_path
|
||||
|
||||
|
||||
Reference in New Issue
Block a user