summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/adb.c18
-rw-r--r--src/adb.h1
-rw-r--r--src/apk_adb.c4
-rw-r--r--src/app_mkpkg.c9
4 files changed, 30 insertions, 2 deletions
diff --git a/src/adb.c b/src/adb.c
index 6e63231..f1a4937 100644
--- a/src/adb.c
+++ b/src/adb.c
@@ -672,6 +672,18 @@ adb_val_t adb_w_blob(struct adb *db, apk_blob_t b)
return ADB_VAL(o, adb_w_data(db, vec, ARRAY_SIZE(vec), vec[0].iov_len));
}
+static adb_val_t adb_w_blob_raw(struct adb *db, apk_blob_t b)
+{
+ adb_val_t val;
+ size_t num_buckets;
+
+ num_buckets = db->num_buckets;
+ db->num_buckets = 0;
+ val = adb_w_blob(db, b);
+ db->num_buckets = num_buckets;
+ return val;
+}
+
adb_val_t adb_w_int(struct adb *db, uint32_t val)
{
if (val >= 0x10000000)
@@ -869,6 +881,12 @@ adb_val_t adb_wo_blob(struct adb_obj *o, unsigned i, apk_blob_t b)
return adb_wo_val(o, i, adb_w_blob(o->db, b));
}
+adb_val_t adb_wo_blob_raw(struct adb_obj *o, unsigned i, apk_blob_t b)
+{
+ assert(o->schema->kind == ADB_KIND_OBJECT);
+ return adb_wo_val(o, i, adb_w_blob_raw(o->db, b));
+}
+
adb_val_t adb_wo_obj(struct adb_obj *o, unsigned i, struct adb_obj *no)
{
assert(o->schema->kind == ADB_KIND_OBJECT);
diff --git a/src/adb.h b/src/adb.h
index 3dfd64c..a306d05 100644
--- a/src/adb.h
+++ b/src/adb.h
@@ -218,6 +218,7 @@ adb_val_t adb_wo_val(struct adb_obj *o, unsigned i, adb_val_t);
adb_val_t adb_wo_val_fromstring(struct adb_obj *o, unsigned i, apk_blob_t);
adb_val_t adb_wo_int(struct adb_obj *o, unsigned i, uint32_t);
adb_val_t adb_wo_blob(struct adb_obj *o, unsigned i, apk_blob_t);
+adb_val_t adb_wo_blob_raw(struct adb_obj *o, unsigned i, apk_blob_t);
adb_val_t adb_wo_obj(struct adb_obj *o, unsigned i, struct adb_obj *);
adb_val_t adb_wo_arr(struct adb_obj *o, unsigned i, struct adb_obj *);
adb_val_t adb_wa_append(struct adb_obj *o, adb_val_t);
diff --git a/src/apk_adb.c b/src/apk_adb.c
index 8a887cf..f8b0fe6 100644
--- a/src/apk_adb.c
+++ b/src/apk_adb.c
@@ -35,7 +35,7 @@ adb_val_t adb_wo_pkginfo(struct adb_obj *obj, unsigned int f, apk_blob_t val)
case ADBI_PI_UNIQUE_ID:
if (!val.ptr || val.len < 4) break;
apk_blob_pull_csum(&val, &csum);
- v = adb_w_int(obj->db, get_unaligned32(csum.data) & ADB_VALUE_MASK);
+ v = adb_w_blob(obj->db, APK_BLOB_CSUM(csum));
break;
case ADBI_PI_REPO_COMMIT:
if (val.len < 40) break;
@@ -386,7 +386,7 @@ const struct adb_object_schema schema_pkginfo = {
.fields = {
ADB_FIELD(ADBI_PI_NAME, "name", scalar_string),
ADB_FIELD(ADBI_PI_VERSION, "version", scalar_version),
- ADB_FIELD(ADBI_PI_UNIQUE_ID, "unique-id", scalar_int),
+ ADB_FIELD(ADBI_PI_UNIQUE_ID, "unique-id", scalar_hexblob),
ADB_FIELD(ADBI_PI_DESCRIPTION, "description", scalar_string),
ADB_FIELD(ADBI_PI_ARCH, "arch", scalar_string),
ADB_FIELD(ADBI_PI_LICENSE, "license", scalar_string),
diff --git a/src/app_mkpkg.c b/src/app_mkpkg.c
index 6944599..d855999 100644
--- a/src/app_mkpkg.c
+++ b/src/app_mkpkg.c
@@ -229,7 +229,10 @@ static int mkpkg_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *a
int i, j, r;
struct mkpkg_ctx *ctx = pctx;
struct apk_ostream *os;
+ struct apk_digest d = {};
char outbuf[PATH_MAX];
+ const int uid_len = apk_digest_alg_len(APK_DIGEST_SHA1);
+ apk_blob_t uid = APK_BLOB_PTR_LEN((char*)d.data, uid_len);
ctx->ac = ac;
adb_w_init_alloca(&ctx->db, ADB_SCHEMA_PACKAGE, 40);
@@ -271,6 +274,7 @@ static int mkpkg_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *a
}
adb_wo_int(&pkgi, ADBI_PI_INSTALLED_SIZE, ctx->installed_size);
+ adb_wo_blob(&pkgi, ADBI_PI_UNIQUE_ID, uid);
adb_wo_obj(&pkg, ADBI_PKG_PKGINFO, &pkgi);
adb_wo_obj(&pkg, ADBI_PKG_PATHS, &ctx->paths);
if (ctx->has_scripts) {
@@ -294,6 +298,11 @@ static int mkpkg_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *a
adb_ro_obj(&pkg, ADBI_PKG_PKGINFO, &pkgi);
adb_ro_obj(&pkg, ADBI_PKG_PATHS, &ctx->paths);
+ // fill in unique id
+ apk_digest_calc(&d, APK_DIGEST_SHA256, ctx->db.adb.ptr, ctx->db.adb.len);
+ uid = adb_ro_blob(&pkgi, ADBI_PI_UNIQUE_ID);
+ memcpy(uid.ptr, d.data, uid.len);
+
if (!ctx->output) {
ctx->output = pkgi_filename(&pkgi, outbuf, sizeof outbuf);
}