extract_utils: extract(): fix src not being searched in "src:dst;args" spec
* Root cause of the issue is improper naming of variables. Turns out, there was no variable to even denote where the blob should have been searched for, at "src". * Previously there was one such variable, suggestively called "TARGET", that was desperately trying to serve as both, depending on who +2d hacks harder. * One such example is "c982836 extract_utils: Fix makefile generation issues". That patch deliberately trimmed the "src:" from a spec (therefore obviously breaking the search at src) but enabling the searching at dst, via the good-for-all TARGET variable. * This patch introduces the following variables: - SRC_FILE: absolute path corresponding to SPEC_SRC_FILE in the Android filesystem. - DST_FILE: absolute path corresponding to SPEC_DST_FILE in the Android filesystem. Somewhat analogous to the old TARGET variable, but actually contains the leading / as well (/system/bin/adsprpcd instead of system/bin/adsprpcd). * Use existing common get_file() function (which previously was impossible to use, because it was impossible to determine calling arguments properly) to reduce complexity of handling adb and disk image as blob sources. * Via the new SRC_FILE and DST_FILE variables, search for a blob in all possible locations (including paths stripped of "/system" which transforms an absolute path in the Android filesystem into a proper relative path to that file in a disk image). Change-Id: Ic40fb4dc93541d8b3f33fde586b773199cf4ded2 Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
This commit is contained in:
committed by
Michael Bestas
parent
d674771760
commit
5f15e3e63c
@@ -985,30 +985,32 @@ function extract() {
|
|||||||
local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}")
|
local SPEC_SRC_FILE=$(src_file "${FILELIST[$i-1]}")
|
||||||
local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}")
|
local SPEC_DST_FILE=$(target_file "${FILELIST[$i-1]}")
|
||||||
local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}")
|
local SPEC_ARGS=$(target_args "${FILELIST[$i-1]}")
|
||||||
local OUTPUT_DIR="$OUTPUT_ROOT"
|
local OUTPUT_DIR=
|
||||||
local TMP_DIR="$OUTPUT_TMP"
|
local TMP_DIR=
|
||||||
local TARGET=
|
local SRC_FILE=
|
||||||
|
local DST_FILE=
|
||||||
|
|
||||||
if [ "${SPEC_ARGS}" = "rootfs" ]; then
|
if [ "${SPEC_ARGS}" = "rootfs" ]; then
|
||||||
TARGET="${SPEC_DST_FILE}"
|
OUTPUT_DIR="${OUTPUT_ROOT}/rootfs"
|
||||||
OUTPUT_DIR="$OUTPUT_DIR/rootfs"
|
TMP_DIR="${OUTPUT_TMP}/rootfs"
|
||||||
TMP_DIR="$TMP_DIR/rootfs"
|
SRC_FILE="/${SPEC_SRC_FILE}"
|
||||||
|
DST_FILE="/${SPEC_DST_FILE}"
|
||||||
else
|
else
|
||||||
TARGET="system/${SPEC_DST_FILE}"
|
OUTPUT_DIR="${OUTPUT_ROOT}"
|
||||||
SPEC_SRC_FILE="system/${SPEC_SRC_FILE}"
|
TMP_DIR="${OUTPUT_TMP}"
|
||||||
|
SRC_FILE="/system/${SPEC_SRC_FILE}"
|
||||||
|
DST_FILE="/system/${SPEC_DST_FILE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$SRC" = "adb" ]; then
|
if [ "$SRC" = "adb" ]; then
|
||||||
printf ' - %s .. ' "/$TARGET"
|
printf ' - %s .. ' "${DST_FILE}"
|
||||||
else
|
else
|
||||||
printf ' - %s \n' "/$TARGET"
|
printf ' - %s \n' "${DST_FILE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local DIR=$(dirname "${SPEC_DST_FILE}")
|
# Strip the file path in the vendor repo of "system", if present
|
||||||
if [ ! -d "$OUTPUT_DIR/$DIR" ]; then
|
local VENDOR_REPO_FILE="$OUTPUT_DIR/${DST_FILE#/system}"
|
||||||
mkdir -p "$OUTPUT_DIR/$DIR"
|
mkdir -p $(dirname "${VENDOR_REPO_FILE}")
|
||||||
fi
|
|
||||||
local VENDOR_REPO_FILE="$OUTPUT_DIR/${SPEC_DST_FILE}"
|
|
||||||
|
|
||||||
# Check pinned files
|
# Check pinned files
|
||||||
local HASH="${HASHLIST[$i-1]}"
|
local HASH="${HASHLIST[$i-1]}"
|
||||||
@@ -1017,7 +1019,7 @@ function extract() {
|
|||||||
if [ -f "${VENDOR_REPO_FILE}" ]; then
|
if [ -f "${VENDOR_REPO_FILE}" ]; then
|
||||||
local PINNED="${VENDOR_REPO_FILE}"
|
local PINNED="${VENDOR_REPO_FILE}"
|
||||||
else
|
else
|
||||||
local PINNED="$TMP_DIR/${SPEC_DST_FILE}"
|
local PINNED="${TMP_DIR}${DST_FILE#/system}"
|
||||||
fi
|
fi
|
||||||
if [ -f "$PINNED" ]; then
|
if [ -f "$PINNED" ]; then
|
||||||
if [ "$(uname)" == "Darwin" ]; then
|
if [ "$(uname)" == "Darwin" ]; then
|
||||||
@@ -1036,21 +1038,20 @@ function extract() {
|
|||||||
|
|
||||||
if [ "$KEEP" = "1" ]; then
|
if [ "$KEEP" = "1" ]; then
|
||||||
printf ' + (keeping pinned file with hash %s)\n' "$HASH"
|
printf ' + (keeping pinned file with hash %s)\n' "$HASH"
|
||||||
elif [ "$SRC" = "adb" ]; then
|
|
||||||
# Try Lineage target first
|
|
||||||
adb pull "/$TARGET" "${VENDOR_REPO_FILE}"
|
|
||||||
# if file does not exist try OEM target
|
|
||||||
if [ "$?" != "0" ]; then
|
|
||||||
adb pull "/${SPEC_SRC_FILE}" "${VENDOR_REPO_FILE}"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Try Lineage target first
|
|
||||||
if [ -f "$SRC/$TARGET" ]; then
|
|
||||||
cp "$SRC/$TARGET" "${VENDOR_REPO_FILE}"
|
|
||||||
# if file does not exist try OEM target
|
|
||||||
elif [ -f "$SRC/${SPEC_SRC_FILE}" ]; then
|
|
||||||
cp "$SRC/${SPEC_SRC_FILE}" "${VENDOR_REPO_FILE}"
|
|
||||||
else
|
else
|
||||||
|
FOUND=false
|
||||||
|
# Try Lineage target first.
|
||||||
|
# Also try to search for files stripped of
|
||||||
|
# the "/system" prefix, if we're actually extracting
|
||||||
|
# from a system image.
|
||||||
|
for CANDIDATE in "${DST_FILE}" "${DST_FILE#/system}" "${SRC_FILE}" "${SRC_FILE#/system}"; do
|
||||||
|
get_file ${CANDIDATE} ${VENDOR_REPO_FILE} ${SRC} && {
|
||||||
|
FOUND=true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "${FOUND}" = false ]; then
|
||||||
printf ' !! file not found in source\n'
|
printf ' !! file not found in source\n'
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -1070,6 +1071,7 @@ function extract() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "${VENDOR_REPO_FILE}" ]; then
|
if [ -f "${VENDOR_REPO_FILE}" ]; then
|
||||||
|
local DIR=$(dirname "${VENDOR_REPO_FILE}")
|
||||||
local TYPE="${DIR##*/}"
|
local TYPE="${DIR##*/}"
|
||||||
if [ "$TYPE" = "bin" -o "$TYPE" = "sbin" ]; then
|
if [ "$TYPE" = "bin" -o "$TYPE" = "sbin" ]; then
|
||||||
chmod 755 "${VENDOR_REPO_FILE}"
|
chmod 755 "${VENDOR_REPO_FILE}"
|
||||||
|
Reference in New Issue
Block a user