From 6f32c6b8836059a9ed8cb16382d28b4d57ea9bb7 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 4 Feb 2019 16:26:47 +0100 Subject: [PATCH] Add flag to surpress creation of symlinks when unpacking Signed-off-by: David Oberhollenzer --- include/pkgio.h | 1 + main/cmd/install/install.c | 6 +++++- main/cmd/unpack.c | 6 +++++- main/pkg_unpack.c | 7 +++++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/pkgio.h b/include/pkgio.h index dfafff3..6c00cb8 100644 --- a/include/pkgio.h +++ b/include/pkgio.h @@ -7,6 +7,7 @@ enum { UNPACK_NO_CHOWN = 0x01, UNPACK_NO_CHMOD = 0x02, + UNPACK_NO_SYMLINKS = 0x04, }; int pkg_unpack(int rootfd, int flags, pkg_reader_t *rd); diff --git a/main/cmd/install/install.c b/main/cmd/install/install.c index ca27512..350dfc8 100644 --- a/main/cmd/install/install.c +++ b/main/cmd/install/install.c @@ -9,10 +9,11 @@ static const struct option long_opts[] = { { "list-packages", no_argument, NULL, 'p' }, { "list-files", no_argument, NULL, 'l' }, { "format", required_argument, NULL, 'F' }, + { "no-symlinks", no_argument, NULL, 'L' }, { 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, struct pkg_dep_list *list) @@ -150,6 +151,9 @@ static int cmd_install(int argc, char **argv) case 'm': flags |= UNPACK_NO_CHMOD; break; + case 'L': + flags |= UNPACK_NO_SYMLINKS; + break; default: tell_read_help(argv[0]); goto out; diff --git a/main/cmd/unpack.c b/main/cmd/unpack.c index 1e0e97d..d579a9d 100644 --- a/main/cmd/unpack.c +++ b/main/cmd/unpack.c @@ -14,10 +14,11 @@ static const struct option long_opts[] = { { "root", required_argument, NULL, 'r' }, { "no-chown", no_argument, NULL, 'o' }, { "no-chmod", no_argument, NULL, 'm' }, + { "no-symlinks", no_argument, NULL, 'L' }, { 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) { @@ -34,6 +35,9 @@ static int cmd_unpack(int argc, char **argv) case 'r': root = optarg; break; + case 'L': + flags |= UNPACK_NO_SYMLINKS; + break; case 'o': flags |= UNPACK_NO_CHOWN; break; diff --git a/main/pkg_unpack.c b/main/pkg_unpack.c index 86db2ab..c4238ac 100644 --- a/main/pkg_unpack.c +++ b/main/pkg_unpack.c @@ -9,7 +9,7 @@ #include "pkgio.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; @@ -27,6 +27,9 @@ static int create_hierarchy(int dirfd, image_entry_t *list) for (ent = list; ent != NULL; ent = ent->next) { if (S_ISLNK(ent->mode)) { + if (flags & UNPACK_NO_SYMLINKS) + continue; + if (symlinkat(ent->data.symlink.target, dirfd, ent->name)) { 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)) goto fail; - if (create_hierarchy(rootfd, list)) + if (create_hierarchy(rootfd, list, flags)) goto fail; for (;;) {