BPackageInfo: Support reading both HPKG format versions
This commit is contained in:
@@ -167,12 +167,16 @@ private:
|
|||||||
friend class Parser;
|
friend class Parser;
|
||||||
struct StringBuilder;
|
struct StringBuilder;
|
||||||
struct FieldName;
|
struct FieldName;
|
||||||
|
struct PackageFileLocation;
|
||||||
|
|
||||||
typedef BObjectList<BPackageResolvable> ResolvableList;
|
typedef BObjectList<BPackageResolvable> ResolvableList;
|
||||||
typedef BObjectList<BPackageResolvableExpression>
|
typedef BObjectList<BPackageResolvableExpression>
|
||||||
ResolvableExpressionList;
|
ResolvableExpressionList;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
status_t _ReadFromPackageFile(
|
||||||
|
const PackageFileLocation& fileLocation);
|
||||||
|
|
||||||
static status_t _AddVersion(BMessage* archive,
|
static status_t _AddVersion(BMessage* archive,
|
||||||
const char* field,
|
const char* field,
|
||||||
const BPackageVersion& version);
|
const BPackageVersion& version);
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <package/hpkg/NoErrorOutput.h>
|
#include <package/hpkg/NoErrorOutput.h>
|
||||||
#include <package/hpkg/PackageReader.h>
|
#include <package/hpkg/PackageReader.h>
|
||||||
|
#include <package/hpkg/v1/PackageInfoContentHandler.h>
|
||||||
|
#include <package/hpkg/v1/PackageReader.h>
|
||||||
#include <package/PackageInfoContentHandler.h>
|
#include <package/PackageInfoContentHandler.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -1267,6 +1269,40 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - PackageFileLocation
|
||||||
|
|
||||||
|
|
||||||
|
struct BPackageInfo::PackageFileLocation {
|
||||||
|
PackageFileLocation(const char* path)
|
||||||
|
:
|
||||||
|
fPath(path),
|
||||||
|
fFD(-1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PackageFileLocation(int fd)
|
||||||
|
:
|
||||||
|
fPath(NULL),
|
||||||
|
fFD(fd)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* Path() const
|
||||||
|
{
|
||||||
|
return fPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FD() const
|
||||||
|
{
|
||||||
|
return fFD;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char* fPath;
|
||||||
|
int fFD;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - BPackageInfo
|
// #pragma mark - BPackageInfo
|
||||||
|
|
||||||
|
|
||||||
@@ -1409,28 +1445,14 @@ BPackageInfo::ReadFromConfigString(const BString& packageInfoString,
|
|||||||
status_t
|
status_t
|
||||||
BPackageInfo::ReadFromPackageFile(const char* path)
|
BPackageInfo::ReadFromPackageFile(const char* path)
|
||||||
{
|
{
|
||||||
BHPKG::BNoErrorOutput errorOutput;
|
return _ReadFromPackageFile(PackageFileLocation(path));
|
||||||
BHPKG::BPackageReader packageReader(&errorOutput);
|
|
||||||
status_t error = packageReader.Init(path);
|
|
||||||
if (error != B_OK)
|
|
||||||
return error;
|
|
||||||
|
|
||||||
BPackageInfoContentHandler handler(*this);
|
|
||||||
return packageReader.ParseContent(&handler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BPackageInfo::ReadFromPackageFile(int fd)
|
BPackageInfo::ReadFromPackageFile(int fd)
|
||||||
{
|
{
|
||||||
BHPKG::BNoErrorOutput errorOutput;
|
return _ReadFromPackageFile(PackageFileLocation(fd));
|
||||||
BHPKG::BPackageReader packageReader(&errorOutput);
|
|
||||||
status_t error = packageReader.Init(fd, false);
|
|
||||||
if (error != B_OK)
|
|
||||||
return error;
|
|
||||||
|
|
||||||
BPackageInfoContentHandler handler(*this);
|
|
||||||
return packageReader.ParseContent(&handler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1971,6 +1993,39 @@ BPackageInfo::ParseVersionString(const BString& string, bool revisionIsOptional,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BPackageInfo::_ReadFromPackageFile(const PackageFileLocation& fileLocation)
|
||||||
|
{
|
||||||
|
BHPKG::BNoErrorOutput errorOutput;
|
||||||
|
|
||||||
|
// try current package file format version
|
||||||
|
{
|
||||||
|
BHPKG::BPackageReader packageReader(&errorOutput);
|
||||||
|
status_t error = fileLocation.Path() != NULL
|
||||||
|
? packageReader.Init(fileLocation.Path())
|
||||||
|
: packageReader.Init(fileLocation.FD(), false);
|
||||||
|
if (error == B_OK) {
|
||||||
|
BPackageInfoContentHandler handler(*this);
|
||||||
|
return packageReader.ParseContent(&handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error != B_MISMATCHED_VALUES)
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// try package file format version 1
|
||||||
|
BHPKG::V1::BPackageReader packageReader(&errorOutput);
|
||||||
|
status_t error = fileLocation.Path() != NULL
|
||||||
|
? packageReader.Init(fileLocation.Path())
|
||||||
|
: packageReader.Init(fileLocation.FD(), false);
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
BHPKG::V1::BPackageInfoContentHandler handler(*this);
|
||||||
|
return packageReader.ParseContent(&handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*static*/ status_t
|
/*static*/ status_t
|
||||||
BPackageInfo::_AddVersion(BMessage* archive, const char* field,
|
BPackageInfo::_AddVersion(BMessage* archive, const char* field,
|
||||||
const BPackageVersion& version)
|
const BPackageVersion& version)
|
||||||
|
|||||||
Reference in New Issue
Block a user