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

fix mirror rights on update

This commit is contained in:
deadc0de6
2020-11-14 13:12:52 +01:00
parent 458b6a0bf1
commit 81d585a37f
2 changed files with 13 additions and 6 deletions

View File

@@ -13,7 +13,7 @@ import filecmp
from dotdrop.logger import Logger
from dotdrop.templategen import Templategen
from dotdrop.utils import patch_ignores, removepath, get_unique_tmp_name, \
write_to_tmpfile, must_ignore, mirror_file_rights
write_to_tmpfile, must_ignore, mirror_file_rights, get_file_perm
from dotdrop.exceptions import UndefinedException
@@ -162,15 +162,20 @@ class Updater:
def _same_rights(self, left, right):
"""return True if files have the same modes"""
try:
lefts = os.stat(left)
rights = os.stat(right)
return lefts.st_mode == rights.st_mode
lefts = get_file_perm(left)
rights = get_file_perm(right)
return lefts == rights
except OSError as e:
self.log.err(e)
return False
def _mirror_rights(self, src, dst):
try:
if self.debug:
srcr = get_file_perm(src)
dstr = get_file_perm(dst)
msg = 'copy rights from {} ({:o}) to {} ({:o})'
self.log.dbg(msg.format(src, srcr, dst, dstr))
mirror_file_rights(src, dst)
except OSError as e:
self.log.err(e)
@@ -228,7 +233,9 @@ class Updater:
# find the differences
diff = filecmp.dircmp(path, dtpath, ignore=None)
# handle directories diff
return self._merge_dirs(diff)
ret = self._merge_dirs(diff)
self._mirror_rights(path, dtpath)
return ret
def _merge_dirs(self, diff):
"""Synchronize directories recursively."""

View File

@@ -300,7 +300,7 @@ def dependencies_met():
def mirror_file_rights(src, dst):
"""mirror file rights of src to dst (can rise exc)"""
rights = os.stat(src).st_mode
rights = get_file_perm(src)
os.chmod(dst, rights)