summaryrefslogtreecommitdiffstats
path: root/prebuilt
diff options
context:
space:
mode:
authorGabriele M <moto.falcon.git@gmail.com>2017-02-27 15:44:17 +0100
committerJason Riordan <jriordan001@gmail.com>2017-02-27 23:33:02 -0500
commit52996421a116965bff6b7b58bd99693b4ef02d23 (patch)
tree548b52322ae272d2be130324aac63a3b23b05be4 /prebuilt
parentcf276aa7cda379b93a38f8e6251fa4fe51eb96d9 (diff)
downloadvendor_replicant-52996421a116965bff6b7b58bd99693b4ef02d23.zip
vendor_replicant-52996421a116965bff6b7b58bd99693b4ef02d23.tar.gz
vendor_replicant-52996421a116965bff6b7b58bd99693b4ef02d23.tar.bz2
backuptool: Preserve the SELinux context of the files
Add a function that allows to copy files preserving their SELinux context that is generic enough to work with both busybox and toybox. Change-Id: If2c245863df5675c18dbf43b6bcedeb33383fc38
Diffstat (limited to 'prebuilt')
-rw-r--r--prebuilt/common/bin/backuptool.functions14
1 files changed, 12 insertions, 2 deletions
diff --git a/prebuilt/common/bin/backuptool.functions b/prebuilt/common/bin/backuptool.functions
index d9b2fc0..8a372a3 100644
--- a/prebuilt/common/bin/backuptool.functions
+++ b/prebuilt/common/bin/backuptool.functions
@@ -7,6 +7,16 @@ export C=/tmp/backupdir
export S=/system
export V=13.0
+copy_file() {
+ cp -dp "$1" "$2"
+ # symlinks don't have a context
+ if [ ! -L "$1" ]; then
+ # it is assumed that every label starts with 'u:object_r' and has no white-spaces
+ local context=`ls -Z "$1" | grep -o 'u:object_r:[^ ]*' | head -1`
+ chcon "$context" "$2"
+ fi
+}
+
backup_file() {
if [ -e "$1" -o -L "$1" ]; then
local F=`basename "$1"`
@@ -16,7 +26,7 @@ backup_file() {
echo "Skipping odexed apk $1";
else
mkdir -p "$C/$D"
- cp -p $1 "$C/$D/$F"
+ copy_file "$1" "$C/$D/$F"
fi
fi
}
@@ -28,7 +38,7 @@ restore_file() {
if [ ! -d "$DIR" ]; then
mkdir -p "$DIR";
fi
- cp -p "$C/$DIR/$FILE" "$1";
+ copy_file "$C/$DIR/$FILE" "$1";
if [ -n "$2" ]; then
echo "Deleting obsolete file $2"
rm "$2";