Cfmtool to write only changed files

Mostly to spare my iCloud Drive! XD
This commit is contained in:
Elliot Nunn 2019-10-18 10:06:51 +08:00
parent f1c2671a36
commit 3942fc27c4
1 changed files with 9 additions and 2 deletions

View File

@ -978,8 +978,15 @@ def write_txt(txt, *path_parts):
def write_bin(bin, *path_parts):
path_parts = path.join(*path_parts)
os.makedirs(path.dirname(path_parts), exist_ok=True)
with open(path_parts, 'wb') as f:
f.write(bin)
# Write only if changed (slightly hacky)
try:
if path.getsize(path_parts) != len(bin): raise Exception
with open(path_parts, 'rb') as f:
if f.read() != bin: raise Exception
except:
with open(path_parts, 'wb') as f:
f.write(bin)
if __name__ == '__main__':