From 7aa82667e4265571a6f861ca51e8af8bdda1a953 Mon Sep 17 00:00:00 2001 From: Giorgos Korfiatis <gkorf@grnet.gr> Date: Thu, 14 May 2015 17:10:04 +0300 Subject: [PATCH] use filecmp instead of hashing --- agkyra/syncer/localfs_client.py | 13 ++----------- agkyra/syncer/utils.py | 13 ------------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/agkyra/syncer/localfs_client.py b/agkyra/syncer/localfs_client.py index 467a653..0bf2dd1 100644 --- a/agkyra/syncer/localfs_client.py +++ b/agkyra/syncer/localfs_client.py @@ -19,6 +19,7 @@ import re import datetime import psutil import time +import filecmp from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler @@ -103,17 +104,7 @@ def eq_float(f1, f2): def files_equal(f1, f2): logger.debug("Comparing files: '%s', '%s'" % (f1, f2)) - stats1, st1 = get_local_status(f1) - stats2, st2 = get_local_status(f2) - if st1 != st2: - return False - if st1 != LOCAL_FILE: - return True - if stats1[stat.ST_SIZE] != stats2[stat.ST_SIZE]: - return False - hash1 = utils.hash_file(f1) - hash2 = utils.hash_file(f2) - return hash1 == hash2 + return filecmp.cmp(f1, f2, shallow=False) def info_is_unhandled(info): diff --git a/agkyra/syncer/utils.py b/agkyra/syncer/utils.py index 7e02fe6..157e63f 100644 --- a/agkyra/syncer/utils.py +++ b/agkyra/syncer/utils.py @@ -21,8 +21,6 @@ import watchdog.utils from agkyra.syncer.common import OBJECT_DIRSEP -BUF_SIZE = 65536 - def to_local_sep(filename): return filename.replace(OBJECT_DIRSEP, os.path.sep) @@ -54,17 +52,6 @@ def hash_string(s): return hashlib.sha256(s).hexdigest() -def hash_file(filename, block_size=BUF_SIZE): - sha256 = hashlib.sha256() - with open(filename, 'rb') as f: - while True: - data = f.read(BUF_SIZE) - if not data: - break - sha256.update(data) - return sha256.hexdigest() - - def time_stamp(): return datetime.datetime.now().strftime("%s.%f") -- GitLab