From 2735bc00e35c5fd8eec6d656f4d8a17ee2630c2a Mon Sep 17 00:00:00 2001 From: Aaro Koskinen Date: Fri, 16 Oct 2015 17:24:46 +0200 Subject: cpio: implement -R/--owner Implement -R/--owner to force ownership of files. function old new delta cpio_main 532 586 +54 get_header_cpio 909 939 +30 print 36 65 +29 cpio_o 804 832 +28 cpio_TRAILER - 11 +11 packed_usage 30667 30662 -5 static.trailer 11 - -11 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 4/1 up/down: 152/-16) Total: 136 bytes Signed-off-by: Aaro Koskinen Signed-off-by: Denys Vlasenko --- archival/libarchive/Kbuild.src | 2 +- archival/libarchive/common.c | 9 +++++++++ archival/libarchive/get_header_cpio.c | 7 ++++++- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 archival/libarchive/common.c (limited to 'archival/libarchive') diff --git a/archival/libarchive/Kbuild.src b/archival/libarchive/Kbuild.src index b7faaf7..b159a78 100644 --- a/archival/libarchive/Kbuild.src +++ b/archival/libarchive/Kbuild.src @@ -4,7 +4,7 @@ # # Licensed under GPLv2 or later, see file LICENSE in this source tree. -lib-y:= +lib-y:= common.o COMMON_FILES:= \ \ diff --git a/archival/libarchive/common.c b/archival/libarchive/common.c new file mode 100644 index 0000000..dd69d22 --- /dev/null +++ b/archival/libarchive/common.c @@ -0,0 +1,9 @@ +/* vi: set sw=4 ts=4: */ +/* + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + */ + +#include "libbb.h" +#include "bb_archive.h" + +const char cpio_TRAILER[] = "TRAILER!!!"; diff --git a/archival/libarchive/get_header_cpio.c b/archival/libarchive/get_header_cpio.c index 7861d1f..badd4a8 100644 --- a/archival/libarchive/get_header_cpio.c +++ b/archival/libarchive/get_header_cpio.c @@ -52,6 +52,11 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle) &major, &minor, &namesize) != 10) bb_error_msg_and_die("damaged cpio file"); file_header->mode = mode; + /* "cpio -R USER:GRP" support: */ + if (archive_handle->cpio__owner.uid != (uid_t)-1L) + uid = archive_handle->cpio__owner.uid; + if (archive_handle->cpio__owner.gid != (gid_t)-1L) + gid = archive_handle->cpio__owner.gid; file_header->uid = uid; file_header->gid = gid; file_header->mtime = mtime; @@ -75,7 +80,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle) /* Update offset amount and skip padding before file contents */ data_align(archive_handle, 4); - if (strcmp(file_header->name, "TRAILER!!!") == 0) { + if (strcmp(file_header->name, cpio_TRAILER) == 0) { /* Always round up. ">> 9" divides by 512 */ archive_handle->cpio__blocks = (uoff_t)(archive_handle->offset + 511) >> 9; goto create_hardlinks; -- cgit v1.1