From 73c3629ab69b0e8ec94259ca4357e041c8c17009 Mon Sep 17 00:00:00 2001 From: Lertsenem Date: Thu, 25 Feb 2016 02:33:54 +0100 Subject: [PATCH] Bug on 'check' command for directories The command always showed a directory mismatch, because of filecmp.cmp function being applied to dirs (and not files only, duh). --- persoconf/commands/check.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/persoconf/commands/check.py b/persoconf/commands/check.py index 5c70431..d57feb9 100644 --- a/persoconf/commands/check.py +++ b/persoconf/commands/check.py @@ -136,18 +136,22 @@ def _compare_and_log(original_file_path, persoconf_backup_path, logger): is_dir = os.path.isdir( resolved_ofp ) - if filecmp.cmp(resolved_ofp, resolved_pbp) : - if is_dir: - logger.info( "No modification on %s/" - % original_file_path ) + if is_dir: + dcmp = filecmp.dircmp(resolved_ofp, resolved_pbp) + if ( len(dcmp.diff_files) > 0 + or len(dcmp.left_only) > 0 + or len(dcmp.right_only) > 0 ): + logger.warning( "Dir %s/ was modified" + % original_file_path ) else: - logger.info( "No modification on %s" + logger.info( "No modification on %s/" % original_file_path ) else: - if is_dir: - logger.warning( "Dir %s/ was modified" - % original_file_path ) + if filecmp.cmp(resolved_ofp, resolved_pbp) : + logger.info( "No modification on %s" + % original_file_path ) + else: logger.warning( "File %s was modified" % original_file_path )