From 67e82c25e145cb0bc754db033d4963a5eba1360a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 22 Dec 2015 09:33:54 +0530 Subject: [PATCH] Image compression: Fix spurious zero byte .bak files being created when compressing png images inside epub files Works around bug in optipng --- src/calibre/utils/img.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/calibre/utils/img.py b/src/calibre/utils/img.py index 99944d2ce9..8fb7389653 100644 --- a/src/calibre/utils/img.py +++ b/src/calibre/utils/img.py @@ -125,6 +125,11 @@ def run_optimizer(file_path, cmd, as_filter=False, input_data=None): except EnvironmentError as err: if err.errno != errno.ENOENT: raise + try: + os.remove(outfile + '.bak') # optipng creates these files + except EnvironmentError as err: + if err.errno != errno.ENOENT: + raise def optimize_jpeg(file_path): exe = get_exe_path('jpegtran')