From e9bbafa51f5783aaafb8d13a677a409de799115e Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Tue, 13 Oct 2020 15:21:53 +0200 Subject: [PATCH] fix bug for #271 --- dotdrop/dotdrop.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 366aa57..34b23c8 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -229,6 +229,9 @@ def cmd_compare(o, tmp): comp = Comparator(diff_cmd=o.diff_command, debug=o.debug) for dotfile in selected: + if not dotfile.src and not dotfile.dst: + # ignore fake dotfile + continue # add dotfile variables t.restore_vars(tvars) newvars = dotfile.get_dotfile_variables() @@ -581,7 +584,21 @@ def cmd_remove(o): # remove dotfile from dotpath dtpath = os.path.join(o.dotpath, dotfile.src) - remove(dtpath) + try: + remove(dtpath) + except OSError: + # did not exist + pass + # remove empty directory + parent = os.path.dirname(dtpath) + # remove any empty parent up to dotpath + while parent != o.dotpath: + if os.path.isdir(parent) and not os.listdir(parent): + msg = 'Remove empty dir \"{}\"'.format(parent) + if o.safe and not LOG.ask(msg): + break + remove(parent) + parent = os.path.dirname(parent) removed.append(dotfile.key) if o.dry: