Kamil Dudka wrote: > - if (rename (src_name, dst_name) == 0) > + int flags = 0; > + if (x->interactive == I_ALWAYS_NO) > + /* do not replace DST_NAME if it was created since our last check */ > + flags = RENAME_NOREPLACE; By then it's too late, as multiple decisions have been made on the basis of stat/lstat calls that are still subject to races. It's better to try the renameat2 with RENAME_NOREPLACE first thing, and fall back on the existing code only if renameat2 fails with errno != EEXIST. Plus, there are some other problems when combining -u and -n. How about the attached patch instead?