Flush file contents to disk and check for empty files.
This commit is contained in:
parent
60b160bcdf
commit
44d696c4af
|
@ -106,14 +106,18 @@ class ComicImage(object):
|
||||||
with open(fn, 'wb') as comicOut:
|
with open(fn, 'wb') as comicOut:
|
||||||
for chunk in self.urlobj.iter_content(chunk_size=self.ChunkBytes):
|
for chunk in self.urlobj.iter_content(chunk_size=self.ChunkBytes):
|
||||||
comicOut.write(chunk)
|
comicOut.write(chunk)
|
||||||
|
comicOut.flush()
|
||||||
|
os.fsync(comicOut.fileno())
|
||||||
self.touch(fn)
|
self.touch(fn)
|
||||||
|
size = os.path.getsize(fn)
|
||||||
|
if size == 0:
|
||||||
|
raise OSError("empty file %s" % fn)
|
||||||
except Exception:
|
except Exception:
|
||||||
if os.path.isfile(fn):
|
if os.path.isfile(fn):
|
||||||
os.remove(fn)
|
os.remove(fn)
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
size = strsize(os.path.getsize(fn))
|
out.info("Saved %s (%s)." % (fn, strsize(size)))
|
||||||
out.info("Saved %s (%s)." % (fn, size))
|
|
||||||
getHandler().comicDownloaded(self.name, fn)
|
getHandler().comicDownloaded(self.name, fn)
|
||||||
|
|
||||||
return fn, True
|
return fn, True
|
||||||
|
|
Loading…
Reference in a new issue