Skip to content

Commit

Permalink
force_chmod as global option to the installer
Browse files Browse the repository at this point in the history
  • Loading branch information
deadc0de6 committed Dec 31, 2023
1 parent b7003a7 commit bd66f24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
12 changes: 6 additions & 6 deletions dotdrop/dotdrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def _dotfile_compare(opts, dotfile, tmp):
dry=opts.dry, base=opts.dotpath,
workdir=opts.workdir, debug=opts.debug,
backup_suffix=opts.install_backup_suffix,
diff_cmd=opts.diff_command)
diff_cmd=opts.diff_command,
force_chmod=True)
comp = Comparator(diff_cmd=opts.diff_command, debug=opts.debug,
ignore_missing_in_dotdrop=ignore_missing_in_dotdrop)

Expand Down Expand Up @@ -234,8 +235,7 @@ def _dotfile_install(opts, dotfile, tmpdir=None):
actionexec=pre_actions_exec,
is_template=is_template,
ignore=ignores,
chmod=dotfile.chmod,
force_chmod=opts.install_force_chmod)
chmod=dotfile.chmod)
else:
# nolink
src = dotfile.src
Expand All @@ -254,8 +254,7 @@ def _dotfile_install(opts, dotfile, tmpdir=None):
noempty=dotfile.noempty,
ignore=ignores,
is_template=is_template,
chmod=dotfile.chmod,
force_chmod=opts.install_force_chmod)
chmod=dotfile.chmod)
if tmp:
tmp = os.path.join(opts.dotpath, tmp)
if os.path.exists(tmp):
Expand Down Expand Up @@ -765,7 +764,8 @@ def _get_install_installer(opts, tmpdir=None):
showdiff=opts.install_showdiff,
backup_suffix=opts.install_backup_suffix,
diff_cmd=opts.diff_command,
remove_existing_in_dir=opts.install_remove_existing)
remove_existing_in_dir=opts.install_remove_existing,
force_chmod=opts.install_force_chmod)
return inst


Expand Down
11 changes: 5 additions & 6 deletions dotdrop/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, base='.', create=True, backup=True,
dry=False, safe=False, workdir='~/.config/dotdrop',
debug=False, diff=True, totemp=None, showdiff=False,
backup_suffix='.dotdropbak', diff_cmd='',
remove_existing_in_dir=False):
remove_existing_in_dir=False, force_chmod=False):
"""
@base: directory path where to search for templates
@create: create directory hierarchy if missing when installing
Expand All @@ -45,6 +45,7 @@ def __init__(self, base='.', create=True, backup=True,
@diff_cmd: diff command to use
@remove_existing_in_dir: remove file in dir dotfiles
if not managed by dotdrop
@force_chmod: apply chmod without confirmation
"""
self.create = create
self.backup = backup
Expand All @@ -64,6 +65,7 @@ def __init__(self, base='.', create=True, backup=True,
self.diff_cmd = diff_cmd
self.action_executed = False
self.remove_existing_in_dir = remove_existing_in_dir
self.force_chmod = force_chmod
# avoids printing file copied logs
# when using install_to_tmp for comparing
self.comparing = False
Expand All @@ -77,7 +79,7 @@ def __init__(self, base='.', create=True, backup=True,
def install(self, templater, src, dst, linktype,
actionexec=None, noempty=False,
ignore=None, is_template=True,
chmod=None, force_chmod=False):
chmod=None):
"""
install src to dst
Expand All @@ -90,7 +92,6 @@ def install(self, templater, src, dst, linktype,
@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
Expand Down Expand Up @@ -189,15 +190,13 @@ def install(self, templater, src, dst, linktype,

self._apply_chmod_after_install(src, dst, ret, err,
chmod=chmod,
force_chmod=force_chmod,
linktype=linktype)

return self._log_install(ret, err)

def _apply_chmod_after_install(self, src, dst, ret, err,
chmod=None,
is_sub=False,
force_chmod=False,
linktype=LinkTypes.NOLINK):
"""
handle chmod after install
Expand Down Expand Up @@ -227,7 +226,7 @@ def _apply_chmod_after_install(self, src, dst, ret, err,
if dstperms != chmod:
# apply mode
msg = f'chmod {dst} to {chmod:o}'
if not force_chmod and self.safe and not self.log.ask(msg):
if not self.force_chmod and self.safe and not self.log.ask(msg):
ret = False
err = 'aborted'
else:
Expand Down

0 comments on commit bd66f24

Please sign in to comment.