From 6474a48961ef3be0c572b740f2a48834996871b3 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Fri, 29 May 2020 10:58:33 +0200 Subject: [PATCH] fix patch rights issue for #234 --- dotdrop/updater.py | 6 +++--- dotdrop/utils.py | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/dotdrop/updater.py b/dotdrop/updater.py index 188882f..67b9f6a 100644 --- a/dotdrop/updater.py +++ b/dotdrop/updater.py @@ -13,7 +13,7 @@ import filecmp from dotdrop.logger import Logger from dotdrop.templategen import Templategen from dotdrop.utils import patch_ignores, remove, get_unique_tmp_name, \ - write_to_tmpfile, must_ignore + write_to_tmpfile, must_ignore, mirror_file_rights TILD = '~' @@ -148,6 +148,7 @@ class Updater: """provide a way to manually patch the template""" content = self._resolve_template(tpath) tmp = write_to_tmpfile(content) + mirror_file_rights(tpath, tmp) cmds = ['diff', '-u', tmp, fpath, '|', 'patch', tpath] self.log.warn('try patching with: \"{}\"'.format(' '.join(cmds))) return False @@ -169,8 +170,7 @@ class Updater: def _mirror_rights(self, src, dst): try: - rights = os.stat(src).st_mode - os.chmod(dst, rights) + mirror_file_rights(src, dst) except OSError as e: self.log.err(e) diff --git a/dotdrop/utils.py b/dotdrop/utils.py index ee1a65d..9c43432 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -233,3 +233,9 @@ def dependencies_met(): for dep in deps: if not which(dep): raise Exception(err.format(dep)) + + +def mirror_file_rights(src, dst): + """mirror file rights of src to dst (can rise exc)""" + rights = os.stat(src).st_mode + os.chmod(dst, rights)