View Single Post
Old 02-06-2012, 05:33 PM   #1
Egnaled Knarf
Junior Member
Egnaled Knarf began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Jan 2010
Device: Phone running whatever
Lightbulb PATCH: ebook-convert: obviate need for write permission in source directory

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:
I can not use all of Calibre for this project because of the abysmal performance when confronted with large collections (> 90000 documents in this case).
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).
Egnaled Knarf is offline   Reply With Quote