{"record":{"id":"50c779e8515189e1","repo":"uutils/coreutils","slug":"could-not-allocate-a-unique-temp-name-in-destinati","errorCode":null,"errorMessage":"could not allocate a unique temp name in destination directory","messagePattern":"could not allocate a unique temp name in destination directory","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src/uu/mv/src/mv.rs","lineNumber":1107,"sourceCode":"        urandom.read_exact(&mut raw)?;\n        for (slot, byte) in tmp_bytes[2..].iter_mut().zip(raw) {\n            *slot = ALPHABET[(byte as usize) % ALPHABET.len()];\n        }\n        let tmp = OsStr::from_bytes(&tmp_bytes);\n\n        match symlinkat(target, &dir_fd, tmp) {\n            Ok(()) => {\n                if let Err(e) = renameat(&dir_fd, tmp, &dir_fd, basename) {\n                    let _ = unlinkat(&dir_fd, tmp, AtFlags::empty());\n                    return Err(io::Error::from(e));\n                }\n                return Ok(());\n            }\n            Err(e) if e == rustix::io::Errno::EXIST => {}\n            Err(e) => return Err(io::Error::from(e)),\n        }\n    }\n    Err(io::Error::new(\n        io::ErrorKind::AlreadyExists,\n        \"could not allocate a unique temp name in destination directory\",\n    ))\n}\n\n#[cfg(windows)]\nfn rename_symlink_fallback(from: &Path, to: &Path) -> io::Result<()> {\n    let path_symlink_points_to = fs::read_link(from)?;\n    if path_symlink_points_to.exists() {\n        if path_symlink_points_to.is_dir() {\n            windows::fs::symlink_dir(&path_symlink_points_to, to)?;\n        } else {\n            windows::fs::symlink_file(&path_symlink_points_to, to)?;\n        }\n        fs::remove_file(from)\n    } else {\n        Err(io::Error::new(\n            io::ErrorKind::NotFound,","sourceCodeStart":1089,"sourceCodeEnd":1125,"githubUrl":"https://github.com/uutils/coreutils/blob/85295bbf788bfd7a6926ba692031563504b304b7/src/uu/mv/src/mv.rs#L1089-L1125","documentation":"For atomic symlink replacement, create_symlink_replace first creates a uniquely-named temporary symlink inside the destination directory (to then rename it over the target). If, after repeated attempts, no unique temp name can be allocated, it gives up with this AlreadyExists error rather than risk clobbering anything.","triggerScenarios":"Creating a temp name (e.g., a randomized suffix via openat with O_EXCL semantics) fails with EEXIST on every attempt — astronomically unlikely by chance, but effectively certain if the directory listing is frozen (e.g., extremely hostile/high-entropy collision or a filesystem quirk always returning EXIST).","commonSituations":"Destination directory on an exotic filesystem that misreports EEXIST; a loop count exhausted due to a broken PRNG/tempname scheme; extremely constrained environments where the directory cannot be written but names always appear to exist.","solutions":["Retry the mv — temp-name allocation is randomized, so a one-off failure is transient","Check destination directory permissions and that the filesystem supports creating symlinks (Windows may require privileges) with `ln -s dest/.probe`","Verify filesystem health (fsck / chkdsk) if it persists on that volume","Fall back to a non-atomic replace (unlink then ln -s) if atomicity is not required, and report the bug"],"exampleFix":"null","handlingStrategy":"retry","validationCode":"# ensure destination dir is writable and symlink creation works\ntouch \"$dest_dir/.probe\" && rm \"$dest_dir/.probe\" || { echo \"dest not writable\"; exit 1; }","typeGuard":null,"tryCatchPattern":"// transient — retry the move a few times\nfor attempt in 1..=3 {\n    match mv_symlink_replace(src, dst) {\n        Ok(()) => break,\n        Err(e) if e.kind() == io::ErrorKind::AlreadyExists && attempt < 3 => continue,\n        Err(e) => return Err(e),\n    }\n}","preventionTips":["Retry transient AlreadyExists failures once before escalating","Confirm the destination filesystem supports symlinks (esp. Windows) before atomic replace","Keep destination directories healthy; investigate persistent EEXIST on that volume"],"tags":["mv","symlink","temp-name","atomic-replace"],"backgroundTag":"temp-name-allocation-failed","analyzedSha":"85295bbf788bfd7a6926ba692031563504b304b7","analyzedAt":"2026-08-31T11:11:36.175Z","contentChangedAt":"2026-08-31T11:11:36.175Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}