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

pack: read package name from description

This commit changes the pack command to read the output package name from
the description file instead of the command line. The command line argument
is replaced with a package repository directory to which the package file
is then written.

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2019-01-30 10:40:02 +01:00
parent 9b18455679
commit 04f19bac2f
3 changed files with 50 additions and 10 deletions

View file

@ -41,11 +41,29 @@ static int handle_requires(input_file_t *f, pkg_desc_t *desc)
return 0;
}
static int handle_name(input_file_t *f, pkg_desc_t *desc)
{
if (desc->name != NULL) {
fprintf(stderr, "%s: %zu: name redefined\n",
f->filename, f->linenum);
return -1;
}
desc->name = strdup(f->line);
if (desc->name == NULL) {
fputs("out of memory\n", stderr);
return -1;
}
return 0;
}
static const struct {
const char *name;
int (*handle)(input_file_t *f, pkg_desc_t *desc);
} line_hooks[] = {
{ "requires", handle_requires },
{ "name", handle_name },
};
#define NUM_LINE_HOOKS (sizeof(line_hooks) / sizeof(line_hooks[0]))
@ -95,6 +113,11 @@ int desc_read(const char *path, pkg_desc_t *desc)
goto fail;
}
if (desc->name == NULL) {
fprintf(stderr, "%s: no name given in package description\n",
f.filename);
}
cleanup_file(&f);
return 0;
fail:
@ -112,4 +135,6 @@ void desc_free(pkg_desc_t *desc)
free(dep);
}
free(desc->name);
}

View file

@ -5,11 +5,11 @@ static const struct option long_opts[] = {
{ "file-compressor", required_argument, NULL, 'f' },
{ "description", required_argument, NULL, 'd' },
{ "file-list", required_argument, NULL, 'l' },
{ "output", required_argument, NULL, 'o' },
{ "repo-dir", required_argument, NULL, 'r' },
{ NULL, 0, NULL, 0 },
};
static const char *short_opts = "t:f:l:o:d:";
static const char *short_opts = "t:f:l:r:d:";
static compressor_t *get_default_compressor(void)
{
@ -60,9 +60,22 @@ static int alloc_file_ids(image_entry_t *list)
return 0;
}
static pkg_writer_t *open_writer(pkg_desc_t *desc, const char *repodir)
{
char *path;
if (mkdir_p(repodir))
return NULL;
path = alloca(strlen(repodir) + strlen(desc->name) + 16);
sprintf(path, "%s/%s.pkg", repodir, desc->name);
return pkg_writer_open(path);
}
static int cmd_pack(int argc, char **argv)
{
const char *filelist = NULL, *filename = NULL, *descfile = NULL;
const char *filelist = NULL, *repodir = NULL, *descfile = NULL;
compressor_t *cmp_toc, *cmp_files;
image_entry_t *list;
pkg_writer_t *wr;
@ -96,12 +109,12 @@ static int cmd_pack(int argc, char **argv)
case 'l':
filelist = optarg;
break;
case 'o':
filename = optarg;
break;
case 'd':
descfile = optarg;
break;
case 'r':
repodir = optarg;
break;
default:
tell_read_help(argv[0]);
return EXIT_FAILURE;
@ -114,8 +127,8 @@ static int cmd_pack(int argc, char **argv)
return EXIT_FAILURE;
}
if (filename == NULL) {
fputs("missing argument: output package file\n", stderr);
if (repodir == NULL) {
fputs("missing argument: repository directory\n", stderr);
tell_read_help(argv[0]);
return EXIT_FAILURE;
}
@ -141,7 +154,7 @@ static int cmd_pack(int argc, char **argv)
if (alloc_file_ids(list))
goto fail_fp;
wr = pkg_writer_open(filename);
wr = open_writer(&desc, repodir);
if (wr == NULL)
goto fail_fp;
@ -175,7 +188,8 @@ static command_t pack = {
"Read a list of files from the given lists file and generate a package.\n"
"Possible options:\n"
" --file-list, -l <path> Specify a file containing a list of input files.\n"
" --output, -o <path> Specify the path of the resulting package file.\n"
" --repo-dir, -r <path> Specify the output repository path to store the\n"
" package in.\n"
"\n"
" --toc-compressor, -t <compressor>\n"
" --file-compressor, -f <compressor>\n"

View file

@ -36,6 +36,7 @@ typedef struct dependency_t {
typedef struct {
dependency_t *deps;
char *name;
} pkg_desc_t;
image_entry_t *filelist_mkdir(input_file_t *f);