link(2) to rename files in sftp

Darren Tucker dtucker at zip.com.au
Tue Apr 6 12:00:57 EST 2004


Carson Gaspar wrote:

> --On Tuesday, April 06, 2004 09:24:31 +1000 Darren Tucker 
> 
>> According to the CVS log, the link shuffle is used to "fix races in
>> rename/symlink" (revs 1.46 and 1.44).
> 
> If rename() has a race condition, the OS is broken. Plain and simple.

The original code for rename looked like the following:
     if (stat(newpath, &st) == -1) {
         ret = rename(oldpath, newpath);
         status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
     }

The idea is obviously to not clobber existing files, but the 
implementation is racy (hence the change, I guess).

I have no idea how to implement that portably for filesystems without 
Unix semantics without the race.

-- 
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4  37C9 C982 80C7 8FF4 FA69
     Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.




More information about the openssh-unix-dev mailing list