mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 12:34:16 +00:00
fix directory listed as copied even when ignored
This commit is contained in:
@@ -287,16 +287,18 @@ class Updater:
|
|||||||
self.log.dry(f'would cp -r {exist} {new}')
|
self.log.dry(f'would cp -r {exist} {new}')
|
||||||
continue
|
continue
|
||||||
self.log.dbg(f'cp -r {exist} {new}')
|
self.log.dbg(f'cp -r {exist} {new}')
|
||||||
|
cpied_cnt = 0
|
||||||
try:
|
try:
|
||||||
ign_func = self._ignore(ignores)
|
ign_func = self._ignore(ignores)
|
||||||
copytree_with_ign(exist, new,
|
cpied_cnt= copytree_with_ign(exist, new,
|
||||||
ignore_func=ign_func,
|
ignore_func=ign_func,
|
||||||
debug=self.debug)
|
debug=self.debug)
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
msg = f'error copying dir {exist}'
|
msg = f'error copying dir {exist}'
|
||||||
self.log.err(f'{msg}: {exc}')
|
self.log.err(f'{msg}: {exc}')
|
||||||
continue
|
continue
|
||||||
self.log.sub(f'\"{new}\" dir added')
|
if cpied_cnt:
|
||||||
|
self.log.sub(f'\"{new}\" dir added')
|
||||||
|
|
||||||
def _ignore(self, ignores):
|
def _ignore(self, ignores):
|
||||||
def ignore_func(path):
|
def ignore_func(path):
|
||||||
|
|||||||
@@ -303,15 +303,18 @@ def must_ignore(paths, ignores, debug=False):
|
|||||||
|
|
||||||
|
|
||||||
def _cp(src, dst, ignore_func=None, debug=False):
|
def _cp(src, dst, ignore_func=None, debug=False):
|
||||||
"""the copy function for copytree"""
|
"""
|
||||||
|
the copy function for copytree
|
||||||
|
returns the numb of files copied
|
||||||
|
"""
|
||||||
if ignore_func and ignore_func(src):
|
if ignore_func and ignore_func(src):
|
||||||
return
|
return 0
|
||||||
if not os.path.isfile(src):
|
if not os.path.isfile(src):
|
||||||
# ignore special files
|
# ignore special files
|
||||||
if debug:
|
if debug:
|
||||||
LOG.dbg(f'ignore special file \"{src}\"',
|
LOG.dbg(f'ignore special file \"{src}\"',
|
||||||
force=True)
|
force=True)
|
||||||
return
|
return 0
|
||||||
dstdir = os.path.dirname(dst)
|
dstdir = os.path.dirname(dst)
|
||||||
if debug:
|
if debug:
|
||||||
LOG.dbg(f'mkdir \"{dstdir}\"',
|
LOG.dbg(f'mkdir \"{dstdir}\"',
|
||||||
@@ -320,7 +323,10 @@ def _cp(src, dst, ignore_func=None, debug=False):
|
|||||||
if debug:
|
if debug:
|
||||||
LOG.dbg(f'cp {src} {dst}',
|
LOG.dbg(f'cp {src} {dst}',
|
||||||
force=True)
|
force=True)
|
||||||
shutil.copy2(src, dst)
|
path = shutil.copy2(src, dst)
|
||||||
|
if os.path.exists(path):
|
||||||
|
return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def copyfile(src, dst, debug=False):
|
def copyfile(src, dst, debug=False):
|
||||||
@@ -332,9 +338,13 @@ def copyfile(src, dst, debug=False):
|
|||||||
|
|
||||||
|
|
||||||
def copytree_with_ign(src, dst, ignore_func=None, debug=False):
|
def copytree_with_ign(src, dst, ignore_func=None, debug=False):
|
||||||
"""copytree with support for ignore"""
|
"""
|
||||||
|
copytree with support for ignore
|
||||||
|
returns the numb of files installed
|
||||||
|
"""
|
||||||
if debug:
|
if debug:
|
||||||
LOG.dbg(f'copytree \"{src}\" to \"{dst}\"', force=True)
|
LOG.dbg(f'copytree \"{src}\" to \"{dst}\"', force=True)
|
||||||
|
copied_count = 0
|
||||||
for entry in os.listdir(src):
|
for entry in os.listdir(src):
|
||||||
srcf = os.path.join(src, entry)
|
srcf = os.path.join(src, entry)
|
||||||
dstf = os.path.join(dst, entry)
|
dstf = os.path.join(dst, entry)
|
||||||
@@ -346,12 +356,13 @@ def copytree_with_ign(src, dst, ignore_func=None, debug=False):
|
|||||||
LOG.dbg(f'mkdir \"{dstf}\"',
|
LOG.dbg(f'mkdir \"{dstf}\"',
|
||||||
force=True)
|
force=True)
|
||||||
os.makedirs(dstf, exist_ok=True)
|
os.makedirs(dstf, exist_ok=True)
|
||||||
copytree_with_ign(srcf, dstf, ignore_func=ignore_func)
|
copied_count += copytree_with_ign(srcf, dstf, ignore_func=ignore_func)
|
||||||
else:
|
else:
|
||||||
if debug:
|
if debug:
|
||||||
LOG.dbg(f'copytree, copy file \"{src}\" to \"{dst}\"',
|
LOG.dbg(f'copytree, copy file \"{src}\" to \"{dst}\"',
|
||||||
force=True)
|
force=True)
|
||||||
_cp(srcf, dstf, ignore_func=ignore_func, debug=debug)
|
copied_count += _cp(srcf, dstf, ignore_func=ignore_func, debug=debug)
|
||||||
|
return copied_count
|
||||||
|
|
||||||
|
|
||||||
def uniq_list(a_list):
|
def uniq_list(a_list):
|
||||||
|
|||||||
Reference in New Issue
Block a user