run-llama/liteparse · error

failed to create temp dir

Error message

failed to create temp dir

What it means

download_pdfium extracts the downloaded pdfium archive into a temporary sibling directory (<dest>.tmp) before atomically renaming it into the cache. fs::create_dir_all(&tmp).expect(...) panics with this message if the temp directory cannot be created — typically a filesystem or permissions failure at the cache location. The build script has no graceful failure path here, so the whole build aborts.

Solutions

  1. Ensure the cache parent directory (from dirs_cache: ~/.cache, ~/Library/Caches, or %LOCALAPPDATA%) exists and is writable by the build user.
  2. Delete any stale <cache>/pdfium-<ver>.tmp path that may be a file or corrupted directory, then rebuild.
  3. Check free disk space and clean the build/cache directories.
  4. Point the cache to a writable location (set HOME to a writable dir, per the related HOME errors).

Example fix

# before: failing build with unwritable cache
$ cargo build
   ... panicked: failed to create temp dir

# after: clear stale tmp and fix permissions
$ rm -rf ~/.cache/liteparse/pdfium*.tmp
$ chmod u+w ~/.cache && cargo build
Defensive patterns

Strategy: validation

Validate before calling

# Preflight: ensure pdfium cache dir is writable
CACHE="$HOME/.cache/liteparse"
mkdir -p "$CACHE" && [ -w "$CACHE" ] || { echo "cache dir not writable: $CACHE"; exit 1; }
rm -rf "$CACHE"/pdfium*.tmp

Prevention

When it happens

Trigger: Running `cargo build` where pdfium-sys must download pdfium and the parent cache directory is not writable or does not exist and cannot be created — e.g. HOME points to a read-only path, disk full, or the leftover .tmp path exists as a file instead of a directory.

Common situations: Read-only Docker build layers or read-only caches; sandboxes/SELinux blocking writes to the home cache dir; full disks on CI machines; a corrupted cache where pdfium.tmp exists as a regular file that remove_dir_all couldn't clean up.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of run-llama/liteparse@22d2dd8cd7 (2026-09-08). Data as JSON: /api/errors/b58472d7b46265ae. Report an issue: GitHub.

Appendix: source

Thrown at crates/pdfium-sys/build.rs:185

    let tag_encoded = PDFIUM_RELEASE_TAG.replace('/', "%2F");
    let url = format!("{PDFIUM_RELEASE_URL}/{tag_encoded}/{asset}");

    eprintln!("pdfium-sys: GET {url}");

    let response = ureq::get(&url).call().unwrap_or_else(|e| {
        panic!("failed to download pdfium from {url}: {e}");
    });

    let reader = response.into_body().into_reader();
    let gz = flate2::read::GzDecoder::new(reader);
    let mut archive = tar::Archive::new(gz);

    // Extract to a temp dir first, then rename atomically
    let tmp = dest.with_extension("tmp");
    if tmp.exists() {
        fs::remove_dir_all(&tmp).ok();
    }
    fs::create_dir_all(&tmp).expect("failed to create temp dir");
    archive
        .unpack(&tmp)
        .expect("failed to extract pdfium archive");

    // Fix dylib install name on macOS so @rpath resolution works
    fix_dylib_install_name(&tmp);

    // Atomic rename into place
    if dest.exists() {
        fs::remove_dir_all(dest).ok();
    }
    fs::rename(&tmp, dest).expect("failed to move pdfium to cache dir");

    eprintln!("pdfium-sys: cached pdfium at {}", dest.display());
}

/// On macOS, pdfium-binaries ships dylibs with install name `./libpdfium.dylib`.
/// We need `@rpath/libpdfium.dylib` for rpath resolution to work.

View on GitHub (pinned to 22d2dd8cd7)