|
![]() |
|
Thread Tools | Search this Thread |
![]() |
#1 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Jan 2010
Device: Phone running whatever
|
![]()
I'm using part of the Calibre cli tools to implement a rudimentary library management system capable of converting documents on the fly to several popular formats.
Spoiler:
While implementing these on-the-fly conversion functions I noticed ebook-convert (and with that Calibre proper as well as far as I can tell) needs write permission in the document source directory for at least conversions from TXT to other formats. Given that it only uses this permission to create a temporary file which is deleted a few moments later and given the risks inherent in allowing write access to the document source directory may I suggest applying this short patch to obviate this requirement? The patch does away with the versioned temporary file in the source directory, replacing it with a proper temporary file as create by Calibre's own TemporaryFile method. This is both cleaner as well as more readable, and works in situations where the user running ebook-convert (in my case www-data) does not have write permission to the library source.
The patch to fix this problem when converting TXT-related documents to other formats is attached to this message. It is of course possible this problem exists elsewhere in Calibre so more patching might be called for. The patch applies to Calibre 0.8.38 (and with some fuzz to earlier versions as well). |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,145
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Your patch will break txt files that reference images using relative paths (with markdown, for instance).
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Jan 2010
Device: Phone running whatever
|
True, I had not thought of that - probably because I don't have any markdown-formatted texts. This breakage could be resolved by symlinking the contents of the source directory to the temporary directory. I'll go hunting for a suitably complex test case to add this to the patch.
|
![]() |
![]() |
![]() |
#4 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,145
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Symlinking isn't cross platform, and there's no way you can guarantee that the linked to resources are in the same directory as the txt file.
|
![]() |
![]() |
![]() |
#5 | |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Jan 2010
Device: Phone running whatever
|
Quote:
Given the (to me at least...) obvious advantages of keeping write access to the library source limited to the absolute minimum I can live with these limitations but the current patch is clearly not ready for general release. Since it does fit my needs I'll just keep patching... |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,145
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Why dont you simply copy the source file out of the library to a temp directory and then convert it and copy the result back.
|
![]() |
![]() |
![]() |
#7 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Jan 2010
Device: Phone running whatever
|
While that would have most of the benefits of my method, it has all of the drawbacks with regard to unresolved relative links and it adds an additional file copy.
|
![]() |
![]() |
![]() |
#8 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,145
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
There are no relative links for documents in the calibre library, unless the user has been manually putting files in there. And since you only care about unix, create a hard link, that will mean no extra copy unless hte temp dir is mounted ona different partition.
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Write Permission | wtw1936 | Library Management | 2 | 09-21-2011 12:40 AM |
Open Source Font Directory for 1.9.5 | Toastedpine | Kobo Reader | 3 | 06-29-2011 02:16 PM |
ebook-convert: access current working directory inside recipe | jens32 | Recipes | 3 | 06-03-2011 10:57 AM |
Do you need permission to write about public places? | ficbot | Writers' Corner | 14 | 12-28-2009 09:58 AM |
Convert LIT bug & patch | llasram | Workshop | 4 | 12-30-2007 04:05 PM |