Delete getmanga output files that aren't properly completed.
authorFredrik Tolf <fredrik@dolda2000.com>
Fri, 19 May 2017 15:10:00 +0000 (17:10 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Fri, 19 May 2017 15:10:00 +0000 (17:10 +0200)
getmanga

index c744617..7dea808 100755 (executable)
--- 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: