{"record":{"id":"6345da862d27481a","repo":"ungoogled-software/ungoogled-chromium","slug":"temporary-unpacking-directory-already-exists-s","errorCode":null,"errorMessage":"Temporary unpacking directory already exists: %s","messagePattern":"Temporary unpacking directory already exists: (.+?)","errorType":"exception","errorClass":"FileExistsError","httpStatus":null,"severity":"error","filePath":"utils/_extraction.py","lineNumber":95,"sourceCode":"    if relative_to is None:\n        return\n    relative_root = unpack_root / relative_to\n    if not relative_root.is_dir():\n        get_logger().error('Could not find relative_to directory in extracted files: %s',\n                           relative_to)\n        raise FileNotFoundError()\n    for src_path in relative_root.iterdir():\n        dest_path = unpack_root / src_path.name\n        src_path.rename(dest_path)\n    relative_root.rmdir()\n\n\ndef _extract_tar_with_7z(binary, archive_path, output_dir, relative_to):\n    get_logger().debug('Using 7-zip extractor')\n    if not relative_to is None and (output_dir / relative_to).exists():\n        get_logger().error('Temporary unpacking directory already exists: %s',\n                           output_dir / relative_to)\n        raise FileExistsError()\n    cmd1 = (binary, 'x', str(archive_path), '-so')\n    cmd2 = (binary, 'x', '-si', '-snld', '-aoa', '-ttar', f'-o{str(output_dir)}')\n    get_logger().debug('7z command line: %s | %s', ' '.join(cmd1), ' '.join(cmd2))\n\n    proc1 = subprocess.Popen(cmd1, stdout=subprocess.PIPE) #pylint: disable=consider-using-with\n    proc2 = subprocess.Popen(cmd2, stdin=proc1.stdout, stdout=subprocess.PIPE) #pylint: disable=consider-using-with\n    proc1.stdout.close()\n    (stdout_data, stderr_data) = proc2.communicate()\n    if proc2.returncode != 0:\n        get_logger().error('7z commands returned non-zero status: %s', proc2.returncode)\n        get_logger().debug('stdout: %s', stdout_data)\n        get_logger().debug('stderr: %s', stderr_data)\n        raise ChildProcessError()\n\n    _process_relative_to(output_dir, relative_to)\n\n\ndef _extract_tar_with_tar(binary, archive_path, output_dir, relative_to):","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/ungoogled-software/ungoogled-chromium/blob/f85e84a480e2e17c103de7013de94320f9a2ba39/utils/_extraction.py#L77-L113","documentation":"_extract_tar_with_7z checks before extracting whether output_dir/relative_to already exists; if it does, the two-pass 7z streaming extraction would collide with leftover files, so it raises FileExistsError. This is a pre-flight sanity check to avoid merging old and new extraction output.","triggerScenarios":"Calling extract_tar_file (which dispatches to the 7z extractor) twice with the same output_dir and non-None relative_to without cleaning up, or a previous failed run left output_dir/relative_to behind.","commonSituations":"Retrying extraction after a crashed run left a stale unpack directory, reusing a cache/temp directory across runs, or two concurrent extractions targeting the same output_dir.","solutions":["Delete output_dir (or output_dir/relative_to) before re-extracting","Use a fresh temporary directory for each extraction (tempfile.TemporaryDirectory)","Skip the relative_to argument if you extract into an empty dedicated dir","Handle the FileExistsError and clean up in a retry path"],"exampleFix":"// before\nextract_tar_file('data.tar.xz', out_dir, relative_to='payload')  # 2nd call fails\n// after\nimport shutil\nif (out_dir / 'payload').exists():\n    shutil.rmtree(out_dir)\nextract_tar_file('data.tar.xz', out_dir, relative_to='payload')","handlingStrategy":"validation","validationCode":"import shutil\nfrom pathlib import Path\ntarget = Path(output_dir) / relative_to\nif relative_to is not None and target.exists():\n    shutil.rmtree(target)","typeGuard":null,"tryCatchPattern":"try:\n    extract_tar_file(archive, out, relative_to=rel)\nexcept FileExistsError:\n    shutil.rmtree(out, ignore_errors=True)\n    extract_tar_file(archive, out, relative_to=rel)","preventionTips":["Always extract into a fresh temp dir (tempfile.TemporaryDirectory)","Clean up output_dir in a finally block or on failure","Avoid reusing the same output_dir across runs without cleanup","Do not run extractions concurrently into the same output_dir"],"tags":["filesystem","archive-extraction","directory-conflict"],"backgroundTag":"output-directory-already-exists","analyzedSha":"f85e84a480e2e17c103de7013de94320f9a2ba39","analyzedAt":"2026-08-29T10:07:17.606Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}