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 <waddlesplash@gmail.com>
This commit is contained in:
Alexander G. M. Smith 2019-08-13 19:17:18 -04:00 committed by waddlesplash
parent 7893e1249e
commit 31d70c106b
3 changed files with 8 additions and 2 deletions

View File

@ -212,7 +212,9 @@ public:
break;
default:
return false;
printf("\tunknown or future attribute: "
"BPackageInfoAttributeID #%d\n", value.attributeID);
return true;
}
return true;

View File

@ -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;

View File

@ -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;