diff --git a/dotdrop/comparator.py b/dotdrop/comparator.py index c6e5db4..119ee79 100644 --- a/dotdrop/comparator.py +++ b/dotdrop/comparator.py @@ -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 '' diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 4fbe6db..69a0af9 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -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: diff --git a/tests-ng/chmod-compare.sh b/tests-ng/chmod-compare.sh index 3bc1155..035227f 100755 --- a/tests-ng/chmod-compare.sh +++ b/tests-ng/chmod-compare.sh @@ -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} diff --git a/tests-ng/chmod-install.sh b/tests-ng/chmod-install.sh index 9fcd341..ed95794 100755 --- a/tests-ng/chmod-install.sh +++ b/tests-ng/chmod-install.sh @@ -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 diff --git a/tests.sh b/tests.sh index d35bdb8..de4738b 100755 --- a/tests.sh +++ b/tests.sh @@ -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