1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-06 02:02:58 +00:00

properly handle chmod on import

This commit is contained in:
deadc0de6
2020-11-14 12:13:08 +01:00
parent 15617ceaea
commit 32e667a59b
3 changed files with 28 additions and 5 deletions

View File

@@ -19,7 +19,8 @@ from dotdrop.installer import Installer
from dotdrop.updater import Updater
from dotdrop.comparator import Comparator
from dotdrop.utils import get_tmpdir, removepath, strip_home, \
uniq_list, patch_ignores, dependencies_met, get_file_perm
uniq_list, patch_ignores, dependencies_met, get_file_perm, \
get_default_file_perms
from dotdrop.linktypes import LinkTypes
from dotdrop.exceptions import YamlException, UndefinedException
@@ -521,7 +522,8 @@ def cmd_importer(o):
shutil.copy2(dst, srcf)
chmod = None
if o.import_mode or perm & o.umask:
dflperm = get_default_file_perms(dst, o.umask)
if o.import_mode or perm != dflperm:
# insert chmod
chmod = perm
retconf = o.conf.new(src, dst, linktype, chmod=chmod)

View File

@@ -312,6 +312,14 @@ def get_umask():
return cur
def get_default_file_perms(path, umask):
"""get default rights for a file"""
base = 0o666
if os.path.isdir(path):
base = 0o777
return base - umask
def get_file_perm(path):
"""return file permission"""
return os.stat(path).st_mode & 0o777