From f0d676502fbddca0aedb1d6ac79d0e0b25a182a7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 13 Mar 2014 14:13:29 +0530 Subject: [PATCH] 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. --- src/calibre/gui2/tweak_book/save.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/calibre/gui2/tweak_book/save.py b/src/calibre/gui2/tweak_book/save.py index 0627c27241..36688dc5d3 100644 --- a/src/calibre/gui2/tweak_book/save.py +++ b/src/calibre/gui2/tweak_book/save.py @@ -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: