mirror of
https://github.com/pygos/pkg-utils.git
synced 2024-11-22 12:59:46 +01:00
Add flags to dump command to dump header data vs file list
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
parent
aab510aa98
commit
09a336507d
4 changed files with 90 additions and 4 deletions
|
@ -30,6 +30,7 @@ pkg_SOURCES += main/cmd/pack/write_hdr.c
|
||||||
|
|
||||||
# dump command
|
# dump command
|
||||||
pkg_SOURCES += main/cmd/dump/dump.c main/cmd/dump/dump.h main/cmd/dump/dump_toc.c
|
pkg_SOURCES += main/cmd/dump/dump.c main/cmd/dump/dump.h main/cmd/dump/dump_toc.c
|
||||||
|
pkg_SOURCES += main/cmd/dump/dump_header.c
|
||||||
|
|
||||||
# unpack command
|
# unpack command
|
||||||
pkg_SOURCES += main/cmd/unpack/unpack.c main/cmd/unpack/unpack.h
|
pkg_SOURCES += main/cmd/unpack/unpack.c main/cmd/unpack/unpack.h
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
#include "dump.h"
|
#include "dump.h"
|
||||||
|
|
||||||
static const struct option long_opts[] = {
|
static const struct option long_opts[] = {
|
||||||
|
{ "dependencies", no_argument, NULL, 'd' },
|
||||||
|
{ "list-files", no_argument, NULL, 'l' },
|
||||||
{ "format", required_argument, NULL, 'f' },
|
{ "format", required_argument, NULL, 'f' },
|
||||||
{ "root", required_argument, NULL, 'r' },
|
{ "root", required_argument, NULL, 'r' },
|
||||||
{ NULL, 0, NULL, 0 },
|
{ NULL, 0, NULL, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *short_opts = "f:r:";
|
static const char *short_opts = "dlf:r:";
|
||||||
|
|
||||||
static int cmd_dump(int argc, char **argv)
|
static int cmd_dump(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -15,7 +17,7 @@ static int cmd_dump(int argc, char **argv)
|
||||||
const char *root = NULL;
|
const char *root = NULL;
|
||||||
int ret = EXIT_FAILURE;
|
int ret = EXIT_FAILURE;
|
||||||
pkg_reader_t *rd;
|
pkg_reader_t *rd;
|
||||||
int i;
|
int i, flags = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
i = getopt_long(argc, argv, short_opts, long_opts, NULL);
|
i = getopt_long(argc, argv, short_opts, long_opts, NULL);
|
||||||
|
@ -38,12 +40,21 @@ static int cmd_dump(int argc, char **argv)
|
||||||
case 'r':
|
case 'r':
|
||||||
root = optarg;
|
root = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'l':
|
||||||
|
flags |= DUMP_TOC;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
flags |= DUMP_DEPS;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
tell_read_help(argv[0]);
|
tell_read_help(argv[0]);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags == 0)
|
||||||
|
flags = DUMP_ALL;
|
||||||
|
|
||||||
if (optind >= argc) {
|
if (optind >= argc) {
|
||||||
fputs("missing argument: package file\n", stderr);
|
fputs("missing argument: package file\n", stderr);
|
||||||
tell_read_help(argv[0]);
|
tell_read_help(argv[0]);
|
||||||
|
@ -57,12 +68,19 @@ static int cmd_dump(int argc, char **argv)
|
||||||
if (optind < argc)
|
if (optind < argc)
|
||||||
fputs("warning: ignoring extra arguments\n", stderr);
|
fputs("warning: ignoring extra arguments\n", stderr);
|
||||||
|
|
||||||
|
if (flags & DUMP_DEPS) {
|
||||||
|
if (dump_header(rd, flags))
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
list = image_entry_list_from_package(rd);
|
list = image_entry_list_from_package(rd);
|
||||||
if (list == NULL)
|
if (list == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (dump_toc(list, root, format))
|
if (flags & DUMP_TOC) {
|
||||||
goto out;
|
if (dump_toc(list, root, format))
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
out:
|
out:
|
||||||
|
@ -81,6 +99,11 @@ static command_t dump = {
|
||||||
"files, et cetera.\n"
|
"files, et cetera.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Possible options:\n"
|
"Possible options:\n"
|
||||||
|
" --dependencies, -d Show dependency information of a package.\n"
|
||||||
|
"\n"
|
||||||
|
" --list-files, -l Produce a list of files. The format for the list\n"
|
||||||
|
" can be specified with --format.\n"
|
||||||
|
"\n"
|
||||||
" --format, -f <format> Specify what format to use for printing the table\n"
|
" --format, -f <format> Specify what format to use for printing the table\n"
|
||||||
" of contents. Default is a pretty printed, human\n"
|
" of contents. Default is a pretty printed, human\n"
|
||||||
" readable version.\n"
|
" readable version.\n"
|
||||||
|
|
|
@ -19,6 +19,14 @@ typedef enum {
|
||||||
TOC_FORMAT_INITRD = 2,
|
TOC_FORMAT_INITRD = 2,
|
||||||
} TOC_FORMAT;
|
} TOC_FORMAT;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
DUMP_TOC = 0x01,
|
||||||
|
DUMP_DEPS = 0x02,
|
||||||
|
DUMP_ALL = (DUMP_TOC | DUMP_DEPS),
|
||||||
|
} DUMP_FLAGS;
|
||||||
|
|
||||||
int dump_toc(image_entry_t *list, const char *root, TOC_FORMAT format);
|
int dump_toc(image_entry_t *list, const char *root, TOC_FORMAT format);
|
||||||
|
|
||||||
|
int dump_header(pkg_reader_t *pkg, int flags);
|
||||||
|
|
||||||
#endif /* DUMP_H */
|
#endif /* DUMP_H */
|
||||||
|
|
54
main/cmd/dump/dump_header.c
Normal file
54
main/cmd/dump/dump_header.c
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#include "dump.h"
|
||||||
|
|
||||||
|
static const char *dependency_type[] = {
|
||||||
|
[PKG_DEPENDENCY_REQUIRES] = "requires",
|
||||||
|
};
|
||||||
|
|
||||||
|
int dump_header(pkg_reader_t *pkg, int flags)
|
||||||
|
{
|
||||||
|
pkg_dependency_t dep;
|
||||||
|
uint8_t buffer[257];
|
||||||
|
pkg_header_t hdr;
|
||||||
|
ssize_t ret;
|
||||||
|
uint16_t i;
|
||||||
|
|
||||||
|
ret = pkg_reader_read_payload(pkg, &hdr, sizeof(hdr));
|
||||||
|
if (ret < 0)
|
||||||
|
return -1;
|
||||||
|
if ((size_t)ret < sizeof(hdr))
|
||||||
|
goto fail_trunc;
|
||||||
|
|
||||||
|
hdr.num_depends = le16toh(hdr.num_depends);
|
||||||
|
|
||||||
|
if (flags & DUMP_DEPS) {
|
||||||
|
printf("Dependencies:\n");
|
||||||
|
|
||||||
|
for (i = 0; i < hdr.num_depends; ++i) {
|
||||||
|
ret = pkg_reader_read_payload(pkg, &dep, sizeof(dep));
|
||||||
|
if (ret < 0)
|
||||||
|
return -1;
|
||||||
|
if ((size_t)ret < sizeof(hdr))
|
||||||
|
goto fail_trunc;
|
||||||
|
|
||||||
|
ret = pkg_reader_read_payload(pkg, buffer,
|
||||||
|
dep.name_length);
|
||||||
|
if (ret < 0)
|
||||||
|
return -1;
|
||||||
|
if ((size_t)ret < dep.name_length)
|
||||||
|
goto fail_trunc;
|
||||||
|
|
||||||
|
buffer[dep.name_length] = '\0';
|
||||||
|
|
||||||
|
printf("\t%s: %s\n", dependency_type[dep.type],
|
||||||
|
(char *)buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
fputc('\n', stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
fail_trunc:
|
||||||
|
fprintf(stderr, "%s: truncated header record\n",
|
||||||
|
pkg_reader_get_filename(pkg));
|
||||||
|
return -1;
|
||||||
|
}
|
Loading…
Reference in a new issue