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