Don't use os.rename() to overwrite file, causes errors on Windows

This commit is contained in:
Erik Johnson 2015-08-20 18:28:38 -05:00
parent 2819b85373
commit 5aff1aeb9e

View File

@ -6,6 +6,7 @@ from __future__ import absolute_import
# Import python libs
import contextlib
import errno
import logging
import hashlib
import os
@ -623,6 +624,19 @@ class Client(object):
else:
destfp.close()
destfp = None
# Can't just do an os.rename() here, this results in a
# WindowsError being raised when the destination path exists on
# a Windows machine. Have to remove the file.
try:
os.remove(dest)
except OSError as exc:
if exc.errno != errno.ENOENT:
raise MinionError(
'Error: Unable to remove {0}: {1}'.format(
dest,
exc.strerror
)
)
os.rename(dest_tmp, dest)
return dest
except HTTPError as exc: