Edit book: Fix a regression in the previous release that broke saving a copy of the current book on linux and OS X

This commit is contained in:
Kovid Goyal 2014-03-17 09:36:04 +05:30
parent e6e4a61ecc
commit a0d19d2f40

View File

@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
__license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
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()
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)