Unlike on Unix, os.rename(src, dst) will fail on Windows if the dst file
already exists. Remove it first.
if not os.path.exists(filename) or not filecmp.cmp(tempfile, filename):
# The filename does not exist or it's different from the new file,
# so replace old file with new.
if not os.path.exists(filename) or not filecmp.cmp(tempfile, filename):
# The filename does not exist or it's different from the new file,
# so replace old file with new.
+ if os.path.exists(filename):
+ os.remove(filename)
os.rename(tempfile, filename)
return
os.rename(tempfile, filename)
return