From 69a57df269d47f80076cfda1827395cf6bab3bcc Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Wed, 27 May 2020 01:12:43 +0200 Subject: [PATCH] Handle directories. --- focker/export.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/focker/export.py b/focker/export.py index 93912a9..b5410d1 100644 --- a/focker/export.py +++ b/focker/export.py @@ -16,10 +16,10 @@ def normalized_recursive_directory_iterator(path): def create_map(name, L): return map(lambda x: os.path.join(name, x), L) L = create_map(name, L) - yield (os.path.relpath(name, path), name, st.st_mode, st.st_uid, st.st_gid, st.st_size) + yield (os.path.relpath(name, path), name, st.st_mode, st.st_uid, st.st_gid, st.st_size, st.st_mtime) Q = chain(L, Q) else: # file - yield (os.path.relpath(name, path), name, st.st_mode, st.st_uid, st.st_gid, st.st_size) + yield (os.path.relpath(name, path), name, st.st_mode, st.st_uid, st.st_gid, st.st_size, st.st_mtime) name = next(Q, None) @@ -37,9 +37,9 @@ def _export_diff(mountpoint, origin_mountpoint, output_directory): def emit_compare(m, o): if m[2] != o[2] or m[3] != o[3] or m[4] != o[4]: print('Metadata change:', o[0]) - elif m[5] != o[5] : + elif stat.S_ISREG(m[2]) and m[5] != o[5]: print('Size change:', o[0]) - elif stat.S_ISREG(m[2]) and filehash(m[1]) != filehash(o[1]): + elif stat.S_ISREG(m[2]) and m[6] != o[6] and filehash(m[1]) != filehash(o[1]): print('Content change:', o[0]) else: # no change pass # print('Compare:', m[0]) @@ -59,6 +59,10 @@ def _export_diff(mountpoint, origin_mountpoint, output_directory): elif m[0] > o[0]: emit_removal(o) o = next(oit, None) + elif stat.S_ISDIR(m[2]) != stat.S_ISDIR(o[2]): + emit_creation(m) + m = next(mit, None) + o = next(oit, None) else: emit_compare(m, o) m = next(mit, None)