@@ -3792,30 +3792,30 @@ def report_progress(fname):
37923792 raise ValueError ('Corrupted files:\n ' + '\n ' .join (importer .corrupted_files ))
37933793 cache = Cache (DB (library_path , load_user_formatter_functions = False ))
37943794 cache .init ()
3795-
3796- format_data = {int (book_id ):data for book_id , data in metadata ['format_data' ].items ()}
3797- extra_files = {int (book_id ):data for book_id , data in metadata .get ('extra_files' , {}).items ()}
3798- for i , (book_id , fmt_key_map ) in enumerate (format_data .items ()):
3799- if abort is not None and abort .is_set ():
3800- return
3801- title = cache ._field_for ('title' , book_id )
3802- if progress is not None :
3803- progress (title , i + poff , total )
3804- cache ._update_path ((book_id ,), mark_as_dirtied = False )
3805- for fmt , fmtkey in fmt_key_map .items ():
3806- if fmt == '.cover' :
3807- with importer .start_file (fmtkey , _ ('Cover for %s' ) % title ) as stream :
3795+ with cache .write_lock :
3796+ format_data = {int (book_id ):data for book_id , data in metadata ['format_data' ].items ()}
3797+ extra_files = {int (book_id ):data for book_id , data in metadata .get ('extra_files' , {}).items ()}
3798+ for i , (book_id , fmt_key_map ) in enumerate (format_data .items ()):
3799+ if abort is not None and abort .is_set ():
3800+ return
3801+ title = cache ._field_for ('title' , book_id )
3802+ if progress is not None :
3803+ progress (title , i + poff , total )
3804+ cache ._update_path ((book_id ,), mark_as_dirtied = False )
3805+ for fmt , fmtkey in fmt_key_map .items ():
3806+ if fmt == '.cover' :
3807+ with importer .start_file (fmtkey , _ ('Cover for %s' ) % title ) as stream :
3808+ path = cache ._get_book_path (book_id )
3809+ cache .backend .set_cover (book_id , path , stream , no_processing = True )
3810+ else :
3811+ with importer .start_file (fmtkey , _ ('{0} format for {1}' ).format (fmt .upper (), title )) as stream :
3812+ size , fname = cache ._do_add_format (book_id , fmt , stream , mtime = stream .mtime )
3813+ cache .fields ['formats' ].table .update_fmt (book_id , fmt , fname , size , cache .backend )
3814+ for relpath , efkey in extra_files .get (book_id , {}).items ():
3815+ with importer .start_file (efkey , _ ('Extra file {0} for book {1}' ).format (relpath , title )) as stream :
38083816 path = cache ._get_book_path (book_id )
3809- cache .backend .set_cover (book_id , path , stream , no_processing = True )
3810- else :
3811- with importer .start_file (fmtkey , _ ('{0} format for {1}' ).format (fmt .upper (), title )) as stream :
3812- size , fname = cache ._do_add_format (book_id , fmt , stream , mtime = stream .mtime )
3813- cache .fields ['formats' ].table .update_fmt (book_id , fmt , fname , size , cache .backend )
3814- for relpath , efkey in extra_files .get (book_id , {}).items ():
3815- with importer .start_file (efkey , _ ('Extra file {0} for book {1}' ).format (relpath , title )) as stream :
3816- path = cache ._get_book_path (book_id )
3817- cache .backend .add_extra_file (relpath , stream , path )
3818- cache .dump_metadata ({book_id })
3817+ cache .backend .add_extra_file (relpath , stream , path )
3818+ cache .dump_metadata ({book_id })
38193819 if importer .corrupted_files :
38203820 raise ValueError ('Corrupted files:\n ' + '\n ' .join (importer .corrupted_files ))
38213821 if progress is not None :
0 commit comments