{"record":{"id":"6d225b859f278a11","repo":"sxyazi/yazi","slug":"path-too-long-windows","errorCode":null,"errorMessage":"path too long","messagePattern":"path too long","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-fs/src/casefold/windows.rs","lineNumber":25,"sourceCode":"\nuse super::Casefold;\n\nimpl Casefold {\n\tpub(super) fn final_name(path: &Path) -> io::Result<OsString> {\n\t\tif let Ok(name) = Self::by_find(path) {\n\t\t\treturn Ok(name);\n\t\t}\n\n\t\tlet file = OpenOptions::new()\n\t\t\t.access_mode(0)\n\t\t\t.custom_flags(FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT)\n\t\t\t.open(path)?;\n\n\t\tmatch Self::by_handle(&file, &mut [0u16; 512])? {\n\t\t\tEither::Left(name) => Ok(name),\n\t\t\tEither::Right(len) => match Self::by_handle(&file, &mut vec![0u16; len as usize])? {\n\t\t\t\tEither::Left(name) => Ok(name),\n\t\t\t\tEither::Right(_) => Err(io::Error::new(ErrorKind::InvalidData, \"path too long\")),\n\t\t\t},\n\t\t}\n\t}\n\n\tfn by_find(path: &Path) -> io::Result<OsString> {\n\t\tSelf::check_name(path)?;\n\t\tlet wide = path.to_wide();\n\n\t\tlet mut data = unsafe { mem::zeroed::<WIN32_FIND_DATAW>() };\n\t\tlet handle = unsafe {\n\t\t\tFindFirstFileExW(\n\t\t\t\twide.as_ptr(),\n\t\t\t\tFindExInfoBasic,\n\t\t\t\t(&raw mut data).cast(),\n\t\t\t\tFindExSearchNameMatch,\n\t\t\t\tptr::null(),\n\t\t\t\t0,\n\t\t\t)","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/sxyazi/yazi/blob/a541adde4e5b082719a0f21a87eb3eab071ece58/yazi-fs/src/casefold/windows.rs#L7-L43","documentation":"On Windows, final_name first queries FileNormalizedNameInfo with a 512-u16 stack buffer; if the API reports it needs more, it retries with a heap buffer of that size. A second failure means the name still doesn't fit, so it returns 'path too long'.","triggerScenarios":"A file whose normalized name exceeds even the API-reported buffer length — path component lengths near the 32k limit, or the handle query raced with a rename that grew the name.","commonSituations":"Extremely deep directory trees with long Unicode names; network paths (UNC) with very long components; files being renamed concurrently.","solutions":["Shorten the path or move the file closer to the root","Use the \\\\?\\ extended-length prefix for very long paths","Retry — a concurrent rename may have invalidated the length probe"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// give the API an oversized buffer up front to avoid the two-step path\nlet mut buf = vec![0u16; 1024]; // 2048 bytes covers virtually all normalized names","typeGuard":null,"tryCatchPattern":"match Casefold::final_name(path) {\n    Ok(n) => n,\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidData => shorten_and_retry(path),\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Keep total path length well under Windows limits (use short install locations)","Avoid extremely deep nesting and very long Unicode components","Enable long-path support (manifest/registry) so normalized names stay short"],"tags":["windows","filesystem","path-length"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"a541adde4e5b082719a0f21a87eb3eab071ece58","analyzedAt":"2026-09-18T10:12:31.659Z","contentChangedAt":"2026-09-18T10:12:31.659Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}