From 50c69db0991f6de15a089207e4056ad927197cc4 Mon Sep 17 00:00:00 2001 From: Fallen_Breath Date: Tue, 17 Aug 2021 13:32:39 +0800 Subject: [PATCH] delete existed temp files in case --- permanent_backup/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/permanent_backup/__init__.py b/permanent_backup/__init__.py index c3a2317..6997ff7 100644 --- a/permanent_backup/__init__.py +++ b/permanent_backup/__init__.py @@ -122,7 +122,10 @@ def filter_ignore(path, files): return [file for file in files if file == 'session.lock' and config.ignore_session_lock] touch_backup_folder() for world in config.world_names: - shutil.copytree(os.path.join(config.server_path, world), os.path.join(config.backup_path, world), ignore=filter_ignore) + target_path = os.path.join(config.backup_path, world) + if os.path.isdir(target_path): + shutil.rmtree(target_path) + shutil.copytree(os.path.join(config.server_path, world), target_path, ignore=filter_ignore) if not auto_save_on: source.get_server().execute('save-on') auto_save_on = True @@ -152,6 +155,7 @@ def filter_ignore(path, files): info_message(source, '备份§a完成§r,耗时{}秒'.format(round(time.time() - start_time, 1)), broadcast=True) except Exception as e: info_message(source, '备份§a失败§r,错误代码{}'.format(e), broadcast=True) + source.get_server().logger.exception('创建备份失败') finally: creating_backup.release() if config.turn_off_auto_save and not auto_save_on: