@@ -418,8 +418,6 @@ def rename_author_path(first_author, old_author_dir, renamed_author, calibre_pat
418418 # Create new_author_dir from parameter or from database
419419 # Create new title_dir from database and add id
420420 new_authordir = get_valid_filename (first_author , chars = 96 )
421- # new_author = calibre_db.session.query(db.Authors).filter(db.Authors.name == renamed_author).first()
422- # old_author_dir = get_valid_filename(old_author_name, chars=96)
423421 new_author_rename_dir = get_valid_filename (renamed_author , chars = 96 )
424422 if gdrive :
425423 g_file = gd .getFileFromEbooksFolder (None , old_author_dir )
@@ -468,7 +466,6 @@ def update_dir_structure_file(book_id, calibre_path, original_filepath, new_auth
468466 db_filename ,
469467 original_filepath ,
470468 path )
471- # old_path = os.path.join(calibre_path, author_dir, new_title_dir).replace('\\', '/')
472469 new_path = os .path .join (calibre_path , new_author_dir , new_title_dir ).replace ('\\ ' , '/' )
473470 all_new_name = get_valid_filename (local_book .title , chars = 42 ) + ' - ' \
474471 + get_valid_filename (new_author , chars = 42 )
@@ -477,8 +474,6 @@ def update_dir_structure_file(book_id, calibre_path, original_filepath, new_auth
477474
478475 if error :
479476 return error
480-
481- # Rename all files from old names to new names
482477 return False
483478
484479
@@ -490,7 +485,7 @@ def upload_new_file_gdrive(book_id, first_author, title, title_dir, original_fil
490485 title_dir + " (" + str (book_id ) + ")" )
491486 book .path = gdrive_path .replace ("\\ " , "/" )
492487 gd .uploadFileToEbooksFolder (os .path .join (gdrive_path , file_name ).replace ("\\ " , "/" ), original_filepath )
493- return False # rename_files_on_change(first_author, renamed_author, local_book=book, gdrive=True)
488+ return False
494489
495490
496491def update_dir_structure_gdrive (book_id , first_author ):
@@ -523,19 +518,21 @@ def update_dir_structure_gdrive(book_id, first_author):
523518 all_new_name = get_valid_filename (book .title , chars = 42 ) + ' - ' \
524519 + get_valid_filename (new_authordir , chars = 42 )
525520 rename_all_files_on_change (book , book .path , book .path , all_new_name , gdrive = True ) # todo: Move filenames on gdrive
526- # change location in database to new author/title path
527- # book.path = os.path.join(authordir, new_titledir).replace('\\', '/')
528521 return False
529522
530523
531524def move_files_on_change (calibre_path , new_author_dir , new_titledir , localbook , db_filename , original_filepath , path ):
532525 new_path = os .path .join (calibre_path , new_author_dir , new_titledir )
533- # new_name = get_valid_filename(localbook.title, chars=96) + ' - ' + new_author_dir
534526 try :
535527 if original_filepath :
536528 if not os .path .isdir (new_path ):
537529 os .makedirs (new_path )
538- shutil .move (original_filepath , os .path .join (new_path , db_filename ))
530+ try :
531+ shutil .move (original_filepath , os .path .join (new_path , db_filename ))
532+ except OSError :
533+ log .error ("Rename title from {} to {} failed with error, trying to "
534+ "move without metadata" .format (path , new_path ))
535+ shutil .move (original_filepath , os .path .join (new_path , db_filename ), copy_function = shutil .copy )
539536 log .debug ("Moving title: %s to %s" , original_filepath , new_path )
540537 else :
541538 # Check new path is not valid path
0 commit comments