From 3942fc27c487b75cdc8db58d5371a17a5fe070fe Mon Sep 17 00:00:00 2001 From: Elliot Nunn Date: Fri, 18 Oct 2019 10:06:51 +0800 Subject: [PATCH] Cfmtool to write only changed files Mostly to spare my iCloud Drive! XD --- cfmtool.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cfmtool.py b/cfmtool.py index 50d26a6..a0ec400 100755 --- a/cfmtool.py +++ b/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__':