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 @@ 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: