mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 06:09:17 +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.updater import Updater
|
||||||
from dotdrop.comparator import Comparator
|
from dotdrop.comparator import Comparator
|
||||||
from dotdrop.utils import get_tmpdir, removepath, strip_home, \
|
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.linktypes import LinkTypes
|
||||||
from dotdrop.exceptions import YamlException, UndefinedException
|
from dotdrop.exceptions import YamlException, UndefinedException
|
||||||
|
|
||||||
@@ -521,7 +522,8 @@ def cmd_importer(o):
|
|||||||
shutil.copy2(dst, srcf)
|
shutil.copy2(dst, srcf)
|
||||||
|
|
||||||
chmod = None
|
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
|
# insert chmod
|
||||||
chmod = perm
|
chmod = perm
|
||||||
retconf = o.conf.new(src, dst, linktype, chmod=chmod)
|
retconf = o.conf.new(src, dst, linktype, chmod=chmod)
|
||||||
|
|||||||
@@ -312,6 +312,14 @@ def get_umask():
|
|||||||
return cur
|
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):
|
def get_file_perm(path):
|
||||||
"""return file permission"""
|
"""return file permission"""
|
||||||
return os.stat(path).st_mode & 0o777
|
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
|
# 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
|
# the dotfile source
|
||||||
tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
|
tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
|
||||||
mkdir -p ${tmps}/dotfiles
|
mkdir -p ${tmps}/dotfiles
|
||||||
@@ -155,7 +168,7 @@ mkdir -p ${tmps}/dotfiles
|
|||||||
|
|
||||||
# import with --preserve-mode
|
# import with --preserve-mode
|
||||||
for i in ${toimport}; do
|
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}
|
cd ${ddpath} | ${bin} import -c ${cfg} -m -f -p p1 -V ${i}
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -182,9 +195,9 @@ _EOF
|
|||||||
rm -rf ${tmps}/dotfiles
|
rm -rf ${tmps}/dotfiles
|
||||||
mkdir -p ${tmps}/dotfiles
|
mkdir -p ${tmps}/dotfiles
|
||||||
|
|
||||||
# import with --preserve-mode
|
# import without --preserve-mode
|
||||||
for i in ${toimport}; do
|
for i in ${toimport}; do
|
||||||
chmod `umask -S` ${i}
|
chmod_to_umask ${i}
|
||||||
cd ${ddpath} | ${bin} import -c ${cfg} -f -p p1 -V ${i}
|
cd ${ddpath} | ${bin} import -c ${cfg} -f -p p1 -V ${i}
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user