fix: skip re-extraction if source directory already exists

When reusing a source image (Copy flow), the archive was already
extracted in /mnt/converter/in/. The extraction step failed with
'Destination path already exists' from 7z.

Now extract_if_needed checks if the expected output directory already
contains disk images, and returns it directly without re-extracting.
This commit is contained in:
Claus Lohmar 2026-07-23 09:28:02 +00:00
parent 111d0d1331
commit 7ded831354

View file

@ -6,6 +6,7 @@ Runs on the Proxmox host (srv2) where qemu-img, 7z, unzip, tar are available.
from __future__ import annotations from __future__ import annotations
import logging
import os import os
import re import re
import shutil import shutil
@ -17,6 +18,8 @@ from typing import Optional
STAGING_IN = Path("/mnt/converter/in") STAGING_IN = Path("/mnt/converter/in")
STAGING_OUT = Path("/mnt/converter/out") STAGING_OUT = Path("/mnt/converter/out")
logger = logging.getLogger("backend.converter")
DISK_EXTENSIONS = {".vmdk", ".qcow2", ".qcow", ".img", ".raw", ".vhd", ".vhdx"} DISK_EXTENSIONS = {".vmdk", ".qcow2", ".qcow", ".img", ".raw", ".vhd", ".vhdx"}
ARCHIVE_EXTENSIONS = {".7z", ".zip", ".rar", ".tar.gz", ".tgz", ".tar", ".gz", ".bz2", ".xz"} ARCHIVE_EXTENSIONS = {".7z", ".zip", ".rar", ".tar.gz", ".tgz", ".tar", ".gz", ".bz2", ".xz"}
@ -77,6 +80,16 @@ def extract_if_needed(filename: str) -> Path:
stem = stem[:-len(e)] stem = stem[:-len(e)]
break break
# If already extracted, skip re-extraction
expected_dir = STAGING_IN / stem
if expected_dir.is_dir() and any(
f.suffix.lower() in DISK_EXTENSIONS
for f in expected_dir.rglob("*")
if f.is_file()
):
logger.info("Already extracted: %s", expected_dir)
return expected_dir
# Snapshot STAGING_IN before extraction # Snapshot STAGING_IN before extraction
before = set(STAGING_IN.iterdir()) if STAGING_IN.exists() else set() before = set(STAGING_IN.iterdir()) if STAGING_IN.exists() else set()