Add flag to surpress creation of symlinks when unpacking

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2019-02-04 16:26:47 +01:00
parent deb7bb0d4e
commit 6f32c6b883
4 changed files with 16 additions and 4 deletions

View File

@ -7,6 +7,7 @@
enum { enum {
UNPACK_NO_CHOWN = 0x01, UNPACK_NO_CHOWN = 0x01,
UNPACK_NO_CHMOD = 0x02, UNPACK_NO_CHMOD = 0x02,
UNPACK_NO_SYMLINKS = 0x04,
}; };
int pkg_unpack(int rootfd, int flags, pkg_reader_t *rd); int pkg_unpack(int rootfd, int flags, pkg_reader_t *rd);

View File

@ -9,10 +9,11 @@ static const struct option long_opts[] = {
{ "list-packages", no_argument, NULL, 'p' }, { "list-packages", no_argument, NULL, 'p' },
{ "list-files", no_argument, NULL, 'l' }, { "list-files", no_argument, NULL, 'l' },
{ "format", required_argument, NULL, 'F' }, { "format", required_argument, NULL, 'F' },
{ "no-symlinks", no_argument, NULL, 'L' },
{ NULL, 0, NULL, 0 }, { NULL, 0, NULL, 0 },
}; };
static const char *short_opts = "r:omdR:plF:"; static const char *short_opts = "r:omdR:plF:L";
static int unpack_packages(int repofd, int rootfd, int flags, static int unpack_packages(int repofd, int rootfd, int flags,
struct pkg_dep_list *list) struct pkg_dep_list *list)
@ -150,6 +151,9 @@ static int cmd_install(int argc, char **argv)
case 'm': case 'm':
flags |= UNPACK_NO_CHMOD; flags |= UNPACK_NO_CHMOD;
break; break;
case 'L':
flags |= UNPACK_NO_SYMLINKS;
break;
default: default:
tell_read_help(argv[0]); tell_read_help(argv[0]);
goto out; goto out;

View File

@ -14,10 +14,11 @@ static const struct option long_opts[] = {
{ "root", required_argument, NULL, 'r' }, { "root", required_argument, NULL, 'r' },
{ "no-chown", no_argument, NULL, 'o' }, { "no-chown", no_argument, NULL, 'o' },
{ "no-chmod", no_argument, NULL, 'm' }, { "no-chmod", no_argument, NULL, 'm' },
{ "no-symlinks", no_argument, NULL, 'L' },
{ NULL, 0, NULL, 0 }, { NULL, 0, NULL, 0 },
}; };
static const char *short_opts = "r:om"; static const char *short_opts = "r:omL";
static int cmd_unpack(int argc, char **argv) static int cmd_unpack(int argc, char **argv)
{ {
@ -34,6 +35,9 @@ static int cmd_unpack(int argc, char **argv)
case 'r': case 'r':
root = optarg; root = optarg;
break; break;
case 'L':
flags |= UNPACK_NO_SYMLINKS;
break;
case 'o': case 'o':
flags |= UNPACK_NO_CHOWN; flags |= UNPACK_NO_CHOWN;
break; break;

View File

@ -9,7 +9,7 @@
#include "pkgio.h" #include "pkgio.h"
#include "util/util.h" #include "util/util.h"
static int create_hierarchy(int dirfd, image_entry_t *list) static int create_hierarchy(int dirfd, image_entry_t *list, int flags)
{ {
image_entry_t *ent; image_entry_t *ent;
@ -27,6 +27,9 @@ static int create_hierarchy(int dirfd, image_entry_t *list)
for (ent = list; ent != NULL; ent = ent->next) { for (ent = list; ent != NULL; ent = ent->next) {
if (S_ISLNK(ent->mode)) { if (S_ISLNK(ent->mode)) {
if (flags & UNPACK_NO_SYMLINKS)
continue;
if (symlinkat(ent->data.symlink.target, if (symlinkat(ent->data.symlink.target,
dirfd, ent->name)) { dirfd, ent->name)) {
fprintf(stderr, "symlink %s to %s: %s\n", fprintf(stderr, "symlink %s to %s: %s\n",
@ -175,7 +178,7 @@ int pkg_unpack(int rootfd, int flags, pkg_reader_t *rd)
if (pkg_reader_rewind(rd)) if (pkg_reader_rewind(rd))
goto fail; goto fail;
if (create_hierarchy(rootfd, list)) if (create_hierarchy(rootfd, list, flags))
goto fail; goto fail;
for (;;) { for (;;) {