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

add force_chmod for #304

This commit is contained in:
deadc0de6
2021-03-15 07:49:09 +01:00
parent faa7846155
commit 82569b3057
8 changed files with 23 additions and 9 deletions

View File

@@ -19,6 +19,7 @@ Entry | Description | Default
`diff_command` | the diff command to use for diffing files | `diff -r -u {0} {1}`
`dotpath` | path to the directory containing the dotfiles to be managed by dotdrop (absolute path or relative to the config file location) | `dotfiles`
`filter_file` | list of paths to load templating filters from (see [Templating available filters](templating.md#template-filters)) | -
`force_chmod` | if true, do not ask confirmation to apply permissions on install | `false`
`func_file` | list of paths to load templating functions from (see [Templating available methods](templating.md#template-methods)) | -
`ignore_missing_in_dotdrop` | ignore missing files in dotdrop when comparing and importing (see [Ignore missing](usage.md#ignore-missing)) | false
`ignoreempty` | do not deploy template if empty | false

View File

@@ -91,12 +91,15 @@ On `install` the following rules are applied:
* if `chmod` is specified in the dotfile, it will be applied to the installed dotfile
* otherwise the permissions of the dotfile in the `dotpath` are applied.
* if the global setting `force_chmod` is set to true dotdrop will not ask
for confirmation to apply permission
On `update`:
* if the permissions of the file in the filesystem differ from the dotfile in the `dotpath`
then the dotfile entry `chmod` is added/updated accordingly
## Symlink dotfiles
Dotdrop is able to install dotfiles in three different ways

View File

@@ -59,7 +59,6 @@ class CfgYaml:
key_dotfile_noempty = 'ignoreempty'
key_dotfile_template = 'template'
key_dotfile_chmod = 'chmod'
key_dotfile_ignore_missing = 'ignore_missing_in_dotdrop'
# profile
key_profile_dotfiles = 'dotfiles'

View File

@@ -226,7 +226,8 @@ def _dotfile_install(o, dotfile, tmpdir=None):
actionexec=pre_actions_exec,
is_template=is_template,
ignore=ignores,
chmod=dotfile.chmod)
chmod=dotfile.chmod,
force_chmod=o.install_force_chmod)
elif hasattr(dotfile, 'link') and \
dotfile.link == LinkTypes.LINK_CHILDREN:
# link_children
@@ -235,7 +236,8 @@ def _dotfile_install(o, dotfile, tmpdir=None):
actionexec=pre_actions_exec,
is_template=is_template,
chmod=dotfile.chmod,
ignore=ignores)
ignore=ignores,
force_chmod=o.install_force_chmod)
else:
# nolink
src = dotfile.src
@@ -256,7 +258,8 @@ def _dotfile_install(o, dotfile, tmpdir=None):
noempty=dotfile.noempty,
ignore=ignores,
is_template=is_template,
chmod=dotfile.chmod)
chmod=dotfile.chmod,
force_chmod=o.install_force_chmod)
if tmp:
tmp = os.path.join(o.dotpath, tmp)
if os.path.exists(tmp):

View File

@@ -66,7 +66,7 @@ class Installer:
def install(self, templater, src, dst, linktype,
actionexec=None, noempty=False,
ignore=[], is_template=True,
chmod=None):
chmod=None, force_chmod=False):
"""
install src to dst
@@ -79,6 +79,7 @@ class Installer:
@ignore: pattern to ignore when installing
@is_template: this dotfile is a template
@chmod: rights to apply if any
@force_chmod: do not ask user to chmod
return
- True, None : success
@@ -171,7 +172,7 @@ class Installer:
if dstperms != chmod:
# apply mode
msg = 'chmod {} to {:o}'.format(dst, chmod)
if self.safe and not self.log.ask(msg):
if not force_chmod and self.safe and not self.log.ask(msg):
r = False
err = 'aborted'
else:

View File

@@ -257,6 +257,7 @@ class Options(AttrMonitor):
self.install_default_actions_post = [a for a in self.default_actions
if a.kind == Action.post]
self.install_ignore = self.instignore
self.install_force_chmod = self.force_chmod
# "compare" specifics
self.compare_focus = self.args['--file']

View File

@@ -40,6 +40,7 @@ class Settings(DictParser):
key_func_file = 'func_file'
key_filter_file = 'filter_file'
key_diff_command = 'diff_command'
key_force_chmod = 'force_chmod'
key_template_dotfile_default = 'template_dotfile_default'
key_ignore_missing_in_dotdrop = 'ignore_missing_in_dotdrop'
@@ -59,7 +60,8 @@ class Settings(DictParser):
minversion=None, func_file=[], filter_file=[],
diff_command='diff -r -u {0} {1}',
template_dotfile_default=True,
ignore_missing_in_dotdrop=False):
ignore_missing_in_dotdrop=False,
force_chmod=False):
self.backup = backup
self.banner = banner
self.create = create
@@ -87,6 +89,7 @@ class Settings(DictParser):
self.diff_command = diff_command
self.template_dotfile_default = template_dotfile_default
self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop
self.force_chmod = force_chmod
def _serialize_seq(self, name, dic):
"""serialize attribute 'name' into 'dic'"""
@@ -111,6 +114,7 @@ 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._serialize_seq(self.key_default_actions, dic)
self._serialize_seq(self.key_import_actions, dic)

View File

@@ -121,6 +121,7 @@ config:
backup: true
create: true
dotpath: dotfiles
force_chmod: true
dotfiles:
f_f777:
src: f777
@@ -191,7 +192,8 @@ _EOF
# install
echo "first install round"
cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 -V
#cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 -V
cd ${ddpath} | ${bin} install -c ${cfg} -p p1 -V
has_rights "${tmpd}/f777" "777"
has_rights "${tmpd}/link" "777"