{"record":{"id":"48053d1860c3d909","repo":"run-llama/liteparse","slug":"failed-to-move-pdfium-to-cache-dir","errorCode":null,"errorMessage":"failed to move pdfium to cache dir","messagePattern":"failed to move pdfium to cache dir","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pdfium-sys/build.rs","lineNumber":197,"sourceCode":"\n    // Extract to a temp dir first, then rename atomically\n    let tmp = dest.with_extension(\"tmp\");\n    if tmp.exists() {\n        fs::remove_dir_all(&tmp).ok();\n    }\n    fs::create_dir_all(&tmp).expect(\"failed to create temp dir\");\n    archive\n        .unpack(&tmp)\n        .expect(\"failed to extract pdfium archive\");\n\n    // Fix dylib install name on macOS so @rpath resolution works\n    fix_dylib_install_name(&tmp);\n\n    // Atomic rename into place\n    if dest.exists() {\n        fs::remove_dir_all(dest).ok();\n    }\n    fs::rename(&tmp, dest).expect(\"failed to move pdfium to cache dir\");\n\n    eprintln!(\"pdfium-sys: cached pdfium at {}\", dest.display());\n}\n\n/// On macOS, pdfium-binaries ships dylibs with install name `./libpdfium.dylib`.\n/// We need `@rpath/libpdfium.dylib` for rpath resolution to work.\nfn fix_dylib_install_name(dir: &Path) {\n    let target_os = env::var(\"CARGO_CFG_TARGET_OS\").unwrap_or_default();\n    if target_os != \"macos\" {\n        return;\n    }\n\n    let dylib = dir.join(\"lib/libpdfium.dylib\");\n    if !dylib.exists() {\n        return;\n    }\n\n    let status = Command::new(\"install_name_tool\")","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/run-llama/liteparse/blob/22d2dd8cd7f7b9320102b57ddaf0e663ff7d15a8/crates/pdfium-sys/build.rs#L179-L215","documentation":"After a successful extraction, download_pdfium atomically renames the .tmp directory into its final cache location with fs::rename, panicking with this message if the rename fails. fs::rename fails across filesystem boundaries (EXDEV) or when the destination exists as something rename cannot replace (e.g. a file, or a directory that couldn't be removed).","triggerScenarios":"Running `cargo build` where the pdfium cache dest path exists as a file (or a directory that fs::remove_dir_all silently failed to delete), or where dest and tmp end up on different mount points/filesystems (e.g. cache dir is a symlink into another mount).","commonSituations":"Cache dirs symlinked to another volume/mount; concurrent builds racing on the same cache path where one build removes dest while another renames; permissions preventing removal of the existing dest; corrupted cache containing a file named like the expected directory.","solutions":["Remove the conflicting path in the cache dir (the dest location) and rebuild.","Avoid concurrent cargo builds sharing the same cache on first download; run one build first or pre-populate the cache.","Ensure the cache dir is not a cross-filesystem symlink/mount that breaks atomic rename.","Check permissions so remove_dir_all(dest) can actually clear an existing stale entry."],"exampleFix":"# before: cache dest is a stale file on a mounted volume\n$ cargo build\n   ... panicked: failed to move pdfium to cache dir\n\n# after: clear the conflicting cache entry and retry serially\n$ rm -rf ~/.cache/liteparse/pdfium*\n$ cargo build  # single build, no parallel races","handlingStrategy":"validation","validationCode":"# Preflight: cache dest must not be a cross-device symlink and must be clearable\nCACHE=\"$HOME/.cache/liteparse\"\n[ ! -L \"$CACHE\" ] || { echo \"cache is a symlink to another fs\"; exit 1; }\n[ ! -e \"$CACHE/pdfium\" ] || [ -d \"$CACHE/pdfium\" ] || { echo \"stale file at cache dest\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the pdfium cache on the same filesystem as its parent dir (avoid cross-device symlinks)","Don't run multiple first-time builds concurrently against a shared cache","Pre-populate the cache once, then share it read-only","Clean stale cache entries rather than leaving partial dirs"],"tags":["build-script","filesystem","rename","cache","pdfium"],"backgroundTag":"file-write-failed","analyzedSha":"22d2dd8cd7f7b9320102b57ddaf0e663ff7d15a8","analyzedAt":"2026-09-08T06:09:49.009Z","contentChangedAt":"2026-09-08T06:09:49.009Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}