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

Add listing modes to install command

Allow the install command to either list the packages it wants to install,
or to list the files it would install.

Optionally allow the command to ignore dependencies.

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2019-02-03 12:37:49 +01:00
parent c800554979
commit c23a2c8c33
6 changed files with 131 additions and 22 deletions

View file

@ -11,7 +11,7 @@ GLOBALHDR += include/image_entry.h include/pkgio.h include/input_file.h
MAIN = main/pkg.c main/util.c main/compressor.c main/command.c main/pkgreader.c
MAIN += main/pkgwriter.c main/image_entry.c main/image_entry_sort.c
MAIN += main/mkdir_p.c main/pkgio_rd_image_entry.c main/pkg_unpack.c
MAIN += main/input_file.c
MAIN += main/input_file.c main/dump_toc.c
pkg_SOURCES = $(GLOBALHDR) $(MAIN)
pkg_CFLAGS = $(AM_CFLAGS)
@ -30,7 +30,7 @@ pkg_SOURCES += main/cmd/pack/pack.h main/cmd/pack/pack.c
pkg_SOURCES += main/cmd/pack/desc.c main/cmd/pack/write_hdr.c
# 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
pkg_SOURCES += main/cmd/dump/dump_header.c
# install command

View file

@ -26,10 +26,18 @@ typedef struct image_entry_t {
} data;
} image_entry_t;
typedef enum {
TOC_FORMAT_PRETTY = 0,
TOC_FORMAT_SQFS = 1,
TOC_FORMAT_INITRD = 2,
} TOC_FORMAT;
void image_entry_free(image_entry_t *ent);
void image_entry_free_list(image_entry_t *list);
image_entry_t *image_entry_sort(image_entry_t *list);
int dump_toc(image_entry_t *list, const char *root, TOC_FORMAT format);
#endif /* IMAGE_ENTRY_H */

View file

@ -14,20 +14,12 @@
#include "pkgio.h"
#include "util.h"
typedef enum {
TOC_FORMAT_PRETTY = 0,
TOC_FORMAT_SQFS = 1,
TOC_FORMAT_INITRD = 2,
} 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_header(pkg_reader_t *pkg, int flags);
#endif /* DUMP_H */

View file

@ -2,13 +2,17 @@
static const struct option long_opts[] = {
{ "root", required_argument, NULL, 'r' },
{ "no-chown", required_argument, NULL, 'o' },
{ "no-chmod", required_argument, NULL, 'm' },
{ "no-chown", no_argument, NULL, 'o' },
{ "no-chmod", no_argument, NULL, 'm' },
{ "no-dependencies", no_argument, NULL, 'd' },
{ "repo-dir", required_argument, NULL, 'R' },
{ "list-packages", no_argument, NULL, 'p' },
{ "list-files", no_argument, NULL, 'l' },
{ "format", required_argument, NULL, 'F' },
{ NULL, 0, NULL, 0 },
};
static const char *short_opts = "R:r:om";
static const char *short_opts = "r:omdRplF:";
static int unpack_packages(int repofd, int rootfd, int flags,
struct pkg_dep_list *list)
@ -32,11 +36,53 @@ static int unpack_packages(int repofd, int rootfd, int flags,
return 0;
}
static void list_packages(struct pkg_dep_list *list)
{
struct pkg_dep_node *it;
for (it = list->head; it != NULL; it = it->next)
printf("%s\n", it->name);
}
static int list_files(int repofd, const char *rootdir, TOC_FORMAT format,
struct pkg_dep_list *list)
{
struct pkg_dep_node *it;
image_entry_t *toc;
pkg_reader_t *rd;
for (it = list->head; it != NULL; it = it->next) {
rd = pkg_reader_open_repo(repofd, it->name);
if (rd == NULL)
return -1;
toc = image_entry_list_from_package(rd);
if (toc == NULL) {
pkg_reader_close(rd);
return -1;
}
if (dump_toc(toc, rootdir, format)) {
image_entry_free_list(toc);
pkg_reader_close(rd);
return -1;
}
image_entry_free_list(toc);
pkg_reader_close(rd);
}
return 0;
}
static int cmd_install(int argc, char **argv)
{
int i, rootfd = AT_FDCWD, repofd = AT_FDCWD, flags = 0;
int ret = EXIT_FAILURE, mode = INSTALL_MODE_INSTALL;
TOC_FORMAT format = TOC_FORMAT_PRETTY;
const char *rootdir = NULL;
struct pkg_dep_list list;
int ret = EXIT_FAILURE;
bool resolve_deps = true;
memset(&list, 0, sizeof(list));
@ -46,6 +92,26 @@ static int cmd_install(int argc, char **argv)
break;
switch (i) {
case 'd':
resolve_deps = false;
break;
case 'p':
mode = INSTALL_MODE_LIST_PKG;
break;
case 'l':
mode = INSTALL_MODE_LIST_FILES;
break;
case 'F':
if (strcmp(optarg, "sqfs") == 0) {
format = TOC_FORMAT_SQFS;
} else if (strcmp(optarg, "initrd") == 0) {
format = TOC_FORMAT_INITRD;
} else {
fprintf(stderr, "unknown format '%s'\n",
optarg);
goto out;
}
break;
case 'R':
if (repofd != AT_FDCWD) {
fputs("repo specified more than once\n",
@ -75,6 +141,8 @@ static int cmd_install(int argc, char **argv)
perror(optarg);
goto out;
}
rootdir = optarg;
break;
case 'o':
flags |= UNPACK_NO_CHOWN;
@ -93,14 +161,27 @@ static int cmd_install(int argc, char **argv)
goto out;
}
if (collect_dependencies(repofd, &list))
goto out;
if (resolve_deps) {
if (collect_dependencies(repofd, &list))
goto out;
if (sort_by_dependencies(&list))
goto out;
if (sort_by_dependencies(&list))
goto out;
}
if (unpack_packages(repofd, rootfd, flags, &list))
goto out;
switch (mode) {
case INSTALL_MODE_LIST_PKG:
list_packages(&list);
break;
case INSTALL_MODE_LIST_FILES:
if (list_files(repofd, rootdir, format, &list))
goto out;
break;
default:
if (unpack_packages(repofd, rootfd, flags, &list))
goto out;
break;
}
ret = EXIT_SUCCESS;
out:
@ -130,7 +211,23 @@ static command_t install = {
" Keep the uid/gid of the user who runs the program.\n"
" --no-chmod, -m Do not change permission flags of the extarcted\n"
" data. Use 0644 for all files and 0755 for all\n"
" directories.\n",
" directories.\n"
" --no-dependencies, -d Do not resolve dependencies, only install files\n"
" packages listed on the command line.\n"
" --list-packages, -p Do not install packages, print out final package\n"
" list that would be installed.\n"
" --list-files, -l Do not install packages, print out table of\n"
" contents for all packages that would be installed.\n"
" --format, -F <format> Specify what format to use for printing the table\n"
" of contents. Default is a pretty printed, human\n"
" readable version.\n"
"\n"
" If \"sqfs\" is specified, a squashfs pseudo file\n"
" is genareated for setting permissions bits and\n"
" ownership appropriately.\n"
"\n"
" If \"initrd\" is specified, a format appropriate\n"
" for Linux gen_init_cpio is produced.\n",
.run_cmd = cmd_install,
};

View file

@ -1,6 +1,7 @@
#ifndef INSTALL_H
#define INSTALL_H
#include <stdbool.h>
#include <getopt.h>
#include <stdlib.h>
#include <unistd.h>
@ -8,11 +9,18 @@
#include <stdio.h>
#include <fcntl.h>
#include "image_entry.h"
#include "pkgreader.h"
#include "command.h"
#include "pkgio.h"
#include "util.h"
enum {
INSTALL_MODE_INSTALL = 0,
INSTALL_MODE_LIST_PKG,
INSTALL_MODE_LIST_FILES,
};
struct pkg_dep_node {
char *name;

View file

@ -1,4 +1,8 @@
#include "dump.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include "image_entry.h"
typedef int (*print_fun_t)(image_entry_t *ent, const char *root);