{"record":{"id":"d2697972f2b17055","repo":"quickwit-oss/tantivy","slug":"invalidinput-d26979","errorCode":"InvalidInput","errorMessage":"Path {:?} does not have parent directory.","messagePattern":"Path (.+?) does not have parent directory\\.","errorType":"error_code","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src/directory/mmap_directory/mod.rs","lineNumber":367,"sourceCode":"#[derive(Clone)]\nstruct MmapArc(Arc<dyn Deref<Target = [u8]> + Send + Sync>);\n\nimpl Deref for MmapArc {\n    type Target = [u8];\n\n    fn deref(&self) -> &[u8] {\n        self.0.deref()\n    }\n}\nunsafe impl StableDeref for MmapArc {}\n\n/// Writes a file in an atomic manner.\npub(crate) fn atomic_write(path: &Path, content: &[u8]) -> io::Result<()> {\n    // We create the temporary file in the same directory as the target file.\n    // Indeed the canonical temp directory and the target file might sit in different\n    // filesystem, in which case the atomic write may actually not work.\n    let parent_path = path.parent().ok_or_else(|| {\n        io::Error::new(\n            io::ErrorKind::InvalidInput,\n            \"Path {:?} does not have parent directory.\",\n        )\n    })?;\n    let mut tempfile = tempfile::Builder::new().tempfile_in(parent_path)?;\n    tempfile.write_all(content)?;\n    tempfile.flush()?;\n    tempfile.as_file_mut().sync_data()?;\n    tempfile.into_temp_path().persist(path)?;\n    Ok(())\n}\n\nimpl Directory for MmapDirectory {\n    fn get_file_handle(&self, path: &Path) -> Result<Arc<dyn FileHandle>, OpenReadError> {\n        debug!(\"Open Read {path:?}\");\n        let full_path = self.resolve_path(path);\n\n        let mut mmap_cache = self.inner.mmap_cache.write().map_err(|_| {","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/quickwit-oss/tantivy/blob/b5d8deb80c26924e6b007a5b1a7630f35ca64de4/src/directory/mmap_directory/mod.rs#L349-L385","documentation":"atomic_write creates its temp file in the target file's parent directory (so the final rename is atomic within one filesystem). If the given path has no parent component (e.g. a bare filename like \"meta.json\" relative to nothing, or a root-level oddity), parent() returns None and this InvalidInput error is thrown.","triggerScenarios":"Calling atomic_write (directly or via directory APIs that write metadata/managed files) with a Path built from a bare file name without a directory component, or a path whose parent is empty.","commonSituations":"Building paths with Path::new(\"file.json\") instead of joining onto the index directory; passing an empty or malformed path string to a custom directory implementation.","solutions":["Join the file name onto a concrete directory path before calling: dir.join(\"meta.json\")","Use the index/directory path as base instead of a bare relative name","If you control the caller, canonicalize or resolve the path first and assert it has a parent"],"exampleFix":"// before\natomic_write(Path::new(\"meta.json\"), &bytes)?;\n// after\nlet path = index_dir.join(\"meta.json\");\natomic_write(&path, &bytes)?;","handlingStrategy":"validation","validationCode":"fn has_parent(p: &Path) -> bool { p.parent().map_or(false, |p| !p.as_os_str().is_empty()) }","typeGuard":null,"tryCatchPattern":"match atomic_write(&path, &bytes) {\n    Err(e) if e.kind() == io::ErrorKind::InvalidInput\n        && e.to_string().contains(\"parent directory\") => {\n        eprintln!(\"path {:?} lacks a parent dir\", path);\n    }\n    Err(e) => return Err(e),\n    Ok(()) => (),\n}","preventionTips":["Always build file paths via dir.join(\"name\") rather than bare names","Canonicalize paths before writing","Reject empty/path-less filenames at your API boundary","Prefer using the directory handle's path for managed files"],"tags":["io","path","invalid-input","atomic-write"],"backgroundTag":"path-has-no-parent","analyzedSha":"b5d8deb80c26924e6b007a5b1a7630f35ca64de4","analyzedAt":"2026-09-05T13:20:51.521Z","contentChangedAt":"2026-09-05T13:20:51.521Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}