[git commit] rpm2cpio: use rpm_gettags

Denys Vlasenko vda.linux at googlemail.com
Thu Aug 10 07:56:49 UTC 2017


commit: https://git.busybox.net/busybox/commit/?id=3c9b8fe25233dc52bbeec2ab29e49b8f62e4739b
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
rpm_gettags                                            -     451    +451
rpm2cpio_main                                        140      78     -62
skip_header                                           92       -     -92
rpm_main                                            1477    1049    -428
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 451/-582)         Total: -131 bytes

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 archival/rpm.c | 54 ++++++++++--------------------------------------------
 1 file changed, 10 insertions(+), 44 deletions(-)

diff --git a/archival/rpm.c b/archival/rpm.c
index 461e170..f46d88b 100644
--- a/archival/rpm.c
+++ b/archival/rpm.c
@@ -124,7 +124,13 @@ static int rpm_gettags(const char *filename)
 	unsigned pass, idx;
 	unsigned storepos;
 
-	fd = xopen(filename, O_RDONLY);
+	if (!filename) { /* rpm2cpio w/o filename? */
+		filename = bb_msg_standard_output;
+		fd = 0;
+	} else {
+		fd = xopen(filename, O_RDONLY);
+	}
+
 	storepos = xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
 	G.tagcount = 0;
 	tags = NULL;
@@ -500,55 +506,15 @@ int rpm_main(int argc, char **argv)
 //usage:#define rpm2cpio_full_usage "\n\n"
 //usage:       "Output a cpio archive of the rpm file"
 
-enum { rpm_fd = STDIN_FILENO };
-
-static unsigned skip_header(void)
-{
-	struct rpm_header header;
-	unsigned len;
-
-	xread(rpm_fd, &header, sizeof(header));
-//	if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC_STR, 3) != 0) {
-//		bb_error_msg_and_die("invalid RPM header magic");
-//	}
-//	if (header.version != 1) {
-//		bb_error_msg_and_die("unsupported RPM header version");
-//	}
-	if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER)) {
-		bb_error_msg_and_die("invalid RPM header magic or unsupported version");
-		// ": %x != %x", header.magic_and_ver, htonl(RPM_HEADER_MAGICnVER));
-	}
-
-	/* Seek past index entries, and past store */
-	len = 16 * ntohl(header.entries) + ntohl(header.size);
-	seek_by_jump(rpm_fd, len);
-
-	return sizeof(header) + len;
-}
-
 /* No getopt required */
 int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
 {
-	struct rpm_lead lead;
-	unsigned pos;
-
-	if (argv[1]) {
-		xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd);
-	}
-	xread(rpm_fd, &lead, sizeof(lead));
+	int rpm_fd;
 
-	/* Just check the magic, the rest is irrelevant */
-	if (lead.magic != htonl(RPM_LEAD_MAGIC)) {
-		bb_error_msg_and_die("invalid RPM magic");
-	}
-
-	/* Skip the signature header, align to 8 bytes */
-	pos = skip_header();
-	seek_by_jump(rpm_fd, (-(int)pos) & 7);
+	G.pagesize = getpagesize();
 
-	/* Skip the main header */
-	skip_header();
+	rpm_fd = rpm_gettags(argv[1]);
 
 	//if (SEAMLESS_COMPRESSION) - we do this at the end instead.
 	//	/* We need to know whether child (gzip/bzip/etc) exits abnormally */


More information about the busybox-cvs mailing list