Edit book: Fix file permissions for the edited book being changed on Linux and OS X

Since the editor saves by using a temp file and then renaming the temp
file to overwrite the original, we have to explicitly copy over
permissions and owner metadata to the temp file to ensure they remain
unchanged.
This commit is contained in:
Kovid Goyal 2014-03-13 14:13:29 +05:30
parent aea66db018
commit f0d676502f

View File

@ -22,6 +22,13 @@ from calibre.utils.ipc import RC
def save_container(container, path):
temp = PersistentTemporaryFile(
prefix=('_' if iswindows else '.'), suffix=os.path.splitext(path)[1], dir=os.path.dirname(path))
if hasattr(os, 'fchmod'):
# Ensure file permissions and owner information is preserved
fno = temp.fileno()
st = os.stat(path)
os.fchmod(fno, st.st_mode)
os.fchown(fno, st.st_uid, st.st_gid)
temp.close()
temp = temp.name
try: