mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-05 06:13:49 +00:00
properly handle chmod on import
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user