Skip to content

Commit

Permalink
handling deleting syncing nicely
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Mar 8, 2022
1 parent 0faca56 commit 1e1c7af
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions region_file_updater/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def print_log(server: ServerInterface, msg: str):
with open(LogFilePath, 'a') as logfile:
logfile.write(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) + ': ' + msg + '\n')
except Exception as e:
server.logger.info('错误写入日志文件: {}'.format(e))
server.logger.error('无法写入日志文件: {}'.format(e))


def add_region(source: CommandSource, region: Region):
Expand Down Expand Up @@ -159,17 +159,18 @@ def region_update(source: CommandSource):
historyList.clear()
for region in regionList:
for region_file in region.to_file_list():
source_dir = os.path.join(config.source_world_directory, region_file)
destination = os.path.join(config.destination_world_directory, region_file)
src_file = os.path.join(config.source_world_directory, region_file)
dest_file = os.path.join(config.destination_world_directory, region_file)
try:
source.get_server().logger.info('- "{}" -> "{}"'.format(source_dir, destination))
shutil.copyfile(source_dir, destination)
if not os.path.isfile(src_file) and os.path.isfile(dest_file):
os.remove(dest_file)
source.get_server().logger.info('- *deleted* -> "{}"'.format(src_file, dest_file))
else:
source.get_server().logger.info('- "{}" -> "{}"'.format(src_file, dest_file))
shutil.copyfile(src_file, dest_file)
except Exception as e:
msg = '失败,错误信息:{}'.format(str(e))
flag = False
if isinstance(e, FileNotFoundError) and os.path.exists(destination):
os.remove(destination)
source.get_server().logger.info('在目的地被删除的文件: {}'.format(destination))
else:
msg = '成功'
flag = True
Expand Down

0 comments on commit 1e1c7af

Please sign in to comment.