diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 9ae4022..32f957c 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -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) diff --git a/dotdrop/utils.py b/dotdrop/utils.py index a2fdba0..d8f77b8 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -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 diff --git a/tests-ng/chmod-import.sh b/tests-ng/chmod-import.sh index 5845f90..054a0c0 100755 --- a/tests-ng/chmod-import.sh +++ b/tests-ng/chmod-import.sh @@ -47,6 +47,19 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename $BASH_SOURCE) <==$(tput sgr0)" # this is the test ################################################################ +# $1 file +chmod_to_umask() +{ + u=`umask` + u=`echo ${u} | sed 's/^0*//'` + if [ -d ${1} ]; then + v=$((777 - u)) + else + v=$((666 - u)) + fi + chmod ${v} ${1} +} + # the dotfile source tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d` mkdir -p ${tmps}/dotfiles @@ -155,7 +168,7 @@ mkdir -p ${tmps}/dotfiles # import with --preserve-mode for i in ${toimport}; do - chmod `umask -S` ${i} + chmod_to_umask ${i} cd ${ddpath} | ${bin} import -c ${cfg} -m -f -p p1 -V ${i} done @@ -182,9 +195,9 @@ _EOF rm -rf ${tmps}/dotfiles mkdir -p ${tmps}/dotfiles -# import with --preserve-mode +# import without --preserve-mode for i in ${toimport}; do - chmod `umask -S` ${i} + chmod_to_umask ${i} cd ${ddpath} | ${bin} import -c ${cfg} -f -p p1 -V ${i} done