mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
SONY XML cache: Handle case where XML db contains reference to a file that does not exist gracefully
This commit is contained in:
parent
c2a80c1e7b
commit
8573807497
@ -610,7 +610,11 @@ class XMLCache(object):
|
|||||||
# is not new, compare its Sony DB date against localtime and gmtime.
|
# is not new, compare its Sony DB date against localtime and gmtime.
|
||||||
# Count the matches. When we must set a date, use the one with the most
|
# Count the matches. When we must set a date, use the one with the most
|
||||||
# matches. Use localtime if the case of a tie, and hope it is right.
|
# matches. Use localtime if the case of a tie, and hope it is right.
|
||||||
timestamp = os.path.getmtime(path)
|
try:
|
||||||
|
timestamp = os.path.getmtime(path)
|
||||||
|
except:
|
||||||
|
debug_print('Failed to get timestamp for:', path)
|
||||||
|
timestamp = time.time()
|
||||||
rec_date = record.get('date', None)
|
rec_date = record.get('date', None)
|
||||||
|
|
||||||
def clean(x):
|
def clean(x):
|
||||||
@ -627,12 +631,12 @@ class XMLCache(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if not getattr(book, '_new_book', False): # book is not new
|
if not getattr(book, '_new_book', False): # book is not new
|
||||||
if record.get('tz', None) is not None:
|
if record.get('tz', None) is not None:
|
||||||
use_tz_var = True
|
use_tz_var = True
|
||||||
if strftime(timestamp, zone=time.gmtime) == rec_date:
|
if strftime(timestamp, zone=time.gmtime) == rec_date:
|
||||||
gtz_count += 1
|
gtz_count += 1
|
||||||
elif strftime(timestamp, zone=time.localtime) == rec_date:
|
elif strftime(timestamp, zone=time.localtime) == rec_date:
|
||||||
ltz_count += 1
|
ltz_count += 1
|
||||||
else: # book is new. Set the time using the current votes
|
else: # book is new. Set the time using the current votes
|
||||||
if use_tz_var:
|
if use_tz_var:
|
||||||
tz = time.localtime
|
tz = time.localtime
|
||||||
@ -646,7 +650,10 @@ class XMLCache(object):
|
|||||||
debug_print("Use GMT TZ for new book", book.lpath)
|
debug_print("Use GMT TZ for new book", book.lpath)
|
||||||
date = strftime(timestamp, zone=tz)
|
date = strftime(timestamp, zone=tz)
|
||||||
record.set('date', clean(date))
|
record.set('date', clean(date))
|
||||||
record.set('size', clean(str(os.stat(path).st_size)))
|
try:
|
||||||
|
record.set('size', clean(str(os.stat(path).st_size)))
|
||||||
|
except:
|
||||||
|
record.set('size', '0')
|
||||||
title = book.title if book.title else _('Unknown')
|
title = book.title if book.title else _('Unknown')
|
||||||
record_set('title', title)
|
record_set('title', title)
|
||||||
ts = book.title_sort
|
ts = book.title_sort
|
||||||
|
Loading…
x
Reference in New Issue
Block a user