From daaea5d13e27550f22c603561717d61d7314ede1 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Fri, 19 May 2017 17:10:00 +0200 Subject: [PATCH] Delete getmanga output files that aren't properly completed. --- getmanga | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/getmanga b/getmanga index c744617..7dea808 100755 --- a/getmanga +++ b/getmanga @@ -83,11 +83,17 @@ def download(mng, tdir, pattern): msg(1, "getting %s...", nm) with page.open() as fp: with open(path, "wb") as out: - while True: - data = fp.read(65536) - if data == b"": - break - out.write(data) + done = False + try: + while True: + data = fp.read(65536) + if data == b"": + done = True + break + out.write(data) + finally: + if not done: + os.unlink(path) try: img = Image.open(path) except OSError: -- 2.11.0