scripts/unpack: common directory unpacking is not thread-safe

emby and emby4 both unzip into ${BUILD}/system, which is fun when
both add-ons are being unpacked concurrently.
This commit is contained in:
MilhouseVH 2019-02-08 17:17:43 +00:00
parent 93f2479fe5
commit cc9dfe5875

View File

@ -52,24 +52,40 @@ fi
if [ -d "$SOURCES/${PKG_NAME}" -o -d "$PKG_DIR/sources" ]; then
build_msg "CLR_UNPACK" "UNPACK" "${PKG_NAME}" "indent"
# unpack into a unique location as unpacking into a single ${BUILD} directory is not thread-safe
PKG_UNPACK_DIR="${BUILD}/.unpack/${PKG_NAME}"
rm -fr "${PKG_UNPACK_DIR}"
mkdir -p "${PKG_UNPACK_DIR}"
pkg_call_exists pre_unpack && pkg_call pre_unpack
if pkg_call_exists unpack; then
pkg_call unpack
else
if [ -n "$PKG_URL" ]; then
$SCRIPTS/extract "${PKG_NAME}" $BUILD
${SCRIPTS}/extract "${PKG_NAME}" "${PKG_UNPACK_DIR}"
fi
fi
if [ ! -d "$PKG_BUILD" ]; then
if [ -n "$PKG_SOURCE_DIR" ]; then
mv $BUILD/$PKG_SOURCE_DIR "$PKG_BUILD"
elif [ -d "$PKG_BUILD"* ]; then
mv "$PKG_BUILD"* "$PKG_BUILD"
_pkg_build="$(basename "${PKG_BUILD}")"
[ -d "${PKG_UNPACK_DIR}/${_pkg_build}"* ] && mv "${PKG_UNPACK_DIR}/${_pkg_build}"* "${PKG_BUILD}"
if [ ! -d "${PKG_BUILD}" ]; then
if [ -n "${PKG_SOURCE_DIR}" ]; then
if [ -d "${PKG_UNPACK_DIR}"/${PKG_SOURCE_DIR} ]; then
mv "${PKG_UNPACK_DIR}"/${PKG_SOURCE_DIR} "${PKG_BUILD}"
else
# fallback
mv "${BUILD}"/${PKG_SOURCE_DIR} "${PKG_BUILD}"
fi
elif [ -d "${PKG_BUILD}"* ]; then
mv "${PKG_BUILD}"* "${PKG_BUILD}"
fi
fi
# cleanup
rm -fr "${PKG_UNPACK_DIR}"
if [ -d "$PKG_DIR/sources" ]; then
[ ! -d "$PKG_BUILD" ] && mkdir -p "$PKG_BUILD"
cp -PRf "$PKG_DIR/sources/"* "$PKG_BUILD"