mirror of
https://github.com/pygos/pkg-utils.git
synced 2024-11-22 04:49:46 +01:00
Allow empty packages, i.e. packages not containing any files
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
parent
d55ee9bd72
commit
95c7302d25
8 changed files with 63 additions and 62 deletions
|
@ -13,6 +13,6 @@ enum {
|
||||||
|
|
||||||
int pkg_unpack(int rootfd, int flags, pkg_reader_t *rd);
|
int pkg_unpack(int rootfd, int flags, pkg_reader_t *rd);
|
||||||
|
|
||||||
image_entry_t *image_entry_list_from_package(pkg_reader_t *pkg);
|
int image_entry_list_from_package(pkg_reader_t *pkg, image_entry_t ** list);
|
||||||
|
|
||||||
#endif /* PKGIO_H */
|
#endif /* PKGIO_H */
|
||||||
|
|
|
@ -75,11 +75,10 @@ static int cmd_dump(int argc, char **argv)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
list = image_entry_list_from_package(rd);
|
if (image_entry_list_from_package(rd, &list))
|
||||||
if (list == NULL)
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (flags & DUMP_TOC) {
|
if (flags & DUMP_TOC && list != NULL) {
|
||||||
if (dump_toc(list, root, format))
|
if (dump_toc(list, root, format))
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,13 +58,12 @@ static int list_files(int repofd, const char *rootdir, TOC_FORMAT format,
|
||||||
if (rd == NULL)
|
if (rd == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
toc = image_entry_list_from_package(rd);
|
if (image_entry_list_from_package(rd, &toc)) {
|
||||||
if (toc == NULL) {
|
|
||||||
pkg_reader_close(rd);
|
pkg_reader_close(rd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dump_toc(toc, rootdir, format)) {
|
if (toc != NULL && dump_toc(toc, rootdir, format)) {
|
||||||
image_entry_free_list(toc);
|
image_entry_free_list(toc);
|
||||||
pkg_reader_close(rd);
|
pkg_reader_close(rd);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -258,27 +258,49 @@ static const keyword_handler_t line_hooks[] = {
|
||||||
|
|
||||||
#define NUM_LINE_HOOKS (sizeof(line_hooks) / sizeof(line_hooks[0]))
|
#define NUM_LINE_HOOKS (sizeof(line_hooks) / sizeof(line_hooks[0]))
|
||||||
|
|
||||||
image_entry_t *filelist_read(const char *filename)
|
static int alloc_file_ids(image_entry_t *list)
|
||||||
|
{
|
||||||
|
image_entry_t *ent;
|
||||||
|
uint64_t file_id = 0;
|
||||||
|
|
||||||
|
for (ent = list; ent != NULL; ent = ent->next) {
|
||||||
|
if (!S_ISREG(ent->mode))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (file_id > 0x00000000FFFFFFFFUL) {
|
||||||
|
fprintf(stderr, "too many input files\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ent->data.file.id = file_id++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int filelist_read(const char *filename, image_entry_t **out)
|
||||||
{
|
{
|
||||||
image_entry_t *list = NULL;
|
image_entry_t *list = NULL;
|
||||||
input_file_t f;
|
input_file_t f;
|
||||||
|
|
||||||
if (open_file(&f, filename))
|
if (open_file(&f, filename))
|
||||||
return NULL;
|
return -1;
|
||||||
|
|
||||||
if (process_file(&f, line_hooks, NUM_LINE_HOOKS, &list))
|
if (process_file(&f, line_hooks, NUM_LINE_HOOKS, &list))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (list == NULL) {
|
if (list != NULL) {
|
||||||
fprintf(stderr, "%s: does not contain any entries\n",
|
list = image_entry_sort(list);
|
||||||
f.filename);
|
|
||||||
goto fail;
|
if (alloc_file_ids(list))
|
||||||
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup_file(&f);
|
cleanup_file(&f);
|
||||||
return list;
|
*out = list;
|
||||||
|
return 0;
|
||||||
fail:
|
fail:
|
||||||
cleanup_file(&f);
|
cleanup_file(&f);
|
||||||
image_entry_free_list(list);
|
image_entry_free_list(list);
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,26 +40,6 @@ static compressor_t *try_get_compressor(const char *name)
|
||||||
return cmp;
|
return cmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int alloc_file_ids(image_entry_t *list)
|
|
||||||
{
|
|
||||||
image_entry_t *ent;
|
|
||||||
uint64_t file_id = 0;
|
|
||||||
|
|
||||||
for (ent = list; ent != NULL; ent = ent->next) {
|
|
||||||
if (!S_ISREG(ent->mode))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (file_id > 0x00000000FFFFFFFFUL) {
|
|
||||||
fprintf(stderr, "too many input files\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ent->data.file.id = file_id++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
|
@ -77,7 +57,7 @@ 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;
|
compressor_t *cmp_toc, *cmp_files;
|
||||||
image_entry_t *list;
|
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;
|
||||||
|
@ -133,27 +113,15 @@ static int cmd_pack(int argc, char **argv)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filelist == NULL) {
|
|
||||||
fputs("missing argument: input file list\n", stderr);
|
|
||||||
tell_read_help(argv[0]);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optind < argc)
|
if (optind < argc)
|
||||||
fputs("warning: ignoring extra arguments\n", stderr);
|
fputs("warning: ignoring extra arguments\n", stderr);
|
||||||
|
|
||||||
if (desc_read(descfile, &desc))
|
if (desc_read(descfile, &desc))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
list = filelist_read(filelist);
|
if (filelist != NULL && filelist_read(filelist, &list))
|
||||||
if (list == NULL)
|
|
||||||
goto fail_desc;
|
goto fail_desc;
|
||||||
|
|
||||||
list = image_entry_sort(list);
|
|
||||||
|
|
||||||
if (alloc_file_ids(list))
|
|
||||||
goto fail_fp;
|
|
||||||
|
|
||||||
wr = open_writer(&desc, repodir);
|
wr = open_writer(&desc, repodir);
|
||||||
if (wr == NULL)
|
if (wr == NULL)
|
||||||
goto fail_fp;
|
goto fail_fp;
|
||||||
|
@ -161,11 +129,13 @@ static int cmd_pack(int argc, char **argv)
|
||||||
if (write_header_data(wr, &desc))
|
if (write_header_data(wr, &desc))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (write_toc(wr, list, cmp_toc))
|
if (list != NULL) {
|
||||||
goto fail;
|
if (write_toc(wr, list, cmp_toc))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
if (write_files(wr, list, cmp_files))
|
if (write_files(wr, list, cmp_files))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
pkg_writer_close(wr);
|
pkg_writer_close(wr);
|
||||||
image_entry_free_list(list);
|
image_entry_free_list(list);
|
||||||
|
|
|
@ -42,7 +42,7 @@ int filelist_mkslink(input_file_t *f, void *obj);
|
||||||
|
|
||||||
int filelist_mkfile(input_file_t *f, void *obj);
|
int filelist_mkfile(input_file_t *f, void *obj);
|
||||||
|
|
||||||
image_entry_t *filelist_read(const char *filename);
|
int filelist_read(const char *filename, image_entry_t **out);
|
||||||
|
|
||||||
int write_toc(pkg_writer_t *wr, image_entry_t *list, compressor_t *cmp);
|
int write_toc(pkg_writer_t *wr, image_entry_t *list, compressor_t *cmp);
|
||||||
|
|
||||||
|
|
|
@ -198,13 +198,15 @@ int pkg_unpack(int rootfd, int flags, pkg_reader_t *rd)
|
||||||
record_t *hdr;
|
record_t *hdr;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
list = image_entry_list_from_package(rd);
|
if (image_entry_list_from_package(rd, &list))
|
||||||
if (list == NULL)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (pkg_reader_rewind(rd))
|
if (pkg_reader_rewind(rd))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
if (list == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (create_hierarchy(rootfd, list, flags))
|
if (create_hierarchy(rootfd, list, flags))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
|
|
@ -83,20 +83,28 @@ fail_trunc:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
image_entry_t *image_entry_list_from_package(pkg_reader_t *pkg)
|
int image_entry_list_from_package(pkg_reader_t *pkg, image_entry_t **out)
|
||||||
{
|
{
|
||||||
image_entry_t *list = NULL, *end = NULL, *imgent;
|
image_entry_t *list = NULL, *end = NULL, *imgent;
|
||||||
toc_entry_t ent;
|
toc_entry_t ent;
|
||||||
record_t *hdr;
|
record_t *hdr;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
char *path;
|
char *path;
|
||||||
|
int status;
|
||||||
|
|
||||||
if (pkg_reader_rewind(pkg))
|
if (pkg_reader_rewind(pkg))
|
||||||
return NULL;
|
return -1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (pkg_reader_get_next_record(pkg) <= 0)
|
status = pkg_reader_get_next_record(pkg);
|
||||||
return NULL;
|
|
||||||
|
if (status == 0) {
|
||||||
|
*out = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
hdr = pkg_reader_current_record_header(pkg);
|
hdr = pkg_reader_current_record_header(pkg);
|
||||||
} while (hdr->magic != PKG_MAGIC_TOC);
|
} while (hdr->magic != PKG_MAGIC_TOC);
|
||||||
|
@ -170,7 +178,8 @@ image_entry_t *image_entry_list_from_package(pkg_reader_t *pkg)
|
||||||
goto fail_multi;
|
goto fail_multi;
|
||||||
}
|
}
|
||||||
|
|
||||||
return image_entry_sort(list);
|
*out = image_entry_sort(list);
|
||||||
|
return 0;
|
||||||
fail_oom:
|
fail_oom:
|
||||||
fputs("out of memory\n", stderr);
|
fputs("out of memory\n", stderr);
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -184,5 +193,5 @@ fail_multi:
|
||||||
goto fail;
|
goto fail;
|
||||||
fail:
|
fail:
|
||||||
image_entry_free_list(list);
|
image_entry_free_list(list);
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue