[Buildbot-devel] Some questions/problems running latest build bot source on Windows

Tommi Virtanen tv at tv.debian.net
Thu Nov 11 15:07:40 UTC 2004


Brian Warner wrote:
> --- buildbot/status/builder.py	15 Oct 2004 16:59:44 -0000	1.39
> +++ buildbot/status/builder.py	8 Nov 2004 21:19:39 -0000	1.40
> @@ -757,7 +757,12 @@
>          tmpfilename = filename + ".tmp"
>          try:
>              pickle.dump(self, open(tmpfilename, "w"), -1)
> -            os.rename(tmpfilename, filename)
> +            try:
> +                os.rename(tmpfilename, filename)
> +            except OSError:
> +                # windows cannot rename a file on top of an existing one
> +                os.unlink(filename)
> +                os.rename(tmpfilename, filename)
>          except Exception, e:
>              log.msg("unable to save build %s-#%d" % (self.builder.name,
>                                                       self.number))

[and another one just like it]

That's downright dangerous if the file is in any way precious.
os.rename can fail due to e.g. no memory available, causing you
to run that unlink, and then fail _again_ to rename the file, thus
losing the target file.

I'd suggest making any windows-specific fixes just that --
windows-specific. if os.sys.platform == 'win32': ...

The real issue is that OSError covers quite a lot of different
failures, and you're really only concerned with one: the target
file exists.

PS. os.rename isn't safe on NFS, you really should use os.link.




More information about the devel mailing list