Skip to content

Commit

Permalink
manifest: cleanup
Browse files Browse the repository at this point in the history
Remove unused fucntion (pkg_emit_manifest_buf) and directly call
native ucl emitters where possible
  • Loading branch information
bapt committed Oct 20, 2023
1 parent 6dd3c09 commit 959e2d6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 66 deletions.
29 changes: 16 additions & 13 deletions libpkg/pkg_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
int64_t flatsize = 0;
int64_t nfiles;
const char *relocation;
char *manifest;
ucl_object_t *obj;
hardlinks_t hardlinks = tll_init();

if (pkg_is_valid(pkg) != EPKG_OK) {
Expand Down Expand Up @@ -131,19 +133,20 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
* Register shared libraries used by the package if
* SHLIBS enabled in conf. Deletes shlib info if not.
*/
xstring *b = xstring_new();

pkg_emit_manifest_buf(pkg, b, PKG_MANIFEST_EMIT_COMPACT);
fflush(b->fp);
packing_append_buffer(pkg_archive, b->buf, "+COMPACT_MANIFEST", strlen(b->buf));
xstring_reset(b);
if (pc->expand_manifest)
pkg_emit_manifest_buf(pkg, b, PKG_MANIFEST_EMIT_UCL);
else
pkg_emit_manifest_buf(pkg, b, 0);
fflush(b->fp);
packing_append_buffer(pkg_archive, b->buf, "+MANIFEST", strlen(b->buf));
xstring_free(b);

obj = pkg_emit_object(pkg, PKG_MANIFEST_EMIT_COMPACT);
manifest = ucl_object_emit(obj, UCL_EMIT_JSON_COMPACT);
ucl_object_unref(obj);
packing_append_buffer(pkg_archive, manifest, "+COMPACT_MANIFEST", strlen(manifest));
free(manifest);
obj = pkg_emit_object(pkg, 0);
if (pc->expand_manifest) {
manifest = ucl_object_emit(obj, UCL_EMIT_CONFIG);
} else {
manifest = ucl_object_emit(obj, UCL_EMIT_JSON_COMPACT);
}
ucl_object_unref(obj);
packing_append_buffer(pkg_archive, manifest, "+MANIFEST", strlen(manifest));

counter_init("packing files", nfiles);

Expand Down
58 changes: 6 additions & 52 deletions libpkg/pkg_manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,69 +1243,23 @@ pkg_emit_object(struct pkg *pkg, short flags)
return (top);
}


static int
emit_manifest(struct pkg *pkg, xstring **out, short flags)
int
pkg_emit_manifest_file(struct pkg *pkg, FILE *out, short flags)
{
ucl_object_t *top;

top = pkg_emit_object(pkg, flags);

if ((flags & PKG_MANIFEST_EMIT_PRETTY) == PKG_MANIFEST_EMIT_PRETTY)
ucl_object_emit_buf(top, UCL_EMIT_YAML, out);
ucl_object_emit_file(top, UCL_EMIT_YAML, out);
else if ((flags & PKG_MANIFEST_EMIT_UCL) == PKG_MANIFEST_EMIT_UCL)
ucl_object_emit_buf(top, UCL_EMIT_CONFIG, out);
ucl_object_emit_file(top, UCL_EMIT_CONFIG, out);
else if ((flags & PKG_MANIFEST_EMIT_JSON) == PKG_MANIFEST_EMIT_JSON)
ucl_object_emit_buf(top, UCL_EMIT_JSON, out);
ucl_object_emit_file(top, UCL_EMIT_JSON, out);
else
ucl_object_emit_buf(top, UCL_EMIT_JSON_COMPACT, out);
ucl_object_emit_file(top, UCL_EMIT_JSON_COMPACT, out);

ucl_object_unref(top);

return (EPKG_OK);
}

/*
* This routine is able to output to either a (FILE *) or a (struct sbuf *). It
* exist only to avoid code duplication and should not be called except from
* pkg_emit_manifest_file() and pkg_emit_manifest_buf().
*/
static int
pkg_emit_manifest_generic(struct pkg *pkg, void *out, short flags,
bool out_is_a_buf)
{
xstring *output = NULL;
SHA256_CTX *sign_ctx = NULL;
int rc;

if (out_is_a_buf)
output = out;

rc = emit_manifest(pkg, &output, flags);

fflush(output->fp);
if (sign_ctx != NULL)
sha256_update(sign_ctx, output->buf, strlen(output->buf));

if (!out_is_a_buf)
fprintf(out, "%s\n", output->buf);

if (!out_is_a_buf)
xstring_free(output);

return (rc);
}

int
pkg_emit_manifest_file(struct pkg *pkg, FILE *f, short flags)
{

return (pkg_emit_manifest_generic(pkg, f, flags, false));
}

int
pkg_emit_manifest_buf(struct pkg *pkg, xstring *b, short flags)
{

return (pkg_emit_manifest_generic(pkg, b, flags, true));
}
1 change: 0 additions & 1 deletion libpkg/private/pkg.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,6 @@ int pkgdb_set_pkg_digest(struct pkgdb *db, struct pkg *pkg);
int pkgdb_is_dir_used(struct pkgdb *db, struct pkg *p, const char *dir, int64_t *res);
int pkgdb_file_set_cksum(struct pkgdb *db, struct pkg_file *file, const char *sha256);

int pkg_emit_manifest_buf(struct pkg*, xstring *, short);
int pkg_emit_filelist(struct pkg *, FILE *);

bool ucl_object_emit_buf(const ucl_object_t *obj, enum ucl_emitter emit_type,
Expand Down

0 comments on commit 959e2d6

Please sign in to comment.