summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2021-12-03 14:52:07 +0200
committerTimo Teräs <timo.teras@iki.fi>2021-12-03 14:53:30 +0200
commit1ab81fdd4cb9b88dad35cc93521650f85837fd6e (patch)
treee446d4db5c60e1dddca717d19030880428cbc5ef
parent4dde7e7e0fc79708119644b14b7123213d0de10d (diff)
downloadapk-tools-1ab81fdd4cb9b88dad35cc93521650f85837fd6e.tar.gz
apk-tools-1ab81fdd4cb9b88dad35cc93521650f85837fd6e.tar.bz2
apk-tools-1ab81fdd4cb9b88dad35cc93521650f85837fd6e.tar.xz
apk-tools-1ab81fdd4cb9b88dad35cc93521650f85837fd6e.zip
db: convert v3 scripts to ipkg on install
fixes #10796
-rw-r--r--src/apk_package.h1
-rw-r--r--src/app_mkpkg.c2
-rw-r--r--src/database.c19
-rw-r--r--src/package.c19
4 files changed, 32 insertions, 9 deletions
diff --git a/src/apk_package.h b/src/apk_package.h
index c6aa051..1d9ca6e 100644
--- a/src/apk_package.h
+++ b/src/apk_package.h
@@ -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);
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,
struct apk_istream *is,
unsigned int type, unsigned int size);
diff --git a/src/app_mkpkg.c b/src/app_mkpkg.c
index 04ef697..4e61066 100644
--- a/src/app_mkpkg.c
+++ b/src/app_mkpkg.c
@@ -74,7 +74,7 @@ static int option_parse_applet(void *ctx, struct apk_ctx *ac, int optch, const c
case OPT_MKPKG_script:
apk_blob_split(APK_BLOB_STR(optarg), APK_BLOB_STRLIT(":"), &l, &r);
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));
return -EINVAL;
}
diff --git a/src/database.c b/src/database.c
index 3776bb1..589a505 100644
--- a/src/database.c
+++ b/src/database.c
@@ -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 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 apk_database *db = ctx->db;
struct apk_installed_package *ipkg = ctx->ipkg;
- struct adb_obj triggers, pkginfo, obj;
+ struct adb_obj scripts, triggers, pkginfo, obj;
int i;
// 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->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);
adb_ro_obj(pkg, ADBI_PKG_TRIGGERS, &triggers);
for (i = ADBI_FIRST; i <= adb_ra_num(&triggers); i++)
diff --git a/src/package.c b/src/package.c
index 0ad0156..6003c5b 100644
--- a/src/package.c
+++ b/src/package.c
@@ -738,20 +738,25 @@ void apk_pkg_free(struct apk_package *pkg)
free(pkg);
}
-int apk_ipkg_add_script(struct apk_installed_package *ipkg,
- struct apk_istream *is,
- unsigned int type, unsigned int size)
+int apk_ipkg_assign_script(struct apk_installed_package *ipkg, unsigned int type, apk_blob_t b)
{
- apk_blob_t b;
-
- if (type >= APK_SCRIPT_MAX) return -1;
- b = apk_blob_from_istream(is, size);
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,
+ struct apk_istream *is,
+ unsigned int type, unsigned int size)
+{
+ return apk_ipkg_assign_script(ipkg, type, apk_blob_from_istream(is, size));
+}
+
void apk_ipkg_run_script(struct apk_installed_package *ipkg,
struct apk_database *db,
unsigned int type, char **argv)