package: Suppress version mismatch errors where V1 is supported

* Add flags parameter to Init() of BPackageReader and friends.
* Introduce flag B_HPKG_READER_DONT_PRINT_VERSION_MISMATCH_MESSAGE and
  don't print a version mismatch error when given.
* package extract/list: Use the new flag.
This commit is contained in:
Ingo Weinhold 2013-05-20 20:15:59 +02:00
parent 64bb883062
commit d59e0feb59
12 changed files with 64 additions and 24 deletions

View File

@ -166,6 +166,14 @@ enum {
};
// Reader Init() flags
enum {
B_HPKG_READER_DONT_PRINT_VERSION_MISMATCH_MESSAGE = 0x01
// Fail silently when encountering a package format version mismatch.
// Don't print anything to the error output.
};
enum {
B_HPKG_COMPRESSION_LEVEL_NONE = 0,
B_HPKG_COMPRESSION_LEVEL_FASTEST = 1,

View File

@ -31,8 +31,8 @@ public:
BPackageReader(BErrorOutput* errorOutput);
~BPackageReader();
status_t Init(const char* fileName);
status_t Init(int fd, bool keepFD);
status_t Init(const char* fileName, uint32 flags = 0);
status_t Init(int fd, bool keepFD, uint32 flags = 0);
status_t ParseContent(
BPackageContentHandler* contentHandler);
status_t ParseContent(BLowLevelPackageContentHandler*

View File

@ -28,8 +28,8 @@ public:
PackageReaderImpl(BErrorOutput* errorOutput);
~PackageReaderImpl();
status_t Init(const char* fileName);
status_t Init(int fd, bool keepFD);
status_t Init(const char* fileName, uint32 flags);
status_t Init(int fd, bool keepFD, uint32 flags);
status_t ParseContent(
BPackageContentHandler* contentHandler);
status_t ParseContent(BLowLevelPackageContentHandler*

View File

@ -89,7 +89,8 @@ protected:
protected:
template<typename Header, uint32 kMagic, uint16 kVersion>
status_t Init(int fd, bool keepFD, Header& header);
status_t Init(int fd, bool keepFD, Header& header,
uint32 flags);
status_t InitHeapReader(uint32 compression,
uint32 chunkSize, off_t offset,
uint64 compressedSize,
@ -316,7 +317,7 @@ private:
template<typename Header, uint32 kMagic, uint16 kVersion>
status_t
ReaderImplBase::Init(int fd, bool keepFD, Header& header)
ReaderImplBase::Init(int fd, bool keepFD, Header& header, uint32 flags)
{
status_t error = _Init(fd, keepFD);
if (error != B_OK)
@ -345,9 +346,11 @@ ReaderImplBase::Init(int fd, bool keepFD, Header& header)
// version
if (B_BENDIAN_TO_HOST_INT16(header.version) != kVersion) {
ErrorOutput()->PrintError("Error: Invalid/unsupported %s file "
"version (%d)\n", fFileType,
B_BENDIAN_TO_HOST_INT16(header.version));
if ((flags & B_HPKG_READER_DONT_PRINT_VERSION_MISMATCH_MESSAGE) == 0) {
ErrorOutput()->PrintError("Error: Invalid/unsupported %s file "
"version (%d)\n", fFileType,
B_BENDIAN_TO_HOST_INT16(header.version));
}
return B_MISMATCHED_VALUES;
}

View File

@ -776,14 +776,15 @@ Package::Load()
// try current package file format version
{
PackageReaderImpl packageReader(&errorOutput);
status_t error = packageReader.Init(fd, false);
status_t error = packageReader.Init(fd, false,
BHPKG::B_HPKG_READER_DONT_PRINT_VERSION_MISMATCH_MESSAGE);
if (error == B_OK) {
// parse content
LoaderContentHandler handler(this);
error = handler.Init();
if (error != B_OK)
RETURN_ERROR(error);
error = packageReader.ParseContent(&handler);
if (error != B_OK)
RETURN_ERROR(error);

View File

@ -82,6 +82,12 @@ struct VersionPolicyV1 {
return data.UncompressedSize();
}
static inline status_t InitReader(PackageReader& packageReader,
const char* fileName)
{
return packageReader.Init(fileName);
}
static status_t GetHeapReader(PackageReader& packageReader,
HeapReaderBase*& _heapReader, bool& _mustDelete)
{
@ -128,6 +134,14 @@ struct VersionPolicyV2 {
return data.Size();
}
static inline status_t InitReader(PackageReader& packageReader,
const char* fileName)
{
return packageReader.Init(fileName,
BPackageKit::BHPKG
::B_HPKG_READER_DONT_PRINT_VERSION_MISMATCH_MESSAGE);
}
static status_t GetHeapReader(PackageReader& packageReader,
HeapReaderBase*& _heapReader, bool& _mustDelete)
{
@ -755,7 +769,7 @@ do_extract(const char* packageFileName, const char* changeToDirectory,
}
typename VersionPolicy::PackageReader packageReader(&errorOutput);
status_t error = packageReader.Init(packageFileName);
status_t error = VersionPolicy::InitReader(packageReader, packageFileName);
if (error != B_OK) {
if (ignoreVersionError && error == B_MISMATCHED_VALUES)
return;

View File

@ -47,6 +47,12 @@ struct VersionPolicyV1 {
{
return data.UncompressedSize();
}
static inline status_t InitReader(PackageReader& packageReader,
const char* fileName)
{
return packageReader.Init(fileName);
}
};
struct VersionPolicyV2 {
@ -60,6 +66,14 @@ struct VersionPolicyV2 {
{
return data.Size();
}
static inline status_t InitReader(PackageReader& packageReader,
const char* fileName)
{
return packageReader.Init(fileName,
BPackageKit::BHPKG
::B_HPKG_READER_DONT_PRINT_VERSION_MISMATCH_MESSAGE);
}
};
@ -370,7 +384,7 @@ do_list(const char* packageFileName, bool listAttributes, bool filePathsOnly,
// open package
BStandardErrorOutput errorOutput;
typename VersionPolicy::PackageReader packageReader(&errorOutput);
status_t error = packageReader.Init(packageFileName);
status_t error = VersionPolicy::InitReader(packageReader, packageFileName);
if (error != B_OK) {
if (ignoreVersionError && error == B_MISMATCHED_VALUES)
return;

View File

@ -33,22 +33,22 @@ BPackageReader::~BPackageReader()
status_t
BPackageReader::Init(const char* fileName)
BPackageReader::Init(const char* fileName, uint32 flags)
{
if (fImpl == NULL)
return B_NO_INIT;
return fImpl->Init(fileName);
return fImpl->Init(fileName, flags);
}
status_t
BPackageReader::Init(int fd, bool keepFD)
BPackageReader::Init(int fd, bool keepFD, uint32 flags)
{
if (fImpl == NULL)
return B_NO_INIT;
return fImpl->Init(fd, keepFD);
return fImpl->Init(fd, keepFD, flags);
}

View File

@ -318,7 +318,7 @@ PackageReaderImpl::~PackageReaderImpl()
status_t
PackageReaderImpl::Init(const char* fileName)
PackageReaderImpl::Init(const char* fileName, uint32 flags)
{
// open file
int fd = open(fileName, O_RDONLY);
@ -328,16 +328,16 @@ PackageReaderImpl::Init(const char* fileName)
return errno;
}
return Init(fd, true);
return Init(fd, true, flags);
}
status_t
PackageReaderImpl::Init(int fd, bool keepFD)
PackageReaderImpl::Init(int fd, bool keepFD, uint32 flags)
{
hpkg_header header;
status_t error = inherited::Init<hpkg_header, B_HPKG_MAGIC, B_HPKG_VERSION>(
fd, keepFD, header);
fd, keepFD, header, flags);
if (error != B_OK)
return error;
fHeapSize = HeapReader()->UncompressedHeapSize();

View File

@ -624,7 +624,7 @@ PackageWriterImpl::_Init(const char* fileName,
// in update mode, parse the TOC
if ((Flags() & B_HPKG_WRITER_UPDATE_PACKAGE) != 0) {
PackageReaderImpl packageReader(fListener);
result = packageReader.Init(FD(), false);
result = packageReader.Init(FD(), false, 0);
if (result != B_OK)
return result;

View File

@ -74,7 +74,7 @@ RepositoryReaderImpl::Init(int fd, bool keepFD)
{
hpkg_repo_header header;
status_t error = inherited::Init<hpkg_repo_header, B_HPKG_REPO_MAGIC,
B_HPKG_REPO_VERSION>(fd, keepFD, header);
B_HPKG_REPO_VERSION>(fd, keepFD, header, 0);
if (error != B_OK)
return error;

View File

@ -759,7 +759,7 @@ packagefs_mount_file(int fd, ::Directory*& _mountedDirectory)
{
PackageLoaderErrorOutput errorOutput;
PackageReaderImpl packageReader(&errorOutput);
status_t error = packageReader.Init(fd, false);
status_t error = packageReader.Init(fd, false, 0);
if (error != B_OK)
RETURN_ERROR(error);