diff --git a/headers/os/package/PackageInfo.h b/headers/os/package/PackageInfo.h index 9554a209f9..aad8b13ac8 100644 --- a/headers/os/package/PackageInfo.h +++ b/headers/os/package/PackageInfo.h @@ -28,9 +28,8 @@ namespace BPackageKit { /* * Keeps a list of package info elements (e.g. name, version, vendor, ...) which * will be converted to package attributes when creating a package. Usually, - * these elements have been parsed from a ".PackageInfo"-file. - * Alternatively, the package reader populates a BPackageInfo object by - * collecting package attributes from an existing package. + * these elements have been parsed from a ".PackageInfo" file. + * Alternatively, they can be read from an existing package file. */ class BPackageInfo { public: @@ -52,6 +51,8 @@ public: status_t ReadFromConfigString( const BString& packageInfoString, ParseErrorListener* listener = NULL); + status_t ReadFromPackageFile(const char* path); + status_t ReadFromPackageFile(int fd); status_t InitCheck() const; diff --git a/src/kits/package/PackageInfo.cpp b/src/kits/package/PackageInfo.cpp index f24bd9201f..42da18ec90 100644 --- a/src/kits/package/PackageInfo.cpp +++ b/src/kits/package/PackageInfo.cpp @@ -14,6 +14,9 @@ #include #include +#include +#include +#include namespace BPackageKit { @@ -903,6 +906,34 @@ BPackageInfo::ReadFromConfigString(const BString& packageInfoString, } +status_t +BPackageInfo::ReadFromPackageFile(const char* path) +{ + BHPKG::BNoErrorOutput errorOutput; + 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 +BPackageInfo::ReadFromPackageFile(int fd) +{ + BHPKG::BNoErrorOutput errorOutput; + BHPKG::BPackageReader packageReader(&errorOutput); + status_t error = packageReader.Init(fd, false); + if (error != B_OK) + return error; + + BPackageInfoContentHandler handler(*this); + return packageReader.ParseContent(&handler); +} + + status_t BPackageInfo::InitCheck() const {