parent
4dde7e7e0f
commit
1ab81fdd4c
|
@ -144,6 +144,7 @@ void apk_pkg_from_adb(struct apk_database *db, struct apk_package *pkg, struct a
|
||||||
struct apk_installed_package *apk_pkg_install(struct apk_database *db, struct apk_package *pkg);
|
struct apk_installed_package *apk_pkg_install(struct apk_database *db, struct apk_package *pkg);
|
||||||
void apk_pkg_uninstall(struct apk_database *db, struct apk_package *pkg);
|
void apk_pkg_uninstall(struct apk_database *db, struct apk_package *pkg);
|
||||||
|
|
||||||
|
int apk_ipkg_assign_script(struct apk_installed_package *ipkg, unsigned int type, apk_blob_t blob);
|
||||||
int apk_ipkg_add_script(struct apk_installed_package *ipkg,
|
int apk_ipkg_add_script(struct apk_installed_package *ipkg,
|
||||||
struct apk_istream *is,
|
struct apk_istream *is,
|
||||||
unsigned int type, unsigned int size);
|
unsigned int type, unsigned int size);
|
||||||
|
|
|
@ -74,7 +74,7 @@ static int option_parse_applet(void *ctx, struct apk_ctx *ac, int optch, const c
|
||||||
case OPT_MKPKG_script:
|
case OPT_MKPKG_script:
|
||||||
apk_blob_split(APK_BLOB_STR(optarg), APK_BLOB_STRLIT(":"), &l, &r);
|
apk_blob_split(APK_BLOB_STR(optarg), APK_BLOB_STRLIT(":"), &l, &r);
|
||||||
i = adb_s_field_by_name_blob(&schema_scripts, l);
|
i = adb_s_field_by_name_blob(&schema_scripts, l);
|
||||||
if (i == APK_SCRIPT_INVALID) {
|
if (!i) {
|
||||||
apk_err(out, "invalid script type: " BLOB_FMT, BLOB_PRINTF(l));
|
apk_err(out, "invalid script type: " BLOB_FMT, BLOB_PRINTF(l));
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2334,10 +2334,19 @@ static int apk_db_install_v2meta(struct apk_extract_ctx *ectx, struct apk_istrea
|
||||||
|
|
||||||
static int apk_db_install_v3meta(struct apk_extract_ctx *ectx, struct adb_obj *pkg)
|
static int apk_db_install_v3meta(struct apk_extract_ctx *ectx, struct adb_obj *pkg)
|
||||||
{
|
{
|
||||||
|
static const int script_type_to_field[] = {
|
||||||
|
[APK_SCRIPT_PRE_INSTALL] = ADBI_SCRPT_PREINST,
|
||||||
|
[APK_SCRIPT_POST_INSTALL] = ADBI_SCRPT_POSTINST,
|
||||||
|
[APK_SCRIPT_PRE_DEINSTALL] = ADBI_SCRPT_PREDEINST,
|
||||||
|
[APK_SCRIPT_POST_DEINSTALL] = ADBI_SCRPT_POSTDEINST,
|
||||||
|
[APK_SCRIPT_PRE_UPGRADE] = ADBI_SCRPT_PREUPGRADE,
|
||||||
|
[APK_SCRIPT_POST_UPGRADE] = ADBI_SCRPT_POSTUPGRADE,
|
||||||
|
[APK_SCRIPT_TRIGGER] = ADBI_SCRPT_TRIGGER,
|
||||||
|
};
|
||||||
struct install_ctx *ctx = container_of(ectx, struct install_ctx, ectx);
|
struct install_ctx *ctx = container_of(ectx, struct install_ctx, ectx);
|
||||||
struct apk_database *db = ctx->db;
|
struct apk_database *db = ctx->db;
|
||||||
struct apk_installed_package *ipkg = ctx->ipkg;
|
struct apk_installed_package *ipkg = ctx->ipkg;
|
||||||
struct adb_obj triggers, pkginfo, obj;
|
struct adb_obj scripts, triggers, pkginfo, obj;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// Extract the information not available in index
|
// Extract the information not available in index
|
||||||
|
@ -2346,6 +2355,14 @@ static int apk_db_install_v3meta(struct apk_extract_ctx *ectx, struct adb_obj *p
|
||||||
ipkg->replaces_priority = adb_ro_int(&pkginfo, ADBI_PI_PRIORITY);
|
ipkg->replaces_priority = adb_ro_int(&pkginfo, ADBI_PI_PRIORITY);
|
||||||
ipkg->v3 = 1;
|
ipkg->v3 = 1;
|
||||||
|
|
||||||
|
adb_ro_obj(pkg, ADBI_PKG_SCRIPTS, &scripts);
|
||||||
|
for (i = 0; i < ARRAY_SIZE(script_type_to_field); i++) {
|
||||||
|
apk_blob_t b = adb_ro_blob(&scripts, script_type_to_field[i]);
|
||||||
|
if (APK_BLOB_IS_NULL(b)) continue;
|
||||||
|
apk_ipkg_assign_script(ipkg, i, apk_blob_dup(b));
|
||||||
|
ctx->script_pending |= (i == ctx->script);
|
||||||
|
}
|
||||||
|
|
||||||
apk_string_array_resize(&ipkg->triggers, 0);
|
apk_string_array_resize(&ipkg->triggers, 0);
|
||||||
adb_ro_obj(pkg, ADBI_PKG_TRIGGERS, &triggers);
|
adb_ro_obj(pkg, ADBI_PKG_TRIGGERS, &triggers);
|
||||||
for (i = ADBI_FIRST; i <= adb_ra_num(&triggers); i++)
|
for (i = ADBI_FIRST; i <= adb_ra_num(&triggers); i++)
|
||||||
|
|
|
@ -738,18 +738,23 @@ void apk_pkg_free(struct apk_package *pkg)
|
||||||
free(pkg);
|
free(pkg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int apk_ipkg_assign_script(struct apk_installed_package *ipkg, unsigned int type, apk_blob_t b)
|
||||||
|
{
|
||||||
|
if (APK_BLOB_IS_NULL(b)) return -1;
|
||||||
|
if (type >= APK_SCRIPT_MAX) {
|
||||||
|
free(b.ptr);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (ipkg->script[type].ptr) free(ipkg->script[type].ptr);
|
||||||
|
ipkg->script[type] = b;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int apk_ipkg_add_script(struct apk_installed_package *ipkg,
|
int apk_ipkg_add_script(struct apk_installed_package *ipkg,
|
||||||
struct apk_istream *is,
|
struct apk_istream *is,
|
||||||
unsigned int type, unsigned int size)
|
unsigned int type, unsigned int size)
|
||||||
{
|
{
|
||||||
apk_blob_t b;
|
return apk_ipkg_assign_script(ipkg, type, apk_blob_from_istream(is, size));
|
||||||
|
|
||||||
if (type >= APK_SCRIPT_MAX) return -1;
|
|
||||||
b = apk_blob_from_istream(is, size);
|
|
||||||
if (APK_BLOB_IS_NULL(b)) return -1;
|
|
||||||
if (ipkg->script[type].ptr) free(ipkg->script[type].ptr);
|
|
||||||
ipkg->script[type] = b;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void apk_ipkg_run_script(struct apk_installed_package *ipkg,
|
void apk_ipkg_run_script(struct apk_installed_package *ipkg,
|
||||||
|
|
Loading…
Reference in New Issue