Comment 5 for bug 183948

Revision history for this message
codeslinger (codeslinger) wrote :

[quote] I'm not even going to ask why bzr creates a file and then tries to rename another file over the top of it.. :-o

on second thought, I am going to ask.... because this is just not a good thing for the program to be doing, and people will be saddled with this problem from now until forever. it already cost me a full day of work, multiply that by however many people get zapped by it.....

The fix is trivial and it will make the program robust, right now it is very fragile and has to be coaxed into working. Just because you can get away with doing something does not mean that you should do it. I'm not a python programmer, but in php it would look like this... simply go through the code and replace every rename with a call to this function.

//move, rename file... assumes that you have already done security and sanity checks on $tgt and $src

function robust_file_rename($src, $tgt)
{
   //there should also be a sanity check here for $tgt, you would not ever want to unlink '/' or NULL

    if (file_exists($tgt)) unlink($tgt);
    if (file_exists($tgt)) {} //fail here with informative error msg about the lack of permissions

    $bResult = rename($src, $tgt);
    if (!$bResult) {} //fail here with informative error msg about the lack of permissions etc

   return $bResult;
}