From 677d3240a845833dfb5c76491c0fd05efb934b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Mon, 26 Jun 2017 14:29:29 +0300 Subject: [PATCH] tar: use standard header prefix APKs have been created with GNU tar so far, which uses the GNU extensions for long names. In order to increase portability support the standard header's 'prefix' portion in case the GNU extensions are not present. --- src/archive.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/archive.c b/src/archive.c index 438eb94..b1f9c30 100644 --- a/src/archive.c +++ b/src/archive.c @@ -206,10 +206,12 @@ int apk_tar_parse(struct apk_istream *is, apk_archive_entry_parser parser, int end = 0, r; size_t toskip, paxlen = 0; apk_blob_t pax = APK_BLOB_NULL, longname = APK_BLOB_NULL; + char filename[sizeof buf.name + sizeof buf.prefix + 2]; odi = (struct apk_tar_digest_info *) &buf.linkname[3]; EVP_MD_CTX_init(&teis.mdctx); memset(&entry, 0, sizeof(entry)); + entry.name = buf.name; while ((r = apk_istream_read(is, &buf, 512)) == 512) { offset += 512; if (buf.name[0] == '\0') { @@ -224,13 +226,19 @@ int apk_tar_parse(struct apk_istream *is, apk_archive_entry_parser parser, .gid = apk_resolve_gid(idc, buf.gname, GET_OCTAL(buf.gid)), .mode = GET_OCTAL(buf.mode) & 07777, .mtime = GET_OCTAL(buf.mtime), - .name = entry.name ?: buf.name, + .name = entry.name, .uname = buf.uname, .gname = buf.gname, .device = makedev(GET_OCTAL(buf.devmajor), GET_OCTAL(buf.devminor)), .xattrs = entry.xattrs, }; + if (buf.prefix[0] && buf.typeflag != 'x' && buf.typeflag != 'g') { + snprintf(filename, sizeof filename, "%.*s/%.*s", + (int) sizeof buf.prefix, buf.prefix, + (int) sizeof buf.name, buf.name); + entry.name = filename; + } buf.mode[0] = 0; /* to nul terminate 100-byte buf.name */ buf.magic[0] = 0; /* to nul terminate 100-byte buf.linkname */ teis.csum = NULL;