diff options
author | Sebastian Schuberth <sschuberth@gmail.com> | 2016-06-09 11:34:18 +0200 |
---|---|---|
committer | Sebastian Schuberth <sschuberth@gmail.com> | 2016-06-09 11:49:30 +0200 |
commit | df1ab0f01a695aeedea8a8c050636f80b61b1157 (patch) | |
tree | 2ddfaafed8b98d5b053b3312a6800a4cf582d23d /jenkins_jobs | |
parent | 6e4b760655a7128600e9541875380f07793ccbb0 (diff) | |
download | python-jenkins-job-builder-df1ab0f01a695aeedea8a8c050636f80b61b1157.tar.gz python-jenkins-job-builder-df1ab0f01a695aeedea8a8c050636f80b61b1157.tar.xz python-jenkins-job-builder-df1ab0f01a695aeedea8a8c050636f80b61b1157.zip |
Catch OSError when renaming and try to remove the destination file first
Otherwise the rename fails on Windows if the destination file already
exists.
Change-Id: Id15cfaa5b9278d7e932a7975ab6e5a878b31a642
Diffstat (limited to 'jenkins_jobs')
-rw-r--r-- | jenkins_jobs/builder.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py index 9775f7ff..d7d68bba 100644 --- a/jenkins_jobs/builder.py +++ b/jenkins_jobs/builder.py @@ -110,7 +110,13 @@ class CacheStorage(object): tfile.flush() self._os.fsync(tfile.fileno()) tfile.close() - self._os.rename(tfile.name, self.cachefilename) + try: + self._os.rename(tfile.name, self.cachefilename) + except OSError: + # On Windows, if dst already exists, OSError will be raised even if + # it is a file. Remove the file first in that case and try again. + self._os.remove(self.cachefilename) + self._os.rename(tfile.name, self.cachefilename) self._logger.debug("Cache written out to '%s'" % self.cachefilename) |