Package Kit: add Zstd compression.
Change-Id: Idbdb7cf1bde659046a88ea69a76e3b5fc4cd7013 Reviewed-on: https://review.haiku-os.org/323 Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
b8a38e2bc1
commit
81375d4fbb
@@ -98,7 +98,8 @@ enum BHPKGAttributeID {
|
|||||||
// compression types
|
// compression types
|
||||||
enum {
|
enum {
|
||||||
B_HPKG_COMPRESSION_NONE = 0,
|
B_HPKG_COMPRESSION_NONE = 0,
|
||||||
B_HPKG_COMPRESSION_ZLIB = 1
|
B_HPKG_COMPRESSION_ZLIB = 1,
|
||||||
|
B_HPKG_COMPRESSION_ZSTD = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,17 @@ UseBuildFeatureHeaders zlib ;
|
|||||||
UsePrivateKernelHeaders ;
|
UsePrivateKernelHeaders ;
|
||||||
UsePrivateHeaders package shared storage support ;
|
UsePrivateHeaders package shared storage support ;
|
||||||
|
|
||||||
|
local zstdSources ;
|
||||||
|
local zstdKernelLib ;
|
||||||
|
|
||||||
|
if [ FIsBuildFeatureEnabled zstd ] {
|
||||||
|
zstdSources = ZstdCompressionAlgorithm.cpp ;
|
||||||
|
zstdKernelLib = kernel_libzstd.a ;
|
||||||
|
UseBuildFeatureHeaders zstd ;
|
||||||
|
Includes [ FGristFiles $(zstdSources) ]
|
||||||
|
: [ BuildFeatureAttribute zstd : headers ] ;
|
||||||
|
SubDirC++Flags -DZSTD_ENABLED ;
|
||||||
|
}
|
||||||
|
|
||||||
local subDirs =
|
local subDirs =
|
||||||
indices
|
indices
|
||||||
@@ -117,6 +128,7 @@ local storageKitSources =
|
|||||||
local supportKitSources =
|
local supportKitSources =
|
||||||
CompressionAlgorithm.cpp
|
CompressionAlgorithm.cpp
|
||||||
ZlibCompressionAlgorithm.cpp
|
ZlibCompressionAlgorithm.cpp
|
||||||
|
$(zstdSources)
|
||||||
;
|
;
|
||||||
|
|
||||||
KernelAddon packagefs
|
KernelAddon packagefs
|
||||||
@@ -129,7 +141,7 @@ KernelAddon packagefs
|
|||||||
$(storageKitSources)
|
$(storageKitSources)
|
||||||
$(supportKitSources)
|
$(supportKitSources)
|
||||||
|
|
||||||
: kernel_libz.a
|
: kernel_libz.a $(zstdKernelLib)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ command_create(int argc, const char* const* argv)
|
|||||||
bool quiet = false;
|
bool quiet = false;
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
int32 compressionLevel = BPackageKit::BHPKG::B_HPKG_COMPRESSION_LEVEL_BEST;
|
int32 compressionLevel = BPackageKit::BHPKG::B_HPKG_COMPRESSION_LEVEL_BEST;
|
||||||
|
int32 compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_ZLIB;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
static struct option sLongOptions[] = {
|
static struct option sLongOptions[] = {
|
||||||
@@ -49,7 +50,7 @@ command_create(int argc, const char* const* argv)
|
|||||||
};
|
};
|
||||||
|
|
||||||
opterr = 0; // don't print errors
|
opterr = 0; // don't print errors
|
||||||
int c = getopt_long(argc, (char**)argv, "+b0123456789C:hi:I:qv",
|
int c = getopt_long(argc, (char**)argv, "+b0123456789C:hi:I:qvz",
|
||||||
sLongOptions, NULL);
|
sLongOptions, NULL);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
@@ -96,6 +97,10 @@ command_create(int argc, const char* const* argv)
|
|||||||
verbose = true;
|
verbose = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'z':
|
||||||
|
compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_ZSTD;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
print_usage_and_exit(true);
|
print_usage_and_exit(true);
|
||||||
break;
|
break;
|
||||||
@@ -123,6 +128,10 @@ command_create(int argc, const char* const* argv)
|
|||||||
BPackageKit::BHPKG::B_HPKG_COMPRESSION_NONE);
|
BPackageKit::BHPKG::B_HPKG_COMPRESSION_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (compressionLevel == 0)
|
||||||
|
compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_NONE;
|
||||||
|
writerParameters.SetCompression(compression);
|
||||||
|
|
||||||
PackageWriterListener listener(verbose, quiet);
|
PackageWriterListener listener(verbose, quiet);
|
||||||
BPackageWriter packageWriter(&listener);
|
BPackageWriter packageWriter(&listener);
|
||||||
status_t result = packageWriter.Init(packageFileName, &writerParameters);
|
status_t result = packageWriter.Init(packageFileName, &writerParameters);
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ command_recompress(int argc, const char* const* argv)
|
|||||||
bool quiet = false;
|
bool quiet = false;
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
int32 compressionLevel = BPackageKit::BHPKG::B_HPKG_COMPRESSION_LEVEL_BEST;
|
int32 compressionLevel = BPackageKit::BHPKG::B_HPKG_COMPRESSION_LEVEL_BEST;
|
||||||
|
int32 compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_ZLIB;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
static struct option sLongOptions[] = {
|
static struct option sLongOptions[] = {
|
||||||
@@ -55,7 +56,7 @@ command_recompress(int argc, const char* const* argv)
|
|||||||
};
|
};
|
||||||
|
|
||||||
opterr = 0; // don't print errors
|
opterr = 0; // don't print errors
|
||||||
int c = getopt_long(argc, (char**)argv, "+0123456789:hqv",
|
int c = getopt_long(argc, (char**)argv, "+0123456789:hqvz",
|
||||||
sLongOptions, NULL);
|
sLongOptions, NULL);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
@@ -86,6 +87,10 @@ command_recompress(int argc, const char* const* argv)
|
|||||||
verbose = true;
|
verbose = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'z':
|
||||||
|
compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_ZSTD;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
print_usage_and_exit(true);
|
print_usage_and_exit(true);
|
||||||
break;
|
break;
|
||||||
@@ -124,6 +129,10 @@ command_recompress(int argc, const char* const* argv)
|
|||||||
BPackageKit::BHPKG::B_HPKG_COMPRESSION_NONE);
|
BPackageKit::BHPKG::B_HPKG_COMPRESSION_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (compressionLevel == 0)
|
||||||
|
compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_NONE;
|
||||||
|
writerParameters.SetCompression(compression);
|
||||||
|
|
||||||
PackageWriterListener listener(verbose, quiet);
|
PackageWriterListener listener(verbose, quiet);
|
||||||
BPackageWriter packageWriter(&listener);
|
BPackageWriter packageWriter(&listener);
|
||||||
if (strcmp(outputPackageFileName, "-") == 0) {
|
if (strcmp(outputPackageFileName, "-") == 0) {
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ static const char* kUsage =
|
|||||||
"\n"
|
"\n"
|
||||||
" -q - Be quiet (don't show any output except for errors).\n"
|
" -q - Be quiet (don't show any output except for errors).\n"
|
||||||
" -v - Be verbose (show more info about created package).\n"
|
" -v - Be verbose (show more info about created package).\n"
|
||||||
|
" -z - Use Zstd compression.\n"
|
||||||
"\n"
|
"\n"
|
||||||
" create [ <options> ] <package>\n"
|
" create [ <options> ] <package>\n"
|
||||||
" Creates package file <package> from contents of current directory.\n"
|
" Creates package file <package> from contents of current directory.\n"
|
||||||
@@ -120,6 +121,7 @@ static const char* kUsage =
|
|||||||
" Defaults to 9.\n"
|
" Defaults to 9.\n"
|
||||||
" -q - Be quiet (don't show any output except for errors).\n"
|
" -q - Be quiet (don't show any output except for errors).\n"
|
||||||
" -v - Be verbose (show more info about created package).\n"
|
" -v - Be verbose (show more info about created package).\n"
|
||||||
|
" -z - Use Zstd compression.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Common Options:\n"
|
"Common Options:\n"
|
||||||
" -h, --help - Print this usage info.\n"
|
" -h, --help - Print this usage info.\n"
|
||||||
|
|||||||
@@ -62,7 +62,9 @@ local architectureObject ;
|
|||||||
for architectureObject in [ MultiArchSubDirSetup ] {
|
for architectureObject in [ MultiArchSubDirSetup ] {
|
||||||
on $(architectureObject) {
|
on $(architectureObject) {
|
||||||
UseBuildFeatureHeaders curl ;
|
UseBuildFeatureHeaders curl ;
|
||||||
|
if [ FIsBuildFeatureEnabled zstd ] {
|
||||||
|
SubDirC++Flags -DZSTD_ENABLED ;
|
||||||
|
}
|
||||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg ] ;
|
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg ] ;
|
||||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg v1 ] ;
|
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg v1 ] ;
|
||||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package manager ] ;
|
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package manager ] ;
|
||||||
|
|||||||
@@ -20,6 +20,9 @@
|
|||||||
#include <DataIO.h>
|
#include <DataIO.h>
|
||||||
|
|
||||||
#include <ZlibCompressionAlgorithm.h>
|
#include <ZlibCompressionAlgorithm.h>
|
||||||
|
#ifdef ZSTD_ENABLED
|
||||||
|
#include <ZstdCompressionAlgorithm.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <package/hpkg/HPKGDefsPrivate.h>
|
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||||
#include <package/hpkg/PackageFileHeapReader.h>
|
#include <package/hpkg/PackageFileHeapReader.h>
|
||||||
@@ -824,6 +827,19 @@ ReaderImplBase::InitHeapReader(uint32 compression, uint32 chunkSize,
|
|||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#ifdef ZSTD_ENABLED
|
||||||
|
case B_HPKG_COMPRESSION_ZSTD:
|
||||||
|
decompressionAlgorithm = DecompressionAlgorithmOwner::Create(
|
||||||
|
new(std::nothrow) BZstdCompressionAlgorithm,
|
||||||
|
new(std::nothrow) BZstdDecompressionParameters);
|
||||||
|
decompressionAlgorithmReference.SetTo(decompressionAlgorithm, true);
|
||||||
|
if (decompressionAlgorithm == NULL
|
||||||
|
|| decompressionAlgorithm->algorithm == NULL
|
||||||
|
|| decompressionAlgorithm->parameters == NULL) {
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
fErrorOutput->PrintError("Error: Invalid heap compression\n");
|
fErrorOutput->PrintError("Error: Invalid heap compression\n");
|
||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
|
|||||||
@@ -20,6 +20,9 @@
|
|||||||
|
|
||||||
#include <AutoDeleter.h>
|
#include <AutoDeleter.h>
|
||||||
#include <ZlibCompressionAlgorithm.h>
|
#include <ZlibCompressionAlgorithm.h>
|
||||||
|
#ifdef ZSTD_ENABLED
|
||||||
|
#include <ZstdCompressionAlgorithm.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <package/hpkg/DataReader.h>
|
#include <package/hpkg/DataReader.h>
|
||||||
#include <package/hpkg/ErrorOutput.h>
|
#include <package/hpkg/ErrorOutput.h>
|
||||||
@@ -326,6 +329,29 @@ WriterImplBase::InitHeapReader(size_t headerSize)
|
|||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#ifdef ZSTD_ENABLED
|
||||||
|
case B_HPKG_COMPRESSION_ZSTD:
|
||||||
|
compressionAlgorithm = CompressionAlgorithmOwner::Create(
|
||||||
|
new(std::nothrow) BZstdCompressionAlgorithm,
|
||||||
|
new(std::nothrow) BZstdCompressionParameters(
|
||||||
|
fParameters.CompressionLevel()));
|
||||||
|
compressionAlgorithmReference.SetTo(compressionAlgorithm, true);
|
||||||
|
|
||||||
|
decompressionAlgorithm = DecompressionAlgorithmOwner::Create(
|
||||||
|
new(std::nothrow) BZstdCompressionAlgorithm,
|
||||||
|
new(std::nothrow) BZstdDecompressionParameters);
|
||||||
|
decompressionAlgorithmReference.SetTo(decompressionAlgorithm, true);
|
||||||
|
|
||||||
|
if (compressionAlgorithm == NULL
|
||||||
|
|| compressionAlgorithm->algorithm == NULL
|
||||||
|
|| compressionAlgorithm->parameters == NULL
|
||||||
|
|| decompressionAlgorithm == NULL
|
||||||
|
|| decompressionAlgorithm->algorithm == NULL
|
||||||
|
|| decompressionAlgorithm->parameters == NULL) {
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
fErrorOutput->PrintError("Error: Invalid heap compression\n");
|
fErrorOutput->PrintError("Error: Invalid heap compression\n");
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|||||||
Reference in New Issue
Block a user