Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 12-21-2022, 09:59 AM   #1
falsifier
Junior Member
falsifier began at the beginning.
 
falsifier's Avatar
 
Posts: 7
Karma: 10
Join Date: Dec 2022
Location: in UTC+1 TZ
Device: PocketBook Touch Lux 4
Ebook editor silently overwrites read-only ebook files

I've been using linux version of Calibre's ebook editor for years, since version 3.x I think. I really like it, all the progress it made, but there's this one thing I can't (under)stand: when saving, it silently overwrites read-only ebook files. The read-only attribute is there for a purpose you know, you should at least get a warning about the file being write-protected and a chance to back off…

Last time it worked well enough was in version 5.36 -- when you clicked 'save' you got an error message that the file could not be saved, so you knew you might had done something you didn't want to do. Since 5.37 there's no more message and the file just gets silently overwritten despite being protected -- in theory -- by its read-only attribute. I thought that maybe this was just a new bug and would be fixed soon but there were already more than 10 releases since 5.36 and it still does that. I tried to be careful about it but since I frequently have several editor windows open I've already got bitten by it several times -- I modified and saved wrong ebook files effectively losing large parts of them.

So, am I the only one who finds overwriting of read-only files without any warning unacceptable? Is this a “feature” of this editor or indeed a bug?
falsifier is offline   Reply With Quote
Old 12-21-2022, 11:18 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Why are you even editing read only files? what is it you hope to achieve by doing that? Editing a file that you dont want changed is well...

And this was a deliberate feature, introduced in 5.37 which you can see in https://calibre-ebook.com/whats-new

And it was introduced precisely to prevent someone from losing hours of work if they happen to edit a file that was readonly for a random reason and they dont know how to fix file permissions (which is surprisingly common).

And yes there could be a warning dialog, but implementing one is too much effort for this, at least for me, patches welcome.
kovidgoyal is offline   Reply With Quote
Advert
Old 12-21-2022, 11:21 AM   #3
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
On second thoughts, its much easier to show the warning once when the book is opened. https://github.com/kovidgoyal/calibr...523a7869c8c518
kovidgoyal is offline   Reply With Quote
Old 12-21-2022, 02:34 PM   #4
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 79,750
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by falsifier View Post
I've been using linux version of Calibre's ebook editor for years, since version 3.x I think. I really like it, all the progress it made, but there's this one thing I can't (under)stand: when saving, it silently overwrites read-only ebook files. The read-only attribute is there for a purpose you know, you should at least get a warning about the file being write-protected and a chance to back off…

Last time it worked well enough was in version 5.36 -- when you clicked 'save' you got an error message that the file could not be saved, so you knew you might had done something you didn't want to do. Since 5.37 there's no more message and the file just gets silently overwritten despite being protected -- in theory -- by its read-only attribute. I thought that maybe this was just a new bug and would be fixed soon but there were already more than 10 releases since 5.36 and it still does that. I tried to be careful about it but since I frequently have several editor windows open I've already got bitten by it several times -- I modified and saved wrong ebook files effectively losing large parts of them.

So, am I the only one who finds overwriting of read-only files without any warning unacceptable? Is this a “feature” of this editor or indeed a bug?
It's the fault of Linux for being buggered. Windows would not allow me to overwrite if the file was read-only.
JSWolf is offline   Reply With Quote
Old 12-21-2022, 03:08 PM   #5
lomkiri
Groupie
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 167
Karma: 1497966
Join Date: Jul 2021
Device: N/A
Quote:
Originally Posted by kovidgoyal View Post
And it was introduced precisely to prevent someone from losing hours of work if they happen to edit a file that was readonly for a random reason and they dont know how to fix file permissions (which is surprisingly common).
I am the author of this request, but in fact, my concern was with "save-as", not "save". I agree with Falsifier that it shouldn't be possible to overwrite a RO file, not without warning, at least, but my problem was that it wasn't possible to "save as" to a new file either, which would be the expected behavior. So I've lost my work on that epub. The change you've made at that time solved this issue, but a side-effect was that RO files were not protected anymore (I've noticed it at that time, but said nothing, I didn't want to bother you).

I don't know if I understand the code of your present patch correctly, but it seems that you've put a warning, but no option to desist. Am I right ? If it's the case, I think it would be welcome to be able to desist, and to "save as" instead.

Last edited by lomkiri; 12-21-2022 at 03:11 PM.
lomkiri is offline   Reply With Quote
Advert
Old 12-21-2022, 03:13 PM   #6
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 79,750
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by lomkiri View Post
I am the author of this request, but in fact, my concern was with "save-as", not "save". I agree with Falsifier that it shouldn't be possible to overwrite a RO file, not without warning, at least, but my problem was that it wasn't possible to "save as" to a new file either, which would be the expected behavior. So I've lost my work on that epub. The change you've made at that time solved this issue, but a side-effect was that RO files were not protected anymore (I've noticed it at that time, but said nothing, I didn't want to bother you).

I don't know if I understand the code of your present patch correctly, but it seems that you've put a warning, but no option to desist. Am I right ? If it's the case, I think it would be welcome to be able to desist, and to "save as" instead.
There's no reason to desist. Sometimes I load a file in the editor to try something or look at some code and I don't want to save. So if it was read-only, it would not bother me. But if I was editing to make changes and it came up with a warning, I'd exit the editor and deal with the problem.
JSWolf is offline   Reply With Quote
Old 12-21-2022, 03:41 PM   #7
Quoth
Still reading
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 14,025
Karma: 105092227
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
Quote:
Originally Posted by JSWolf View Post
It's the fault of Linux for being buggered. Windows would not allow me to overwrite if the file was read-only.
Not true. A program can change the write access. It's not happening by accident. I've written programs for Windows to change file permissions.
Only pressed CDs, DVDs, ROMs and similar are immutably Read Only.
Quoth is offline   Reply With Quote
Old 12-21-2022, 03:41 PM   #8
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,724
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by lomkiri View Post
I don't know if I understand the code of your present patch correctly, but it seems that you've put a warning, but no option to desist. Am I right ? If it's the case, I think it would be welcome to be able to desist, and to "save as" instead.
As I read it, the patch issues a warning message when a read-only file is opened, if the user's intent is to change the file and save in place then they should quit the editor and remove the RO permission before trying to edit.

BR
BetterRed is offline   Reply With Quote
Old 12-21-2022, 05:29 PM   #9
lomkiri
Groupie
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 167
Karma: 1497966
Join Date: Jul 2021
Device: N/A
Quote:
Originally Posted by BetterRed View Post
As I read it, the patch issues a warning message when a read-only file is opened, if the user's intent is to change the file and save in place then they should quit the editor and remove the RO permission before trying to edit.
Sure! My bad! I haven't seen the name of the modified method... and have interpolated as my wishes were :-)

Anyway, if I may give my advice, it's not an expected behavior to change the RW rights when we want to write on a protected file, and I guess that's what Falsifier is complaining about. If a book have been put in RO, calibre shouldn't overpass this decision, he could, maybe, only save after a warning, but without changing the permission (as vim do).

In fact, the expected behavior, IMO, would be to deny "save" on a RO only file, maybe with a warning saying why and suggesting either to change the perms or to "save a copy". But I guess it's not an easy task in the code (I understand that "save" and "save a copy" use the same method applied on different paths, so maybe it's not that simple to have a different behavior for one or for the other).

Quote:
Originally Posted by JSWolf View Post
There's no reason to desist. [...] But if I was editing to make changes and it came up with a warning, I'd exit the editor and deal with the problem.
Yes, that's what's I have done, I didn't remember, but when I red the thread, I see I have finally saved my work. From my posts of feb. 2022:

Quote:
When an epub is read-only, the action "Save" fails, which is logical.
What is not expected is that the action "save as" also fails. Is it normal ?
[...]
No, /data/temp/ is 777.
In fact, giving w/r permission to the original epub (and no other action) solves the case and I can "save a copy" (perms of /data/temp/ didn't change)
That's why I presume that the permission of the destinatary dir. (w/r) is mixed up with the permission of the original file (w/o)

Last edited by lomkiri; 12-21-2022 at 05:32 PM.
lomkiri is offline   Reply With Quote
Old 12-21-2022, 08:15 PM   #10
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,724
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
This is on Windows

When I do a Save As, it defaults to the location used for the previous Save As.

However, if that location no longer exists it uses it's parent, and if that location doesn't exist it uses it's parent . . . but that can end up in a location where the current user doesn't have write permission - e.g. the Users directory. If you try to save in that location Windows will tell you that you can't do that, and offer to do the save to your home directory.

BR

Last edited by BetterRed; 12-21-2022 at 08:21 PM.
BetterRed is offline   Reply With Quote
Old 12-23-2022, 05:42 PM   #11
falsifier
Junior Member
falsifier began at the beginning.
 
falsifier's Avatar
 
Posts: 7
Karma: 10
Join Date: Dec 2022
Location: in UTC+1 TZ
Device: PocketBook Touch Lux 4
Quote:
Originally Posted by kovidgoyal View Post
Why are you even editing read only files? what is it you hope to achieve by doing that? Editing a file that you dont want changed is well...
Why are you even thinking I'm editing read-only files? Of course I don't edit them. But I do open and keep them open so I can quickly consult them while indeed editing other ones. I make them write-protected on purpose, to make sure they stay unchanged, because I open them in an editor after all, and s#%t happens. You make a mistake and edit wrong file, and then too quickly click those “Save” and “Close” buttons, giving yourself no chance to revert the changes. Or your cat steps on the ‘Delete’ key on your keyboard while you went to the loo and you don't notice when you're back. You do know Murphy's law, don't you? That read-only file attribute is supposed to protect you from such things, so it's just not right to silently ignore/remove that protection and overwrite files without owner's knowledge and approval…

Quote:
Originally Posted by kovidgoyal View Post
there could be a warning dialog, but implementing one is too much effort for this, at least for me, patches welcome.
Here's a patch for the problem Lomkiri originally reported. With this applied, if the original file is write-protected, ‘Save’ will fail with the ‘Could not save’ error message, but ‘Save a copy’ will succeed. I think it works OK but I only tested it with epubs, and I'm not a proper Python programmer, so someone better verify it.

Code:
--- calibre-6.10.0/src/calibre/gui2/tweak_book/save.py.6.10.0.orig	2022-12-16 03:29:36.000000000 +0100
+++ calibre-6.10.0/src/calibre/gui2/tweak_book/save.py	2022-12-23 23:01:01.483650018 +0100
@@ -48,7 +48,16 @@
                     raise
                 # Somebody deleted the original file
+            if st is not None:
+                try:
+                    os.fchmod(fno, st.st_mode | stat.S_IWUSR)
+                except OSError as err:
+                    if err.errno != errno.EPERM:
+                        raise
+                    raise OSError('Failed to change permissions of {} to {} ({}), with error: {}. Most likely the {} directory has a restrictive umask'.format(
+                        temp.name, oct(st.st_mode), format_permissions(st.st_mode), errno.errorcode[err.errno], os.path.dirname(temp.name)))
+                st = os.stat(fno)
         if st is not None:
             try:
-                os.fchmod(fno, st.st_mode | stat.S_IWUSR)
+                os.fchmod(fno, st.st_mode)
             except OSError as err:
                 if err.errno != errno.EPERM:
Quote:
Originally Posted by kovidgoyal View Post
On second thoughts, its much easier to show the warning once when the book is opened
Well, perhaps useful for someone unaware of opening a read-only file, but not good enough for me.
falsifier is offline   Reply With Quote
Old 12-24-2022, 07:59 AM   #12
falsifier
Junior Member
falsifier began at the beginning.
 
falsifier's Avatar
 
Posts: 7
Karma: 10
Join Date: Dec 2022
Location: in UTC+1 TZ
Device: PocketBook Touch Lux 4
How long does it usually take the moderators (there's 10 of them listed?), to review the posts before they appear here? The first I sent appeared in minutes but I sent a reply over 12 hours ago and it's still not here… Not a great experience for a new member.
falsifier is offline   Reply With Quote
Old 12-24-2022, 08:09 AM   #13
Quoth
Still reading
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 14,025
Karma: 105092227
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
Look at the date!
Also a very active worldwide site.
Quoth is offline   Reply With Quote
Old 12-24-2022, 08:25 AM   #14
falsifier
Junior Member
falsifier began at the beginning.
 
falsifier's Avatar
 
Posts: 7
Karma: 10
Join Date: Dec 2022
Location: in UTC+1 TZ
Device: PocketBook Touch Lux 4
What about the date? And why these last posts appear immediately? Not all are reviewed by moderators? How come?
falsifier is offline   Reply With Quote
Old 12-24-2022, 09:38 AM   #15
Quoth
Still reading
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 14,025
Karma: 105092227
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
Holiday season
Not all of the Moderators are active all the time. They have real lives.
Generally only new members have posts in a moderation queue and it's because of spammers.

This is a brilliant and well moderated site.
Quoth is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript files not referenced in ebook-editor dmonasse Editor 2 04-17-2014 07:37 AM
calibre's ebook viewer unable to open/read some .azw3 files bauerhjb Calibre 1 05-19-2013 09:51 AM
Associating ebook files with Calibre ebook viewer zobop Library Management 1 06-24-2012 11:07 AM
Calibre 0.8.12 Overwrites 'Im_Reading' and 'Read' Status on original Kobo GMFuller Devices 4 07-31-2011 02:12 AM


All times are GMT -4. The time now is 09:26 PM.


MobileRead.com is a privately owned, operated and funded community.