Skip to content

Commit

Permalink
rpmuncompress: Support -C for zip and 7zip archives
Browse files Browse the repository at this point in the history
As both don't support an equivalent to tars --strip-components=1 we move
the files out of top directory ourselves with shell commands.

Support for Ruby gems is still missing - iff at all possible or
desirable.

Resolves: rpm-software-management#3249
  • Loading branch information
ffesti committed Aug 29, 2024
1 parent cc2091f commit de7c318
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions tools/rpmuncompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,20 @@ struct archiveType_s {
const char *cmd;
const char *unpack;
const char *quiet;
const char *dest;
int setTZ;
} archiveTypes[] = {
{ COMPRESSED_NOT, 0, "%{__cat}" , "", "", 0 },
{ COMPRESSED_OTHER, 0, "%{__gzip}", "-dc", "", 0 },
{ COMPRESSED_BZIP2, 0, "%{__bzip2}", "-dc", "", 0 },
{ COMPRESSED_ZIP, 1, "%{__unzip}", "", "-qq", 1 },
{ COMPRESSED_LZMA, 0, "%{__xz}", "-dc", "", 0 },
{ COMPRESSED_XZ, 0, "%{__xz}", "-dc", "", 0 },
{ COMPRESSED_LZIP, 0, "%{__lzip}", "-dc", "", 0 },
{ COMPRESSED_LRZIP, 0, "%{__lrzip}", "-dqo-", "", 0 },
{ COMPRESSED_7ZIP, 1, "%{__7zip}", "x", "", 0 },
{ COMPRESSED_ZSTD, 0, "%{__zstd}", "-dc", "", 0 },
{ COMPRESSED_GEM, 1, "%{__gem}", "unpack", "", 0 },
{ COMPRESSED_NOT, 0, "%{__cat}" , "", "", "", 0 },
{ COMPRESSED_OTHER, 0, "%{__gzip}", "-dc", "", "", 0 },
{ COMPRESSED_BZIP2, 0, "%{__bzip2}", "-dc", "", "", 0 },
{ COMPRESSED_ZIP, 1, "%{__unzip}", "", "-qq", "-d", 1 },
{ COMPRESSED_LZMA, 0, "%{__xz}", "-dc", "", "", 0 },
{ COMPRESSED_XZ, 0, "%{__xz}", "-dc", "", "", 0 },
{ COMPRESSED_LZIP, 0, "%{__lzip}", "-dc", "", "", 0 },
{ COMPRESSED_LRZIP, 0, "%{__lrzip}", "-dqo-", "", "", 0 },
{ COMPRESSED_7ZIP, 1, "%{__7zip}", "x", "", "-o", 0 },
{ COMPRESSED_ZSTD, 0, "%{__zstd}", "-dc", "", "", 0 },
{ COMPRESSED_GEM, 1, "%{__gem}", "unpack", "", "--target=", 0 },
{ -1, 0, NULL, NULL, NULL, 0 },
};

Expand Down Expand Up @@ -151,6 +152,8 @@ static char *doUntar(const char *fn)
if ((at = getArchiver(fn)) == NULL)
goto exit;

int needtar = (at->extractable == 0);

if (dstpath) {
char * sr = singleRoot(fn);

Expand All @@ -159,7 +162,15 @@ static char *doUntar(const char *fn)
* strip the first path entry and extract in the destination path
*/
rasprintf(&mkdir, "mkdir '%s' ; ", dstpath);
rasprintf(&stripcd, " -C '%s' %s", dstpath, sr ? "--strip-components=1" : "");
if (needtar)
rasprintf(&stripcd, " -C '%s' %s", dstpath, sr ? "--strip-components=1" : "");
else {
char * moveup;
if (sr)
rasprintf(&moveup, " ; tmp=`mktemp -u -p'%s'` ; mv %s/%s $tmp ; (shopt -s dotglob; mv $tmp/* %s) ; rmdir $tmp ", dstpath, dstpath, sr, dstpath);
rasprintf(&stripcd, "%s'%s'%s", at->dest, dstpath, sr ? moveup : "");
free(moveup);
}
free(sr);
} else {
mkdir = strdup("");
Expand All @@ -168,7 +179,6 @@ static char *doUntar(const char *fn)
tar = rpmGetPath("%{__tar}", NULL);
if (at->compressed != COMPRESSED_NOT) {
char *zipper = NULL;
int needtar = (at->extractable == 0);

zipper = rpmExpand(at->setTZ ? "TZ=UTC " : "",
at->cmd, " ", at->unpack, " ",
Expand All @@ -193,7 +203,7 @@ static char *doUntar(const char *fn)
free(gem);
free(tmp);
} else {
rasprintf(&buf, "%s '%s'", zipper, fn);
rasprintf(&buf, "%s%s '%s' %s", mkdir, zipper, fn, stripcd);
}
free(zipper);
} else {
Expand Down

0 comments on commit de7c318

Please sign in to comment.