]> www.dolda2000.com Git - automanga.git/commitdiff
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 c7446176a42d899904fe0e4caaf82ddfb78c2757..7dea808376d7f2854185d4c20a019ab82b0a020e 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: