mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-05 09:43:49 +00:00
Merge remote-tracking branch 'origin/fix-418'
This commit is contained in:
@@ -249,15 +249,19 @@ class Importer:
|
||||
if not os.path.isdir(in_fs):
|
||||
# is a file
|
||||
self.log.dbg(f'{in_fs} is file')
|
||||
copyfile(in_fs, srcf, debug=self.debug)
|
||||
if not copyfile(in_fs, srcf, debug=self.debug):
|
||||
self.log.err(f'importing \"{in_fs}\" failed')
|
||||
return False
|
||||
else:
|
||||
# is a dir
|
||||
if os.path.exists(srcf):
|
||||
shutil.rmtree(srcf)
|
||||
self.log.dbg(f'{in_fs} is dir')
|
||||
copytree_with_ign(in_fs, srcf,
|
||||
ignore_func=self._ignore,
|
||||
debug=self.debug)
|
||||
if not copytree_with_ign(in_fs, srcf,
|
||||
ignore_func=self._ignore,
|
||||
debug=self.debug):
|
||||
self.log.err(f'importing \"{in_fs}\" failed')
|
||||
return False
|
||||
except shutil.Error as exc:
|
||||
in_dotpath = exc.args[0][0][0]
|
||||
why = exc.args[0][0][2]
|
||||
|
||||
@@ -484,7 +484,8 @@ class Installer:
|
||||
|
||||
# remove symlink
|
||||
if self.backup and not os.path.isdir(dst):
|
||||
self._backup(dst)
|
||||
if not self._backup(dst):
|
||||
return False, f'could not backup {dst}'
|
||||
overwrite = True
|
||||
try:
|
||||
removepath(dst)
|
||||
@@ -770,7 +771,8 @@ class Installer:
|
||||
overwrite = True
|
||||
|
||||
if self.backup:
|
||||
self._backup(dst)
|
||||
if not self._backup(dst):
|
||||
return False, f'could not backup {dst}'
|
||||
else:
|
||||
self.log.dbg(f'file does not exist on filesystem: {dst}')
|
||||
|
||||
@@ -869,16 +871,20 @@ class Installer:
|
||||
def _backup(self, path):
|
||||
"""backup file pointed by path"""
|
||||
if self.dry:
|
||||
return
|
||||
return True
|
||||
dst = path.rstrip(os.sep) + self.backup_suffix
|
||||
self.log.log(f'backup {path} to {dst}')
|
||||
# os.rename(path, dst)
|
||||
# copy to preserve mode on chmod=preserve
|
||||
# since we expect dotfiles this shouldn't have
|
||||
# such a big impact but who knows.
|
||||
copyfile(path, dst, debug=self.debug)
|
||||
if not copyfile(path, dst, debug=self.debug):
|
||||
return False
|
||||
if not os.path.exists(dst):
|
||||
return False
|
||||
stat = os.stat(path)
|
||||
os.chown(dst, stat.st_uid, stat.st_gid)
|
||||
return True
|
||||
|
||||
def _exec_pre_actions(self, actionexec):
|
||||
"""execute action executor"""
|
||||
|
||||
@@ -287,16 +287,18 @@ class Updater:
|
||||
self.log.dry(f'would cp -r {exist} {new}')
|
||||
continue
|
||||
self.log.dbg(f'cp -r {exist} {new}')
|
||||
cpied_cnt = 0
|
||||
try:
|
||||
ign_func = self._ignore(ignores)
|
||||
copytree_with_ign(exist, new,
|
||||
ignore_func=ign_func,
|
||||
debug=self.debug)
|
||||
cpied_cnt = copytree_with_ign(exist, new,
|
||||
ignore_func=ign_func,
|
||||
debug=self.debug)
|
||||
except OSError as exc:
|
||||
msg = f'error copying dir {exist}'
|
||||
self.log.err(f'{msg}: {exc}')
|
||||
continue
|
||||
self.log.sub(f'\"{new}\" dir added')
|
||||
if cpied_cnt:
|
||||
self.log.sub(f'\"{new}\" dir added')
|
||||
|
||||
def _ignore(self, ignores):
|
||||
def ignore_func(path):
|
||||
|
||||
@@ -303,15 +303,18 @@ def must_ignore(paths, ignores, 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):
|
||||
return
|
||||
return 0
|
||||
if not os.path.isfile(src):
|
||||
# ignore special files
|
||||
if debug:
|
||||
LOG.dbg(f'ignore special file \"{src}\"',
|
||||
force=True)
|
||||
return
|
||||
return 0
|
||||
dstdir = os.path.dirname(dst)
|
||||
if debug:
|
||||
LOG.dbg(f'mkdir \"{dstdir}\"',
|
||||
@@ -320,21 +323,29 @@ def _cp(src, dst, ignore_func=None, debug=False):
|
||||
if debug:
|
||||
LOG.dbg(f'cp {src} {dst}',
|
||||
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):
|
||||
"""
|
||||
copy file from src to dst
|
||||
no dir expected!
|
||||
returns True if file was copied
|
||||
"""
|
||||
_cp(src, dst, debug=debug)
|
||||
return _cp(src, dst, debug=debug) == 1
|
||||
|
||||
|
||||
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:
|
||||
LOG.dbg(f'copytree \"{src}\" to \"{dst}\"', force=True)
|
||||
copied_count = 0
|
||||
for entry in os.listdir(src):
|
||||
srcf = os.path.join(src, entry)
|
||||
dstf = os.path.join(dst, entry)
|
||||
@@ -346,12 +357,18 @@ def copytree_with_ign(src, dst, ignore_func=None, debug=False):
|
||||
LOG.dbg(f'mkdir \"{dstf}\"',
|
||||
force=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:
|
||||
if debug:
|
||||
LOG.dbg(f'copytree, copy file \"{src}\" to \"{dst}\"',
|
||||
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):
|
||||
|
||||
15
scripts/check-doc.sh
vendored
15
scripts/check-doc.sh
vendored
@@ -21,10 +21,15 @@ if ! which remark >/dev/null 2>&1; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "------------------------"
|
||||
echo "checking internal links"
|
||||
find . -type f -iname '*.md' | while read -r line; do
|
||||
remark -f -u validate-links "${line}"
|
||||
done
|
||||
in_cicd="${GH_WORKFLOW:-}"
|
||||
if [ -n "${in_cicd}" ]; then
|
||||
echo "------------------------"
|
||||
echo "checking internal links"
|
||||
find . -type f -iname '*.md' | while read -r line; do
|
||||
remark -f -u validate-links "${line}"
|
||||
done
|
||||
else
|
||||
echo "not checking internal links..."
|
||||
fi
|
||||
|
||||
echo "documentation OK"
|
||||
|
||||
@@ -31,6 +31,7 @@ VALID_RET = [
|
||||
]
|
||||
IGNORES = [
|
||||
'badgen.net',
|
||||
'coveralls.io',
|
||||
]
|
||||
OK_WHEN_FORBIDDEN = [
|
||||
'linux.die.net'
|
||||
|
||||
53
tests-ng/update-ignore.sh
vendored
53
tests-ng/update-ignore.sh
vendored
@@ -40,28 +40,45 @@ tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
|
||||
tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
|
||||
dt="${tmps}/dotfiles"
|
||||
mkdir -p "${dt}"
|
||||
clear_on_exit "${tmps}"
|
||||
clear_on_exit "${tmpd}"
|
||||
|
||||
# dotfiles in dotdrop
|
||||
# "a" dotfiles in dotdrop
|
||||
mkdir -p "${dt}"/a/{b,c,x}
|
||||
echo 'a' > "${dt}"/a/b/abfile
|
||||
echo 'a' > "${dt}"/a/c/acfile
|
||||
echo 'a' > "${dt}"/a/x/xfile
|
||||
|
||||
cp -r "${dt}"/a "${tmpd}"/
|
||||
# "dir" dotfiles in dotdrop
|
||||
mkdir -p "${dt}"/dir/{a,b,c}
|
||||
echo 'a' > "${dt}"/dir/a/a
|
||||
echo 'b' > "${dt}"/dir/b/b
|
||||
echo 'c' > "${dt}"/dir/c/c
|
||||
|
||||
# create destinations
|
||||
cp -r "${dt}"/a "${tmpd}"/
|
||||
cp -r "${dt}"/dir "${tmpd}"/
|
||||
|
||||
# update "a" dotdrop files
|
||||
mkdir -p "${dt}"/a/be-gone
|
||||
echo 'a' > "${dt}"/a/be-gone/file
|
||||
|
||||
# filesystem files
|
||||
# update "a" filesystem files
|
||||
touch "${tmpd}"/a/newfile
|
||||
echo 'b' > "${tmpd}"/a/c/acfile
|
||||
mkdir -p "${tmpd}"/a/newdir/b
|
||||
touch "${tmpd}"/a/newdir/b/c
|
||||
mkdir -p "${tmpd}"/a/x
|
||||
echo "b" > "${tmpd}"/a/x/xfile
|
||||
echo "c" > "${tmpd}"/a/x/yfile
|
||||
|
||||
clear_on_exit "${tmps}"
|
||||
clear_on_exit "${tmpd}"
|
||||
# update "dir" filesystem
|
||||
echo "new" > "${tmpd}"/dir/a/a
|
||||
mkdir -p "${dt}"/dir/a/be-gone
|
||||
touch "${tmpd}"/dir/newfile
|
||||
mkdir -p "${tmpd}"/dir/ignore
|
||||
echo "ignore-me" > "${tmpd}"/dir/ignore/ignore-me
|
||||
echo 'ignore-me' > "${tmpd}"/dir/ignore-file
|
||||
|
||||
# create the config file
|
||||
cfg="${tmps}/config.yaml"
|
||||
@@ -78,22 +95,38 @@ dotfiles:
|
||||
- "*/cfile"
|
||||
- "*/newfile"
|
||||
- "*/newdir"
|
||||
- "*/x/**"
|
||||
- "*/x/*"
|
||||
d_dir:
|
||||
dst: ${tmpd}/dir
|
||||
src: dir
|
||||
upignore:
|
||||
- "*/ignore/*"
|
||||
- "*/ignore-file"
|
||||
profiles:
|
||||
p1:
|
||||
dotfiles:
|
||||
- f_abc
|
||||
- d_dir
|
||||
_EOF
|
||||
|
||||
# update
|
||||
echo "[+] update"
|
||||
cd "${ddpath}" | ${bin} update -f -c "${cfg}" --verbose --profile=p1 --key f_abc
|
||||
cd "${ddpath}" | ${bin} update -f --verbose -c "${cfg}" --profile=p1
|
||||
|
||||
# check files haven't been updated
|
||||
# check "a" files are correct
|
||||
grep_or_fail 'b' "${dt}/a/c/acfile"
|
||||
grep_or_fail 'a' "${dt}/a/x/xfile"
|
||||
[ -e "${dt}"/a/newfile ] && echo "should not have been updated" && exit 1
|
||||
[ -d "${dt}"/a/be-gone ] && echo "should have been removed" && exit 1
|
||||
[ -e "${dt}"/a/newfile ] && echo "'a' newfile should have been removed" && exit 1
|
||||
[ -d "${dt}"/a/be-gone ] && echo "'a' be-gone should have been removed" && exit 1
|
||||
[ -e "${dt}"/x/yfile ] && echo "'a' yfile should not have been added" && exit 1
|
||||
|
||||
# check "dir" files are correct
|
||||
grep_or_fail 'new' "${dt}"/dir/a/a
|
||||
[ -d "${dt}"/dir/a/be-gone ] && echo "'dir' be-gone should have been removed" && exit 1
|
||||
[ ! -e "${tmpd}"/dir/newfile ] && echo "'dir' newfile should have been removed" && exit 1
|
||||
[ -d "${dt}"/dir/ignore ] && echo "'dir' ignore dir not ignored" && exit 1
|
||||
[ -f "${dt}"/dir/ignore/ignore-me ] && echo "'dir' ignore-me not ignored" && exit 1
|
||||
[ -f "${dt}"/dir/ignore-file ] && echo "'dir' ignore-file not ignored" && exit 1
|
||||
|
||||
echo "OK"
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user