1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 14:31:46 +00:00

fix chmod compare bug

This commit is contained in:
deadc0de6
2022-05-26 21:13:39 +02:00
committed by deadc0de
parent 93e33a4d9a
commit 8938cbd602
5 changed files with 36 additions and 9 deletions

View File

@@ -28,9 +28,12 @@ class Comparator:
self.log = Logger(debug=self.debug)
self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop
def compare(self, local_path, deployed_path, ignore=None):
"""diff local_path (dotdrop dotfile) and
deployed_path (destination file)"""
def compare(self, local_path, deployed_path, ignore=None, mode=None):
"""
diff local_path (dotdrop dotfile) and
deployed_path (destination file)
If mode is None, rights will be read from local_path
"""
if not ignore:
ignore = []
local_path = os.path.expanduser(local_path)
@@ -58,19 +61,24 @@ class Comparator:
self.log.dbg('{} is a file'.format(local_path))
ret = self._comp_file(local_path, deployed_path, ignore)
if not ret:
ret = self._comp_mode(local_path, deployed_path)
ret = self._comp_mode(local_path, deployed_path, mode=mode)
return ret
self.log.dbg('{} is a directory'.format(local_path))
ret = self._comp_dir(local_path, deployed_path, ignore)
if not ret:
ret = self._comp_mode(local_path, deployed_path)
ret = self._comp_mode(local_path, deployed_path, mode=mode)
return ret
def _comp_mode(self, local_path, deployed_path):
"""compare mode"""
local_mode = get_file_perm(local_path)
def _comp_mode(self, local_path, deployed_path, mode=None):
"""
compare mode
If mode is None, rights will be read on local_path
"""
local_mode = mode
if not local_mode:
local_mode = get_file_perm(local_path)
deployed_mode = get_file_perm(deployed_path)
if local_mode == deployed_mode:
return ''

View File

@@ -158,7 +158,7 @@ def _dotfile_compare(opts, dotfile, tmp):
# compare
# need to be executed before cleaning
diff = comp.compare(src, dotfile.dst, ignore=ignores)
diff = comp.compare(src, dotfile.dst, ignore=ignores, mode=dotfile.chmod)
# clean tmp transformed dotfile if any
if tmpsrc:

View File

@@ -82,6 +82,9 @@ flink="${tmpd}/filelink"
echo "filelink" > ${flink}
chmod 777 ${flink}
echo "f777" > ${tmps}/dotfiles/f777
chmod 700 ${tmps}/dotfiles/f777
toimport="${dnormal} ${dlink} ${dlinkchildren} ${fnormal} ${flink}"
# create the config file
@@ -93,10 +96,23 @@ config:
create: true
dotpath: dotfiles
dotfiles:
f_f777:
src: f777
dst: ${tmpd}/f777
chmod: 777
profiles:
p1:
dotfiles:
- f_f777
_EOF
#cat ${cfg}
# install
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1
# compare
cd ${ddpath} | ${bin} compare -c ${cfg} -p p1
# import
for i in ${toimport}; do
cd ${ddpath} | ${bin} import -c ${cfg} -f -p p1 ${i}

View File

@@ -88,6 +88,7 @@ clear_on_exit "${tmpd}"
cfg="${tmps}/config.yaml"
echo 'f777' > ${tmps}/dotfiles/f777
chmod 700 ${tmps}/dotfiles/f777
echo 'link' > ${tmps}/dotfiles/link
mkdir -p ${tmps}/dotfiles/dir
echo "f1" > ${tmps}/dotfiles/dir/f1

View File

@@ -84,6 +84,8 @@ if [ ! -z ${workers} ]; then
fi
# run bash tests
export DOTDROP_DEBUG="yes"
unset DOTDROP_FORCE_NODEBUG
workdir_tmp_exists="no"
[ -d "~/.config/dotdrop/tmp" ] && workdir_tmp_exists="yes"
if [ -z ${GITHUB_WORKFLOW} ]; then