Parcourir la source

renamed fileName to targetFileName

master
myitinos il y a 5 ans
Parent
révision
4639a4125c
1 fichiers modifiés avec 9 ajouts et 9 suppressions
  1. +9
    -9
      clone.py

+ 9
- 9
clone.py Voir le fichier

@ -24,28 +24,28 @@ class Cloner:
elif entry.is_file():
self.handleFile(entry.path)
def handleFile(self, fileName: str):
cloneFileName = fileName.replace(self.targetDir, self.backupDir)
def handleFile(self, targetFileName: str):
cloneFileName = targetFileName.replace(self.targetDir, self.backupDir)
cloneHashFileName = cloneFileName + '.md5'
if os.path.exists(cloneFileName):
with open(cloneHashFileName, 'r') as cloneHashFile, open(fileName, 'rb') as targetFile:
with open(cloneHashFileName, 'r') as cloneHashFile, open(targetFileName, 'rb') as targetFile:
cloneHashFileContent = cloneHashFile.read()
targetFileContent = targetFile.read()
realHash = hashlib.md5(targetFileContent).hexdigest()
if realHash != cloneHashFileContent:
os.system('cp {backup} {real}'.format(
backup=cloneFileName, real=fileName))
backup=cloneFileName, real=targetFileName))
logging.warning(
'{file} failed check, restoring...'.format(file=fileName))
'{file} failed check, restoring...'.format(file=targetFileName))
else:
logging.info('{file} is fine'.format(file=fileName))
logging.info('{file} is fine'.format(file=targetFileName))
else:
logging.warning(
'{file} is a new file, added to backup dir'.format(file=fileName))
'{file} is a new file, added to backup dir'.format(file=targetFileName))
os.system('cp {real} {clone}'.format(
real=fileName, clone=cloneFileName))
with open(cloneHashFileName, 'w') as cloneHashFile, open(fileName, 'rb') as targetFile:
real=targetFileName, clone=cloneFileName))
with open(cloneHashFileName, 'w') as cloneHashFile, open(targetFileName, 'rb') as targetFile:
targetFileContent = targetFile.read()
cloneHashFile.write(hashlib.md5(targetFileContent).hexdigest())

Chargement…
Annuler
Enregistrer