Cfmtool to write only changed files
Mostly to spare my iCloud Drive! XD
This commit is contained in:
parent
f1c2671a36
commit
3942fc27c4
11
cfmtool.py
11
cfmtool.py
|
@ -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__':
|
||||
|
|
Loading…
Reference in New Issue