From dce19eb268b1032c1e9c68ef7505c9efa70a93e1 Mon Sep 17 00:00:00 2001 From: Joey Territo Date: Fri, 18 Dec 2020 18:54:42 -0500 Subject: [PATCH] Add logic for respecting ignores/negative ignores when updating files --- dotdrop/updater.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dotdrop/updater.py b/dotdrop/updater.py index 37c6dd0..de38e21 100644 --- a/dotdrop/updater.py +++ b/dotdrop/updater.py @@ -8,6 +8,7 @@ handle the update of dotfiles import os import shutil import filecmp +import fnmatch # local imports from dotdrop.logger import Logger @@ -273,8 +274,22 @@ class Updater: continue if self.debug: self.log.dbg('cp -r {} {}'.format(exist, new)) + # Newly created directory should be copied as is (for efficiency). - shutil.copytree(exist, new) + def ig(src, names): + whitelist, blacklist = set(), set() + for ignore in self.ignores: + for name in names: + path = os.path.join(src, name) + if ignore.startswith('!') and fnmatch.fnmatch(path, ignore[1:]): + # add to whitelist + whitelist.add(name) + elif fnmatch.fnmatch(path, ignore): + # add to blacklist + blacklist.add(name) + return blacklist - whitelist + + shutil.copytree(exist, new, ignore=ig) self.log.sub('\"{}\" dir added'.format(new)) # remove dirs that don't exist in deployed version