From a0d19d2f40b3cbeaff17ec53d983dd2bc787bee3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 17 Mar 2014 09:36:04 +0530 Subject: [PATCH] Edit book: Fix a regression in the previous release that broke saving a copy of the current book on linux and OS X --- src/calibre/gui2/tweak_book/save.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/tweak_book/save.py b/src/calibre/gui2/tweak_book/save.py index 36688dc5d3..cd78860796 100644 --- a/src/calibre/gui2/tweak_book/save.py +++ b/src/calibre/gui2/tweak_book/save.py @@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import, __license__ = 'GPL v3' __copyright__ = '2013, Kovid Goyal ' -import shutil, os +import shutil, os, errno from threading import Thread from Queue import LifoQueue, Empty @@ -25,7 +25,14 @@ def save_container(container, path): if hasattr(os, 'fchmod'): # Ensure file permissions and owner information is preserved fno = temp.fileno() - st = os.stat(path) + try: + st = os.stat(path) + except EnvironmentError as err: + if err.errno != errno.ENOENT: + raise + # path may not exist if we are saving a copy, in which case we use + # the metadata from the original book + st = os.stat(container.path_to_ebook) os.fchmod(fno, st.st_mode) os.fchown(fno, st.st_uid, st.st_gid)