mkpkg: make unique-id field a blob
parent
50ab589e9a
commit
9bd1e95e5b
18
src/adb.c
18
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));
|
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)
|
adb_val_t adb_w_int(struct adb *db, uint32_t val)
|
||||||
{
|
{
|
||||||
if (val >= 0x10000000)
|
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));
|
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)
|
adb_val_t adb_wo_obj(struct adb_obj *o, unsigned i, struct adb_obj *no)
|
||||||
{
|
{
|
||||||
assert(o->schema->kind == ADB_KIND_OBJECT);
|
assert(o->schema->kind == ADB_KIND_OBJECT);
|
||||||
|
|
|
@ -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_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_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(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_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_wo_arr(struct adb_obj *o, unsigned i, struct adb_obj *);
|
||||||
adb_val_t adb_wa_append(struct adb_obj *o, adb_val_t);
|
adb_val_t adb_wa_append(struct adb_obj *o, adb_val_t);
|
||||||
|
|
|
@ -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:
|
case ADBI_PI_UNIQUE_ID:
|
||||||
if (!val.ptr || val.len < 4) break;
|
if (!val.ptr || val.len < 4) break;
|
||||||
apk_blob_pull_csum(&val, &csum);
|
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;
|
break;
|
||||||
case ADBI_PI_REPO_COMMIT:
|
case ADBI_PI_REPO_COMMIT:
|
||||||
if (val.len < 40) break;
|
if (val.len < 40) break;
|
||||||
|
@ -386,7 +386,7 @@ const struct adb_object_schema schema_pkginfo = {
|
||||||
.fields = {
|
.fields = {
|
||||||
ADB_FIELD(ADBI_PI_NAME, "name", scalar_string),
|
ADB_FIELD(ADBI_PI_NAME, "name", scalar_string),
|
||||||
ADB_FIELD(ADBI_PI_VERSION, "version", scalar_version),
|
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_DESCRIPTION, "description", scalar_string),
|
||||||
ADB_FIELD(ADBI_PI_ARCH, "arch", scalar_string),
|
ADB_FIELD(ADBI_PI_ARCH, "arch", scalar_string),
|
||||||
ADB_FIELD(ADBI_PI_LICENSE, "license", scalar_string),
|
ADB_FIELD(ADBI_PI_LICENSE, "license", scalar_string),
|
||||||
|
|
|
@ -229,7 +229,10 @@ static int mkpkg_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *a
|
||||||
int i, j, r;
|
int i, j, r;
|
||||||
struct mkpkg_ctx *ctx = pctx;
|
struct mkpkg_ctx *ctx = pctx;
|
||||||
struct apk_ostream *os;
|
struct apk_ostream *os;
|
||||||
|
struct apk_digest d = {};
|
||||||
char outbuf[PATH_MAX];
|
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;
|
ctx->ac = ac;
|
||||||
adb_w_init_alloca(&ctx->db, ADB_SCHEMA_PACKAGE, 40);
|
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_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_PKGINFO, &pkgi);
|
||||||
adb_wo_obj(&pkg, ADBI_PKG_PATHS, &ctx->paths);
|
adb_wo_obj(&pkg, ADBI_PKG_PATHS, &ctx->paths);
|
||||||
if (ctx->has_scripts) {
|
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_PKGINFO, &pkgi);
|
||||||
adb_ro_obj(&pkg, ADBI_PKG_PATHS, &ctx->paths);
|
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) {
|
if (!ctx->output) {
|
||||||
ctx->output = pkgi_filename(&pkgi, outbuf, sizeof outbuf);
|
ctx->output = pkgi_filename(&pkgi, outbuf, sizeof outbuf);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue