1
0
mirror of https://github.com/janeczku/calibre-web synced 2025-09-11 15:26:00 +00:00

Fix for (#3261 handle permission error on generating new folders during rename of authors)

This commit is contained in:
Ozzie Isaacs
2024-12-21 11:29:50 +01:00
parent 14bb01010d
commit be5247a2ef
3 changed files with 763 additions and 321 deletions

View File

@@ -162,7 +162,7 @@ def upload():
return make_response(jsonify(resp))
else:
resp = {"location": url_for('web.show_book', book_id=book_id)}
return make_response(jsonify(resp))
return Response(json.dumps(resp), mimetype='application/json')
except (OperationalError, IntegrityError, StaleDataError) as e:
calibre_db.session.rollback()
log.error_or_exception("Database error: {}".format(e))
@@ -398,6 +398,7 @@ def get_sorted_entry(field, bookid):
return make_response(jsonify(authors=" & ".join([a.name for a in calibre_db.order_authors([book])])))
return ""
@editbook.route("/ajax/simulatemerge", methods=['POST'])
@user_login_required
@edit_required
@@ -462,6 +463,7 @@ def read_selected_books():
return json.dumps({'success': True})
return ""
@editbook.route("/ajax/mergebooks", methods=['POST'])
@user_login_required
@edit_required
@@ -772,8 +774,9 @@ def prepare_authors(authr, calibre_path, gdrive=False):
all_new_name = helper.get_valid_filename(one_book.title, chars=42) + ' - ' \
+ helper.get_valid_filename(renamed_author.name, chars=42)
# change location in database to new author/title path
helper.rename_all_files_on_change(one_book, new_path, new_path, all_new_name, gdrive)
error = helper.rename_all_files_on_change(one_book, new_path, new_path, all_new_name, gdrive)
if error:
flash(error)
return input_authors

View File

@@ -394,10 +394,16 @@ def delete_book_file(book, calibrepath, book_format=None):
def rename_all_files_on_change(one_book, new_path, old_path, all_new_name, gdrive=False):
for file_format in one_book.data:
if not gdrive:
if not os.path.exists(new_path):
os.makedirs(new_path)
shutil.move(os.path.join(old_path, file_format.name + '.' + file_format.format.lower()),
os.path.join(new_path, all_new_name + '.' + file_format.format.lower()))
try:
if not os.path.exists(new_path):
os.makedirs(new_path)
shutil.move(os.path.join(old_path, file_format.name + '.' + file_format.format.lower()),
os.path.join(new_path, all_new_name + '.' + file_format.format.lower()))
except PermissionError as ex:
log.error("Moving book-id %s folder %s failed: %s", one_book.id, new_path, ex)
return _("Moving book path of Book %(book_id)s to: '%(src)s' failed with error: %(error)s",
book_id=one_book.id, src=new_path, error=str(ex))
else:
g_file = gd.getFileFromEbooksFolder(old_path,
file_format.name + '.' + file_format.format.lower())
@@ -410,6 +416,7 @@ def rename_all_files_on_change(one_book, new_path, old_path, all_new_name, gdriv
# change name in Database
file_format.name = all_new_name
return False
def rename_author_path(first_author, old_author_dir, renamed_author, calibre_path="", gdrive=False):
@@ -468,7 +475,7 @@ def update_dir_structure_file(book_id, calibre_path, original_filepath, new_auth
all_new_name = get_valid_filename(local_book.title, chars=42) + ' - ' \
+ get_valid_filename(new_author, chars=42)
# Book folder already moved, only files need to be renamed
rename_all_files_on_change(local_book, new_path, new_path, all_new_name)
error |= rename_all_files_on_change(local_book, new_path, new_path, all_new_name)
if error:
return error
@@ -511,11 +518,11 @@ def update_dir_structure_gdrive(book_id, first_author):
book.path = new_authordir + '/' + book.path.split('/')[1]
gd.updateDatabaseOnEdit(g_file['id'], book.path)
else:
return _('File %(file)s not found on Google Drive', file=authordir) # file not found'''
return _('File %(file)s not found on Google Drive', file=authordir) # file not found
if titledir != new_titledir or authordir != new_authordir :
all_new_name = get_valid_filename(book.title, chars=42) + ' - ' \
+ get_valid_filename(new_authordir, chars=42)
rename_all_files_on_change(book, book.path, book.path, all_new_name, gdrive=True) # todo: Move filenames on gdrive
return rename_all_files_on_change(book, book.path, book.path, all_new_name, gdrive=True) # todo: Move filenames on gdrive
return False
@@ -558,26 +565,6 @@ def move_files_on_change(calibre_path, new_author_dir, new_titledir, localbook,
return False
def rename_files_on_change(first_author,
renamed_author,
local_book,
original_filepath="",
path="",
calibre_path="",
gdrive=False):
# Rename all files from old names to new names
#try:
#clean_author_database(renamed_author, calibre_path, gdrive=gdrive)
#if first_author and first_author not in renamed_author:
# clean_author_database([first_author], calibre_path, local_book, gdrive)
#if not gdrive and not renamed_author and not original_filepath and len(os.listdir(os.path.dirname(path))) == 0:
# shutil.rmtree(os.path.dirname(path))
#except (OSError, FileNotFoundError) as ex:
# log.error_or_exception("Error in rename file in path {}".format(ex))
# return _("Error in rename file in path: {}".format(str(ex)))
return False
def delete_book_gdrive(book, book_format):
error = None
if book_format:
@@ -972,8 +959,9 @@ def do_download_file(book, book_format, client, data, headers):
# ToDo Check headers parameter
for element in headers:
response.headers[element[0]] = element[1]
log.info('Downloading file: \'%s\' by %s - %s', format(os.path.join(filename, book_name + "." + book_format)),
log.info('Downloading file: \'%s\' by %s', format(os.path.join(filename, book_name + "." + book_format)),
current_user.name, request.headers.get('X-Forwarded-For', request.remote_addr))
log.info('Downloading file: {}'.format(os.path.join(filename, book_name + "." + book_format)))
return response

File diff suppressed because it is too large Load Diff