From eea4dddc32e5fab0af9ccd1ded82d2e6ddbe3083 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 29 Mar 2014 08:38:02 +0530 Subject: [PATCH] Edit Book: When user is editing files belonging to another user account on linux/os x rather than erroring out when saving, change the ownership of the file to the editing user. Fixes #1299097 [Editing doesn't save changes since version 1.28](https://bugs.launchpad.net/calibre/+bug/1299097) --- src/calibre/gui2/tweak_book/save.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tweak_book/save.py b/src/calibre/gui2/tweak_book/save.py index cd78860796..dfe3380d3d 100644 --- a/src/calibre/gui2/tweak_book/save.py +++ b/src/calibre/gui2/tweak_book/save.py @@ -34,7 +34,14 @@ def save_container(container, path): # 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) + try: + os.fchown(fno, st.st_uid, st.st_gid) + except EnvironmentError as err: + if err.errno != errno.EPERM: + # ignore chown failure as user could be editing file belonging + # to a different user, in which case we really cant do anything + # about it short of making the file update non-atomic + raise temp.close() temp = temp.name