Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save void285/511cde3600ae3ef9ad1f7214a6c1cacf to your computer and use it in GitHub Desktop.
Save void285/511cde3600ae3ef9ad1f7214a6c1cacf to your computer and use it in GitHub Desktop.
# coding: utf-8
import re
import os
import codecs
import shutil
# prepare a folder as backup place
backup_path = 'd:\\backup'
# the conflict files path list, copy from everything
files = codecs.open("sync-conflict.txt", "r", "utf-8").read().strip()
# corresponding original file path
files_ori = re.sub(r'\.sync-conflict-\d{8}-\d{6}-[A-Z]{7}\b', '', files)
files = files.split("\n")
files_ori = files_ori.split("\n")
for i in range(0, len(files)):
file_conflict = files[i]
if not file_conflict or not os.path.exists(file_conflict):
continue
file_ori = files_ori[i]
if not os.path.exists(file_ori):
print('file %s not exist' % (file_ori))
continue
mtime_ori = os.path.getmtime(file_ori)
size_ori = os.path.getsize(file_ori)
mtime_conflict = os.path.getmtime(file_conflict)
size_conflict = os.path.getsize(file_conflict)
if mtime_conflict > mtime_ori:
# abnormal, need check manually
print("%s\t%s -> %s | %s -> %s" % (file_ori, mtime_ori, mtime_conflict, size_ori, size_conflict))
else:
# backup conflict files
try:
shutil.move(file_conflict, backup_path)
except Exception as e:
print(file_conflict, str(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment