1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 20:54:51 +00:00

Add logic for respecting ignores/negative ignores when updating files

This commit is contained in:
Joey Territo
2020-12-18 18:54:42 -05:00
parent e1eb5f99c1
commit dce19eb268

View File

@@ -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