1
0
Fork 0
mirror of https://github.com/pygos/pkg-utils.git synced 2024-11-22 04:49:46 +01:00

Move file compressors details from command line to desc file instead

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2019-02-07 23:31:05 +01:00
parent 95c7302d25
commit 4141e666b6
3 changed files with 68 additions and 58 deletions

View file

@ -58,13 +58,62 @@ static int handle_name(input_file_t *f, void *obj)
return 0; return 0;
} }
static int handle_toc_compressor(input_file_t *f, void *obj)
{
pkg_desc_t *desc = obj;
desc->toccmp = compressor_by_name(f->line);
if (desc->toccmp == NULL) {
input_file_complain(f, "unkown compressor");
return -1;
}
return 0;
}
static int handle_data_compressor(input_file_t *f, void *obj)
{
pkg_desc_t *desc = obj;
desc->datacmp = compressor_by_name(f->line);
if (desc->datacmp == NULL) {
input_file_complain(f, "unkown compressor");
return -1;
}
return 0;
}
static const keyword_handler_t line_hooks[] = { static const keyword_handler_t line_hooks[] = {
{ "toc-compressor", handle_toc_compressor },
{ "data-compressor", handle_data_compressor },
{ "requires", handle_requires }, { "requires", handle_requires },
{ "name", handle_name }, { "name", handle_name },
}; };
#define NUM_LINE_HOOKS (sizeof(line_hooks) / sizeof(line_hooks[0])) #define NUM_LINE_HOOKS (sizeof(line_hooks) / sizeof(line_hooks[0]))
static compressor_t *get_default_compressor(void)
{
compressor_t *cmp;
cmp = compressor_by_id(PKG_COMPRESSION_LZMA);
if (cmp != NULL)
return cmp;
cmp = compressor_by_id(PKG_COMPRESSION_ZLIB);
if (cmp != NULL)
return cmp;
cmp = compressor_by_id(PKG_COMPRESSION_NONE);
if (cmp != NULL)
return cmp;
return cmp;
}
int desc_read(const char *path, pkg_desc_t *desc) int desc_read(const char *path, pkg_desc_t *desc)
{ {
input_file_t f; input_file_t f;
@ -80,6 +129,19 @@ int desc_read(const char *path, pkg_desc_t *desc)
} }
cleanup_file(&f); cleanup_file(&f);
if (desc->datacmp == NULL)
desc->datacmp = get_default_compressor();
if (desc->toccmp == NULL)
desc->toccmp = get_default_compressor();
if (desc->datacmp == NULL || desc->toccmp == NULL) {
fputs("no compressor implementations available\n", stderr);
desc_free(desc);
return -1;
}
return 0; return 0;
} }

View file

@ -1,44 +1,13 @@
#include "pack.h" #include "pack.h"
static const struct option long_opts[] = { static const struct option long_opts[] = {
{ "toc-compressor", required_argument, NULL, 't' },
{ "file-compressor", required_argument, NULL, 'f' },
{ "description", required_argument, NULL, 'd' }, { "description", required_argument, NULL, 'd' },
{ "file-list", required_argument, NULL, 'l' }, { "file-list", required_argument, NULL, 'l' },
{ "repo-dir", required_argument, NULL, 'r' }, { "repo-dir", required_argument, NULL, 'r' },
{ NULL, 0, NULL, 0 }, { NULL, 0, NULL, 0 },
}; };
static const char *short_opts = "t:f:l:r:d:"; static const char *short_opts = "l:r:d:";
static compressor_t *get_default_compressor(void)
{
compressor_t *cmp;
cmp = compressor_by_id(PKG_COMPRESSION_LZMA);
if (cmp != NULL)
return cmp;
cmp = compressor_by_id(PKG_COMPRESSION_ZLIB);
if (cmp != NULL)
return cmp;
cmp = compressor_by_id(PKG_COMPRESSION_NONE);
if (cmp != NULL)
return cmp;
return cmp;
}
static compressor_t *try_get_compressor(const char *name)
{
compressor_t *cmp = compressor_by_name(name);
if (cmp == NULL)
fprintf(stderr, "unkown compressor: %s\n", name);
return cmp;
}
static pkg_writer_t *open_writer(pkg_desc_t *desc, const char *repodir) static pkg_writer_t *open_writer(pkg_desc_t *desc, const char *repodir)
{ {
@ -56,36 +25,17 @@ static pkg_writer_t *open_writer(pkg_desc_t *desc, const char *repodir)
static int cmd_pack(int argc, char **argv) static int cmd_pack(int argc, char **argv)
{ {
const char *filelist = NULL, *repodir = NULL, *descfile = NULL; const char *filelist = NULL, *repodir = NULL, *descfile = NULL;
compressor_t *cmp_toc, *cmp_files;
image_entry_t *list = NULL; image_entry_t *list = NULL;
pkg_writer_t *wr; pkg_writer_t *wr;
pkg_desc_t desc; pkg_desc_t desc;
int i; int i;
cmp_toc = get_default_compressor();
cmp_files = cmp_toc;
if (cmp_toc == NULL) {
fputs("no compressor implementations available\n", stderr);
return EXIT_FAILURE;
}
for (;;) { for (;;) {
i = getopt_long(argc, argv, short_opts, long_opts, NULL); i = getopt_long(argc, argv, short_opts, long_opts, NULL);
if (i == -1) if (i == -1)
break; break;
switch (i) { switch (i) {
case 't':
cmp_toc = try_get_compressor(optarg);
if (cmp_toc == NULL)
return EXIT_FAILURE;
break;
case 'f':
cmp_files = try_get_compressor(optarg);
if (cmp_files == NULL)
return EXIT_FAILURE;
break;
case 'l': case 'l':
filelist = optarg; filelist = optarg;
break; break;
@ -130,10 +80,10 @@ static int cmd_pack(int argc, char **argv)
goto fail; goto fail;
if (list != NULL) { if (list != NULL) {
if (write_toc(wr, list, cmp_toc)) if (write_toc(wr, list, desc.toccmp))
goto fail; goto fail;
if (write_files(wr, list, cmp_files)) if (write_files(wr, list, desc.datacmp))
goto fail; goto fail;
} }
@ -163,11 +113,7 @@ static command_t pack = {
" --description, -d <path> Specify a file containing a description of the\n" " --description, -d <path> Specify a file containing a description of the\n"
" package, including information such as package\n" " package, including information such as package\n"
" dependencies, the actual package name, etc.\n" " dependencies, the actual package name, etc.\n"
"\n" "\n",
" --toc-compressor, -t <compressor>\n"
" --file-compressor, -f <compressor>\n"
" Specify what compressor to use for compressing the table of contents,\n"
" or for compressing files respectively.\n",
.run_cmd = cmd_pack, .run_cmd = cmd_pack,
}; };

View file

@ -32,6 +32,8 @@ typedef struct dependency_t {
} dependency_t; } dependency_t;
typedef struct { typedef struct {
compressor_t *datacmp;
compressor_t *toccmp;
dependency_t *deps; dependency_t *deps;
char *name; char *name;
} pkg_desc_t; } pkg_desc_t;