1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-15 13:20:05 +00:00

Merge remote-tracking branch 'origin/fix-418'

This commit is contained in:
deadc0de6
2023-11-30 12:35:15 +01:00
7 changed files with 103 additions and 35 deletions

View File

@@ -249,15 +249,19 @@ class Importer:
if not os.path.isdir(in_fs): if not os.path.isdir(in_fs):
# is a file # is a file
self.log.dbg(f'{in_fs} is 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: else:
# is a dir # is a dir
if os.path.exists(srcf): if os.path.exists(srcf):
shutil.rmtree(srcf) shutil.rmtree(srcf)
self.log.dbg(f'{in_fs} is dir') self.log.dbg(f'{in_fs} is dir')
copytree_with_ign(in_fs, srcf, if not copytree_with_ign(in_fs, srcf,
ignore_func=self._ignore, ignore_func=self._ignore,
debug=self.debug) debug=self.debug):
self.log.err(f'importing \"{in_fs}\" failed')
return False
except shutil.Error as exc: except shutil.Error as exc:
in_dotpath = exc.args[0][0][0] in_dotpath = exc.args[0][0][0]
why = exc.args[0][0][2] why = exc.args[0][0][2]

View File

@@ -484,7 +484,8 @@ class Installer:
# remove symlink # remove symlink
if self.backup and not os.path.isdir(dst): 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 overwrite = True
try: try:
removepath(dst) removepath(dst)
@@ -770,7 +771,8 @@ class Installer:
overwrite = True overwrite = True
if self.backup: if self.backup:
self._backup(dst) if not self._backup(dst):
return False, f'could not backup {dst}'
else: else:
self.log.dbg(f'file does not exist on filesystem: {dst}') self.log.dbg(f'file does not exist on filesystem: {dst}')
@@ -869,16 +871,20 @@ class Installer:
def _backup(self, path): def _backup(self, path):
"""backup file pointed by path""" """backup file pointed by path"""
if self.dry: if self.dry:
return return True
dst = path.rstrip(os.sep) + self.backup_suffix dst = path.rstrip(os.sep) + self.backup_suffix
self.log.log(f'backup {path} to {dst}') self.log.log(f'backup {path} to {dst}')
# os.rename(path, dst) # os.rename(path, dst)
# copy to preserve mode on chmod=preserve # copy to preserve mode on chmod=preserve
# since we expect dotfiles this shouldn't have # since we expect dotfiles this shouldn't have
# such a big impact but who knows. # 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) stat = os.stat(path)
os.chown(dst, stat.st_uid, stat.st_gid) os.chown(dst, stat.st_uid, stat.st_gid)
return True
def _exec_pre_actions(self, actionexec): def _exec_pre_actions(self, actionexec):
"""execute action executor""" """execute action executor"""

View File

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

View File

@@ -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,21 +323,29 @@ 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):
""" """
copy file from src to dst copy file from src to dst
no dir expected! 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): 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 +357,18 @@ 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):

15
scripts/check-doc.sh vendored
View File

@@ -21,10 +21,15 @@ if ! which remark >/dev/null 2>&1; then
exit 1 exit 1
fi fi
echo "------------------------" in_cicd="${GH_WORKFLOW:-}"
echo "checking internal links" if [ -n "${in_cicd}" ]; then
find . -type f -iname '*.md' | while read -r line; do echo "------------------------"
remark -f -u validate-links "${line}" echo "checking internal links"
done 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" echo "documentation OK"

View File

@@ -31,6 +31,7 @@ VALID_RET = [
] ]
IGNORES = [ IGNORES = [
'badgen.net', 'badgen.net',
'coveralls.io',
] ]
OK_WHEN_FORBIDDEN = [ OK_WHEN_FORBIDDEN = [
'linux.die.net' 'linux.die.net'

View File

@@ -40,28 +40,45 @@ tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d) tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
dt="${tmps}/dotfiles" dt="${tmps}/dotfiles"
mkdir -p "${dt}" 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} mkdir -p "${dt}"/a/{b,c,x}
echo 'a' > "${dt}"/a/b/abfile echo 'a' > "${dt}"/a/b/abfile
echo 'a' > "${dt}"/a/c/acfile echo 'a' > "${dt}"/a/c/acfile
echo 'a' > "${dt}"/a/x/xfile 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 mkdir -p "${dt}"/a/be-gone
echo 'a' > "${dt}"/a/be-gone/file echo 'a' > "${dt}"/a/be-gone/file
# filesystem files # update "a" filesystem files
touch "${tmpd}"/a/newfile touch "${tmpd}"/a/newfile
echo 'b' > "${tmpd}"/a/c/acfile echo 'b' > "${tmpd}"/a/c/acfile
mkdir -p "${tmpd}"/a/newdir/b mkdir -p "${tmpd}"/a/newdir/b
touch "${tmpd}"/a/newdir/b/c touch "${tmpd}"/a/newdir/b/c
mkdir -p "${tmpd}"/a/x mkdir -p "${tmpd}"/a/x
echo "b" > "${tmpd}"/a/x/xfile echo "b" > "${tmpd}"/a/x/xfile
echo "c" > "${tmpd}"/a/x/yfile
clear_on_exit "${tmps}" # update "dir" filesystem
clear_on_exit "${tmpd}" 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 # create the config file
cfg="${tmps}/config.yaml" cfg="${tmps}/config.yaml"
@@ -78,22 +95,38 @@ dotfiles:
- "*/cfile" - "*/cfile"
- "*/newfile" - "*/newfile"
- "*/newdir" - "*/newdir"
- "*/x/**" - "*/x/*"
d_dir:
dst: ${tmpd}/dir
src: dir
upignore:
- "*/ignore/*"
- "*/ignore-file"
profiles: profiles:
p1: p1:
dotfiles: dotfiles:
- f_abc - f_abc
- d_dir
_EOF _EOF
# update # update
echo "[+] 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 'b' "${dt}/a/c/acfile"
grep_or_fail 'a' "${dt}/a/x/xfile" grep_or_fail 'a' "${dt}/a/x/xfile"
[ -e "${dt}"/a/newfile ] && echo "should not have been updated" && exit 1 [ -e "${dt}"/a/newfile ] && echo "'a' newfile should have been removed" && exit 1
[ -d "${dt}"/a/be-gone ] && echo "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" echo "OK"
exit 0 exit 0