You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
656 B

#!/usr/bin/env python3
import sys
import os
import hashlib
def hash_file(fname):
if not os.path.exists(fname):
return b""
hasher = hashlib.md5()
with open(fname, "rb") as f:
return hasher.digest()
old_digest = hash_file(sys.argv[3])
with open(sys.argv[3] + ".tmp", "wb") as f:
f.write(open(sys.argv[1], "rb").read())
if os.path.exists(sys.argv[2]):
f.write(open(sys.argv[2], "rb").read())
new_digest = hash_file(sys.argv[3] + ".tmp")
if new_digest != old_digest:
os.rename(sys.argv[3] + ".tmp", sys.argv[3])
os.remove(sys.argv[3] + ".tmp")