diff --git a/headers/os/package/hpkg/HPKGDefs.h b/headers/os/package/hpkg/HPKGDefs.h index b11a788044..9f1029e5e3 100644 --- a/headers/os/package/hpkg/HPKGDefs.h +++ b/headers/os/package/hpkg/HPKGDefs.h @@ -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, diff --git a/headers/os/package/hpkg/PackageReader.h b/headers/os/package/hpkg/PackageReader.h index 3828a4b410..e5b8369385 100644 --- a/headers/os/package/hpkg/PackageReader.h +++ b/headers/os/package/hpkg/PackageReader.h @@ -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* diff --git a/headers/private/package/hpkg/PackageReaderImpl.h b/headers/private/package/hpkg/PackageReaderImpl.h index 7dd0b82cf1..d506b39ded 100644 --- a/headers/private/package/hpkg/PackageReaderImpl.h +++ b/headers/private/package/hpkg/PackageReaderImpl.h @@ -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* diff --git a/headers/private/package/hpkg/ReaderImplBase.h b/headers/private/package/hpkg/ReaderImplBase.h index a8f6830b39..07fc8796b6 100644 --- a/headers/private/package/hpkg/ReaderImplBase.h +++ b/headers/private/package/hpkg/ReaderImplBase.h @@ -89,7 +89,8 @@ protected: protected: template - 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 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; } diff --git a/src/add-ons/kernel/file_systems/packagefs/package/Package.cpp b/src/add-ons/kernel/file_systems/packagefs/package/Package.cpp index 643aa4428b..13d5be71b6 100644 --- a/src/add-ons/kernel/file_systems/packagefs/package/Package.cpp +++ b/src/add-ons/kernel/file_systems/packagefs/package/Package.cpp @@ -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); diff --git a/src/bin/package/command_extract.cpp b/src/bin/package/command_extract.cpp index ae5a6070bd..41d7fb821f 100644 --- a/src/bin/package/command_extract.cpp +++ b/src/bin/package/command_extract.cpp @@ -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; diff --git a/src/bin/package/command_list.cpp b/src/bin/package/command_list.cpp index b6f0b4147a..caebcbf878 100644 --- a/src/bin/package/command_list.cpp +++ b/src/bin/package/command_list.cpp @@ -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; diff --git a/src/kits/package/hpkg/PackageReader.cpp b/src/kits/package/hpkg/PackageReader.cpp index 8453d25b40..1ddeb151e9 100644 --- a/src/kits/package/hpkg/PackageReader.cpp +++ b/src/kits/package/hpkg/PackageReader.cpp @@ -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); } diff --git a/src/kits/package/hpkg/PackageReaderImpl.cpp b/src/kits/package/hpkg/PackageReaderImpl.cpp index bc21926604..acee5c17f2 100644 --- a/src/kits/package/hpkg/PackageReaderImpl.cpp +++ b/src/kits/package/hpkg/PackageReaderImpl.cpp @@ -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( - fd, keepFD, header); + fd, keepFD, header, flags); if (error != B_OK) return error; fHeapSize = HeapReader()->UncompressedHeapSize(); diff --git a/src/kits/package/hpkg/PackageWriterImpl.cpp b/src/kits/package/hpkg/PackageWriterImpl.cpp index 204d3b2b74..7c519c310b 100644 --- a/src/kits/package/hpkg/PackageWriterImpl.cpp +++ b/src/kits/package/hpkg/PackageWriterImpl.cpp @@ -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; diff --git a/src/kits/package/hpkg/RepositoryReaderImpl.cpp b/src/kits/package/hpkg/RepositoryReaderImpl.cpp index 0dc64679df..f59cb8f494 100644 --- a/src/kits/package/hpkg/RepositoryReaderImpl.cpp +++ b/src/kits/package/hpkg/RepositoryReaderImpl.cpp @@ -74,7 +74,7 @@ RepositoryReaderImpl::Init(int fd, bool keepFD) { hpkg_repo_header header; status_t error = inherited::Init(fd, keepFD, header); + B_HPKG_REPO_VERSION>(fd, keepFD, header, 0); if (error != B_OK) return error; diff --git a/src/system/boot/loader/file_systems/packagefs/packagefs.cpp b/src/system/boot/loader/file_systems/packagefs/packagefs.cpp index 390fe2b9ad..6257d53a01 100644 --- a/src/system/boot/loader/file_systems/packagefs/packagefs.cpp +++ b/src/system/boot/loader/file_systems/packagefs/packagefs.cpp @@ -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);