bug fix: add try~catch

pull/1/head
pinb-mini 3 months ago
parent 6a2efb03e5
commit 82ec2d220b

@ -13,4 +13,4 @@ if __name__ == '__main__':
sys.exit(app.exec_()) sys.exit(app.exec_())
# pyinstaller --onefile bunnysync.py --add-data "images/realrabbit.ico:images" --add-data "images/realrabbit2.png:images" --icon=images/realrabbit.png --noconsole # pyinstaller --onefile bunnysync.py --add-data "images/realrabbit.png:images" --add-data "images/realrabbit2.png:images" --icon=images/realrabbit.png --noconsole

@ -74,32 +74,35 @@ class FolderSynchronizer:
count_sync = 0 count_sync = 0
for root, _, files in os.walk(src_folder): for root, _, files in os.walk(src_folder):
for filename in files: for filename in files:
src_path = os.path.join(root, filename) try:
rel_dir = os.path.relpath(root, src_folder) src_path = os.path.join(root, filename)
dest_path = os.path.join(dest_folder, rel_dir, filename) rel_dir = os.path.relpath(root, src_folder)
total_sync += 1 dest_path = os.path.join(dest_folder, rel_dir, filename)
total_sync += 1
src_modified = os.path.getmtime(src_path)
file_info = self.get_file_info(rel_dir, filename) src_modified = os.path.getmtime(src_path)
file_info = self.get_file_info(rel_dir, filename)
if not file_info:
# New file if not file_info:
os.makedirs(os.path.dirname(dest_path), exist_ok=True) # New file
shutil.copy2(src_path, dest_path) os.makedirs(os.path.dirname(dest_path), exist_ok=True)
count_sync += 1 shutil.copy2(src_path, dest_path)
dest_modified = current_time count_sync += 1
modified1, exist1, modified2, exist2 = src_modified, 1, dest_modified, 1 dest_modified = current_time
else: modified1, exist1, modified2, exist2 = src_modified, 1, dest_modified, 1
# Existing file
if src_modified > file_info[3] or not file_info[4]:
shutil.copy2(src_path, dest_path)
count_sync += 1
dest_modified = current_time
modified1, exist1, modified2, exist2 = src_modified, 1, dest_modified, 1
else: else:
modified1, exist1, modified2, exist2 = src_modified, 1, file_info[5], file_info[6] # Existing file
if src_modified > file_info[3] or not file_info[4]:
self.update_db(rel_dir, filename, modified1, exist1, modified2, exist2) shutil.copy2(src_path, dest_path)
count_sync += 1
dest_modified = current_time
modified1, exist1, modified2, exist2 = src_modified, 1, dest_modified, 1
else:
modified1, exist1, modified2, exist2 = src_modified, 1, file_info[5], file_info[6]
except:
pass
finally:
self.update_db(rel_dir, filename, modified1, exist1, modified2, exist2)
return total_sync, count_sync return total_sync, count_sync

Loading…
Cancel
Save