backuptool_ab: Make copy_file preserve file/directory attrs
Change-Id: I52c7b124ff8364464643c51b3f17dba4e4e49435
diff --git a/prebuilt/common/bin/backuptool_ab.functions b/prebuilt/common/bin/backuptool_ab.functions
index 1d1fb86..82ce70b 100644
--- a/prebuilt/common/bin/backuptool_ab.functions
+++ b/prebuilt/common/bin/backuptool_ab.functions
@@ -9,40 +9,28 @@
export backuptool_ab=true
copy_file() {
- # toybox's cp doesn't do directories correctly for whatever reason
- mkdir -p `dirname $2`
+ old=`umask`
+ umask 0322
+ mkdir -m755 -p `dirname $2`
+ umask "$old"
- 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
+ cp -dp --preserve=a "$1" "$2"
}
backup_file() {
if [ -e "$1" -o -L "$1" ]; then
- local FILE=`basename "$1"`
- local DIR=`dirname "$1"`
# dont backup any apps that have odex files, they are useless
- if ( echo "$FILE" | grep -q "\.apk$" ) && [ -e `echo "$1" | sed -e 's/\.apk$/\.odex/'` ]; then
+ if ( echo "$1" | grep -q "\.apk$" ) && [ -e `echo "$1" | sed -e 's/\.apk$/\.odex/'` ]; then
echo "Skipping odexed apk $1";
else
- mkdir -p "$C/$DIR"
- copy_file "$1" "$C/$DIR/$FILE"
+ copy_file "$1" "$C/$1"
fi
fi
}
restore_file() {
- local FILE=`basename "$1"`
- local DIR=`dirname "$1"`
- if [ -e "$C/$DIR/$FILE" -o -L "$C/$DIR/$FILE" ]; then
- if [ ! -d "/postinstall/$DIR" ]; then
- mkdir -p "/postinstall/$DIR";
- fi
- copy_file "$C/$DIR/$FILE" "/postinstall/$1";
+ if [ -e "$C/$1" -o -L "$C/$1" ]; then
+ copy_file "$C/$1" "/postinstall/$1";
if [ -n "$2" ]; then
echo "Deleting obsolete file $2"
rm "$2";