From 31d70c106be1a8f0f0b50dba3a5020adf6421147 Mon Sep 17 00:00:00 2001 From: "Alexander G. M. Smith" Date: Tue, 13 Aug 2019 19:17:18 -0400 Subject: [PATCH] package kit: Skip over future package attributes. Ignore unknown fields (also called attributes) which are from a package file with a different minor version number. Previously it would halt with an error when encountering such a field, even though it can safely be skipped over (if it was unsafe, we would have incremented the major version number). The use case is a future package attribute for pre-uninstall scripts. If they're not run, that just leaves some debris after uninstalling (like symbolic link desktop icons). * Use the B_NOT_SUPPORTED error code when reading unknown package attributes. Don't treat it as an error if the package is a different minor version, just skip it. * Print unknown package attribute index numbers rather than stopping, since they may be from future package file formats and can be safely skipped otherwise. Mention the relevant enum so you can find it in the source code. It's a pity that the previous abstraction layer isn't present, since it tells us what data type the attribute is (string, number, etc), so we could have printed its value too. First step of two for enhancement #13427 See https://review.haiku-os.org/c/haiku/+/1504 to generate packages with a different minor version number (second step of the enhancement). Change-Id: I6db1897824a1713b3d5fab6fdfb990ee5923cd52 Reviewed-on: https://review.haiku-os.org/c/haiku/+/1714 Reviewed-by: waddlesplash --- src/bin/package/PackageInfoPrinter.h | 4 +++- src/kits/package/PackageInfoContentHandler.cpp | 2 +- src/kits/package/hpkg/ReaderImplBase.cpp | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bin/package/PackageInfoPrinter.h b/src/bin/package/PackageInfoPrinter.h index 7284312cb6..8357d90fd6 100644 --- a/src/bin/package/PackageInfoPrinter.h +++ b/src/bin/package/PackageInfoPrinter.h @@ -212,7 +212,9 @@ public: break; default: - return false; + printf("\tunknown or future attribute: " + "BPackageInfoAttributeID #%d\n", value.attributeID); + return true; } return true; diff --git a/src/kits/package/PackageInfoContentHandler.cpp b/src/kits/package/PackageInfoContentHandler.cpp index 0e4ad1d5d1..80c552d587 100644 --- a/src/kits/package/PackageInfoContentHandler.cpp +++ b/src/kits/package/PackageInfoContentHandler.cpp @@ -155,7 +155,7 @@ BPackageInfoContentHandler::HandlePackageAttribute( "Invalid package attribute section: unexpected package " "attribute id %d encountered\n", value.attributeID); } - return B_BAD_DATA; + return B_NOT_SUPPORTED; // Could be a future attribute we can skip. } return B_OK; diff --git a/src/kits/package/hpkg/ReaderImplBase.cpp b/src/kits/package/hpkg/ReaderImplBase.cpp index 612e132134..b0a647feb8 100644 --- a/src/kits/package/hpkg/ReaderImplBase.cpp +++ b/src/kits/package/hpkg/ReaderImplBase.cpp @@ -139,6 +139,8 @@ ReaderImplBase::PackageInfoAttributeHandlerBase::NotifyDone( { status_t error = context->packageContentHandler->HandlePackageAttribute( fPackageInfoValue); + if (context->ignoreUnknownAttributes && error == B_NOT_SUPPORTED) + error = B_OK; // Safe to skip a future/unknown attribute. fPackageInfoValue.Clear(); return error; } @@ -681,6 +683,8 @@ ReaderImplBase::PackageAttributeHandler::HandleAttribute( if (_handler == NULL) { status_t error = context->packageContentHandler ->HandlePackageAttribute(fPackageInfoValue); + if (context->ignoreUnknownAttributes && error == B_NOT_SUPPORTED) + error = B_OK; // Safe to skip a future/unknown attribute. fPackageInfoValue.Clear(); if (error != B_OK) return error;