diff --git a/docs/config-format.md b/docs/config-format.md index ffb93a5..77ae943 100644 --- a/docs/config-format.md +++ b/docs/config-format.md @@ -13,6 +13,7 @@ Entry | Description | Default -------- | ------------- | ------------ `backup` | Create a backup of the dotfile in case it differs from the one that will be installed by dotdrop | true `banner` | Display the banner | true +`chmod_on_import` | Always add a chmod entry on newly imported dotfiles (see `--preserve-mode`) | false `cmpignore` | List of patterns to ignore when comparing, applied to all dotfiles (enclose in quotes when using wildcards; see [ignore patterns](config.md#ignore-patterns)) | - `create` | Create a directory hierarchy when installing dotfiles if it doesn't exist | true `default_actions` | List of action keys to execute for all installed dotfiles (See [actions](config-details.md#actions-entry)) | - diff --git a/docs/config.md b/docs/config.md index eea13c9..14fd656 100644 --- a/docs/config.md +++ b/docs/config.md @@ -86,7 +86,8 @@ dotfiles: On `import`, the following rules are applied: -* If the `-m`/`--preserve-mode` switch is provided, the imported file's permissions are +* If the `-m`/`--preserve-mode` switch is provided or the config option + `chmod_on_import` is true, the imported file's permissions are stored in a `chmod` entry * If the imported file's permissions differ from the umask, then the permissions are automatically stored in the `chmod` entry. diff --git a/dotdrop/options.py b/dotdrop/options.py index 276f0e9..6ad7892 100644 --- a/dotdrop/options.py +++ b/dotdrop/options.py @@ -130,6 +130,7 @@ class Options(AttrMonitor): self.impignore = None self.upignore = None self.link_on_import = None + self.chmod_on_import = None # args parsing self.args = {} @@ -258,7 +259,7 @@ class Options(AttrMonitor): """import specifics""" self.import_path = self.args[''] self.import_as = self.args['--as'] - self.import_mode = self.args['--preserve-mode'] + self.import_mode = self.args['--preserve-mode'] or self.chmod_on_import self.import_ignore = self.args['--ignore'] self.import_ignore.extend(self.impignore) self.import_ignore.append('*{}'.format(self.install_backup_suffix)) diff --git a/dotdrop/settings.py b/dotdrop/settings.py index 7827b9b..2eafe3f 100644 --- a/dotdrop/settings.py +++ b/dotdrop/settings.py @@ -44,6 +44,7 @@ class Settings(DictParser): key_force_chmod = 'force_chmod' key_template_dotfile_default = 'template_dotfile_default' key_ignore_missing_in_dotdrop = 'ignore_missing_in_dotdrop' + key_chmod_on_import = 'chmod_on_import' # import keys key_import_actions = 'import_actions' @@ -63,7 +64,8 @@ class Settings(DictParser): diff_command='diff -r -u {0} {1}', template_dotfile_default=True, ignore_missing_in_dotdrop=False, - force_chmod=False): + force_chmod=False, + chmod_on_import=False): self.backup = backup self.banner = banner self.create = create @@ -92,6 +94,7 @@ class Settings(DictParser): self.template_dotfile_default = template_dotfile_default self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop self.force_chmod = force_chmod + self.chmod_on_import = chmod_on_import def _serialize_seq(self, name, dic): """serialize attribute 'name' into 'dic'""" @@ -116,7 +119,8 @@ class Settings(DictParser): self.key_diff_command: self.diff_command, self.key_template_dotfile_default: self.template_dotfile_default, self.key_ignore_missing_in_dotdrop: self.ignore_missing_in_dotdrop, - self.key_force_chmod: self.force_chmod + self.key_force_chmod: self.force_chmod, + self.key_chmod_on_import: self.chmod_on_import, } self._serialize_seq(self.key_default_actions, dic) self._serialize_seq(self.key_import_actions, dic) diff --git a/tests-ng/chmod-import.sh b/tests-ng/chmod-import.sh index 6d1a5da..cb810eb 100755 --- a/tests-ng/chmod-import.sh +++ b/tests-ng/chmod-import.sh @@ -212,6 +212,37 @@ cd ${ddpath} | ${bin} detail -c ${cfg} -p p1 -V cnt=`cat ${cfg} | grep chmod | wc -l` [ "${cnt}" != "0" ] && echo "chmod inserted but not needed" && exit 1 +## with config option chmod_on_import +cat > ${cfg} << _EOF +config: + backup: true + create: true + dotpath: dotfiles + chmod_on_import: true +dotfiles: +profiles: +_EOF + +# clean +rm -rf ${tmps}/dotfiles +mkdir -p ${tmps}/dotfiles + +# import +for i in ${toimport}; do + chmod_to_umask ${i} + cd ${ddpath} | ${bin} import -c ${cfg} -f -p p1 -V ${i} +done + +cat ${cfg} + +# list files +cd ${ddpath} | ${bin} detail -c ${cfg} -p p1 -V + +cat ${cfg} +tot=`echo ${toimport} | wc -w` +cnt=`cat ${cfg} | grep "chmod: " | wc -l` +[ "${cnt}" != "${tot}" ] && echo "not all chmod inserted (3)" && exit 1 + ## CLEANING rm -rf ${tmps} ${tmpd}