package command: -z now takes an argument to specify the compression method.

The upcoming change to use zstd by default will make the -z no-argument
variant obsolete, so instead we need to support passing "zstd" or "zlib"
to actually indicate the compression method we want to use.
This commit is contained in:
Augustin Cavalier
2021-10-26 16:24:22 -04:00
parent fd7438acec
commit fd276f19fe
4 changed files with 38 additions and 14 deletions
+6 -6
View File
@@ -40,7 +40,7 @@ command_create(int argc, const char* const* argv)
bool quiet = false;
bool verbose = false;
int32 compressionLevel = BPackageKit::BHPKG::B_HPKG_COMPRESSION_LEVEL_BEST;
int32 compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_ZLIB;
int32 compression = parse_compression_argument(NULL);
while (true) {
static struct option sLongOptions[] = {
@@ -51,7 +51,7 @@ command_create(int argc, const char* const* argv)
};
opterr = 0; // don't print errors
int c = getopt_long(argc, (char**)argv, "+b0123456789C:hi:I:qvz",
int c = getopt_long(argc, (char**)argv, "+b0123456789C:hi:I:z:qv",
sLongOptions, NULL);
if (c == -1)
break;
@@ -90,6 +90,10 @@ command_create(int argc, const char* const* argv)
installPath = optarg;
break;
case 'z':
compression = parse_compression_argument(optarg);
break;
case 'q':
quiet = true;
break;
@@ -98,10 +102,6 @@ command_create(int argc, const char* const* argv)
verbose = true;
break;
case 'z':
compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_ZSTD;
break;
default:
print_usage_and_exit(true);
break;
+6 -6
View File
@@ -45,7 +45,7 @@ command_recompress(int argc, const char* const* argv)
bool quiet = false;
bool verbose = false;
int32 compressionLevel = BPackageKit::BHPKG::B_HPKG_COMPRESSION_LEVEL_BEST;
int32 compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_ZLIB;
int32 compression = parse_compression_argument(NULL);
while (true) {
static struct option sLongOptions[] = {
@@ -56,7 +56,7 @@ command_recompress(int argc, const char* const* argv)
};
opterr = 0; // don't print errors
int c = getopt_long(argc, (char**)argv, "+0123456789:hqvz",
int c = getopt_long(argc, (char**)argv, "+0123456789:hz:qv",
sLongOptions, NULL);
if (c == -1)
break;
@@ -79,6 +79,10 @@ command_recompress(int argc, const char* const* argv)
print_usage_and_exit(false);
break;
case 'z':
compression = parse_compression_argument(optarg);
break;
case 'q':
quiet = true;
break;
@@ -87,10 +91,6 @@ command_recompress(int argc, const char* const* argv)
verbose = true;
break;
case 'z':
compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_ZSTD;
break;
default:
print_usage_and_exit(true);
break;
+23 -2
View File
@@ -13,6 +13,8 @@
#include <stdlib.h>
#include <string.h>
#include <package/hpkg/HPKGDefs.h>
extern const char* __progname;
const char* kCommandName = __progname;
@@ -61,7 +63,7 @@ static const char* kUsage =
" an option only for use in package building. It will cause\n"
" the package .self link to point to <path>, which is useful\n"
" to redirect a \"make install\". Only allowed with -b.\n"
" -z - Use Zstd compression.\n"
" -z <type> - Specify compression method to use.\n"
" -q - Be quiet (don't show any output except for errors).\n"
" -v - Be verbose (show more info about created package).\n"
"\n"
@@ -107,7 +109,7 @@ static const char* kUsage =
"\n"
" -0 ... -9 - Use compression level 0 ... 9. 0 means no, 9 best compression.\n"
" Defaults to 9.\n"
" -z - Use Zstd compression.\n"
" -z <type> - Specify compression method to use.\n"
" -q - Be quiet (don't show any output except for errors).\n"
" -v - Be verbose (show more info about created package).\n"
"\n"
@@ -124,6 +126,25 @@ print_usage_and_exit(bool error)
}
int32
parse_compression_argument(const char* arg)
{
if (arg == NULL) {
// Default compression method.
return BPackageKit::BHPKG::B_HPKG_COMPRESSION_ZLIB;
}
if (strcmp(arg, "zstd") == 0) {
return BPackageKit::BHPKG::B_HPKG_COMPRESSION_ZSTD;
} else if (strcmp(arg, "zlib") == 0) {
return BPackageKit::BHPKG::B_HPKG_COMPRESSION_ZLIB;
} else {
fprintf(stderr, "error: unknown compression method '%s'\n", arg);
exit(1);
}
}
int
main(int argc, const char* const* argv)
{
+3
View File
@@ -5,8 +5,11 @@
#ifndef PACKAGE_H
#define PACKAGE_H
#include <SupportDefs.h>
void print_usage_and_exit(bool error);
int32 parse_compression_argument(const char* arg);
int command_add(int argc, const char* const* argv);
int command_checksum(int argc, const char* const* argv);