Commit b3f8b0b7 authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

fix

parent 99719658
Loading
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -140,18 +140,29 @@ def refresh_docx_fields(input_path: str, image: str = "docx-field-refresh") -> s
        temp_input = tmpdir_path / input_path.name
        shutil.copy2(input_path, temp_input)

        # Create a temporary home directory for LibreOffice to prevent creating files in /root
        lo_home = tmpdir_path / "lo_home"
        lo_home.mkdir(mode=0o755, exist_ok=True)

        # Run LibreOffice container on this specific file
        # Get the relative path of the copied file within the temp directory
        file_path_in_container = f"/data/{temp_input.relative_to(tmpdir_path)}"
        
        cmd = [
            "docker", "run", "--rm",
            "-v", f"{tmpdir_path}:/data",
            "-v", f"{lo_home}:/tmp/lo_home",  # Mount temp home directory
            "-u", f"{os.getuid()}:{os.getgid()}",  # <--- run as host user
            "-e", "HOME=/tmp",  # 👈 Tell LibreOffice to use /tmp for its profile
            "-e", "HOME=/tmp/lo_home",  # Tell LibreOffice to use temp directory for its profile
            image,
            "--headless",
            "--nodefault",
            "--norestore",  # Don't restore previous session
            "--nolockcheck",  # Don't check for file locks
            "--convert-to", "docx",
            "--infilter=writer8",
            "--outdir", "/data",
            f"/data/{input_path}",
            file_path_in_container,  # Use the path relative to /data in container
        ]

        print(f"Running command:\n{' '.join(cmd)}\n")