{"record":{"id":"6dfc4daea0f92cbf","repo":"uutils/coreutils","slug":"no-unique-temporary-name-available-in-the-destination","errorCode":null,"errorMessage":"no unique temporary name available in the destination directory","messagePattern":"no unique temporary name available in the destination directory","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src/uucore/src/lib/features/fs.rs","lineNumber":1159,"sourceCode":"            urandom.read_exact(&mut raw)?;\n            for (slot, byte) in name[2..].iter_mut().zip(raw) {\n                *slot = ALPHABET[byte as usize % ALPHABET.len()];\n            }\n            let tmp = OsStr::from_bytes(&name);\n\n            match link_at(target, &dir, tmp, symbolic) {\n                Ok(()) => {\n                    let renamed = renameat(&dir, tmp, &dir, basename);\n                    // Renaming onto an existing link to the same inode is a\n                    // no-op, which leaves the temp behind.\n                    let _ = unlinkat(&dir, tmp, AtFlags::empty());\n                    return renamed.map_err(Into::into);\n                }\n                Err(e) if e.kind() == ErrorKind::AlreadyExists => {}\n                Err(e) => return Err(e),\n            }\n        }\n        Err(Error::new(\n            ErrorKind::AlreadyExists,\n            \"no unique temporary name available in the destination directory\",\n        ))\n    }\n    #[cfg(not(all(unix, not(target_os = \"redox\"))))]\n    {\n        // No atomic replace available here; this leaves the window described\n        // above, accepted only where the platform offers nothing better.\n        match create_link_std(target, dest, symbolic) {\n            Err(e) if e.kind() == ErrorKind::AlreadyExists => {\n                fs::remove_file(dest)?;\n                create_link_std(target, dest, symbolic)\n            }\n            res => res,\n        }\n    }\n}\n","sourceCodeStart":1141,"sourceCodeEnd":1177,"githubUrl":"https://github.com/uutils/coreutils/blob/92995feca29e324a7c559ede91db81c32d9f5d59/src/uucore/src/lib/features/fs.rs#L1141-L1177","documentation":"When creating the temporary link name inside the destination directory, replace_link retries on AlreadyExists a bounded number of times. If every candidate name collides, it gives up and returns 'no unique temporary name available in the destination directory' as an AlreadyExists error.","triggerScenarios":"replace_link (via handle_copy_mode or link) where repeated temp-name attempts in the destination directory all already exist — practically a pathological directory containing collisions for every attempted name.","commonSituations":"Extremely cluttered destination directories; adversarial environments where another process races to claim each temp name; extremely restrictive retry counts with high collision rates.","solutions":["Clean up stale temporary links in the destination directory","Retry the operation (transient race conditions usually resolve)","Ensure the process has write permission in the destination directory so renames succeed"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match replace_link(src, dest) {\n    Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => {\n        // transient collision; clean temp links and retry once\n        cleanup_temp_links(dest.parent().unwrap());\n        replace_link(src, dest)?;\n    }\n    r => r?,\n}","preventionTips":["Periodically clean stale temporary link names from output directories","Ensure the destination directory is writable so renames succeed","Avoid sharing one output directory across many concurrent link operations"],"tags":["filesystem","hardlink","tempfile","collision"],"backgroundTag":"file-already-exists","analyzedSha":"92995feca29e324a7c559ede91db81c32d9f5d59","analyzedAt":"2026-09-20T12:39:35.476Z","contentChangedAt":"2026-09-20T12:39:35.476Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}