View Single Post
Old 10-23-2018, 04:18 PM   #906
ilovejedd
hopeless n00b
ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.
 
ilovejedd's Avatar
 
Posts: 5,110
Karma: 19597086
Join Date: Jan 2009
Location: in the middle of nowhere
Device: PW4, PW3, Libra H2O, iPad 10.5, iPad 11, iPad 12.9
Hmm, looking further into this issue, there appears to be two possible causes:

1.) Caching: If I change files while Calibre is shut down, the Quality Check plugin doesn't catch any of the changes but sometimes it does if I make changes while Calibre is running.

2.) Possible use of a mapped legacy function to get the "db" size.

/src/calibre/db/legacy.py -> I believe format_metadata uses os.stat which would give the same file size as os.path.getsize
Code:
    def sizeof_format(self, index, fmt, index_is_id=False):
        book_id = index if index_is_id else self.id(index)
        return self.new_api.format_metadata(book_id, fmt).get('size', None)
/src/calibre/library/database.py
Code:
    def sizeof_format(self, index, format, index_is_id=False):
        ''' Return size of C{format} for book C{index} in bytes'''
        id = index if index_is_id else self.id(index)
        format = format.upper()
        return self.conn.get('SELECT uncompressed_size FROM data WHERE data.book=? AND data.format=?', (id, format), all=False)

Quality Check/check_fix.py
Code:
    for fmt in formats.split(','):
        db_size = db.sizeof_format(book_id, fmt, index_is_id=True)
        book_path = db.format_abspath(book_id, fmt, index_is_id=True)
        if not book_path:
            self.log.error('Unable to find path to book id:', book_id, db.title(book_id, index_is_id=True))
            continue
        if os.path.exists(book_path):
            actual_size = os.path.getsize(book_path)
            if actual_size != db_size:
That's pretty much the extent of my practically non-existent Python reading skills.

Fixing the code so sizeof_format gets information from database instead of os.stat or to prevent caching is way beyond my skill set. I'm fairly adept at cut-and-paste though, so I managed to add a nuclear option Force repair book sizes. Per the option name, this will forcibly update the sizes for all formats regardless if it's been changed or not so use with care. I only use it with Search scope - Selected book(s).
Attached Files
File Type: zip Quality Check-mod.zip (128.9 KB, 281 views)
ilovejedd is offline   Reply With Quote