From 6ae0ecd49a584abd81f3fa0fb0c0dd5b7a3ddb71 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 11 Jul 2011 14:00:55 +0200 Subject: [PATCH] Add a package info "install-path" attribute The attribute is intended for simplifying package building. The package's install path will be used for the package's .self package symlink, allowing installation to a temporary directory when building the package. --- headers/os/package/PackageInfo.h | 3 +++ headers/os/package/PackageInfoAttributes.h | 2 ++ headers/os/package/hpkg/HPKGDefs.h | 1 + headers/os/package/hpkg/PackageWriter.h | 1 + .../private/package/hpkg/PackageWriterImpl.h | 4 ++++ src/bin/package/command_list.cpp | 4 ++++ src/kits/package/PackageInfo.cpp | 18 +++++++++++++++++- .../package/hpkg/PackageContentHandler.cpp | 1 + src/kits/package/hpkg/PackageWriter.cpp | 10 ++++++++++ src/kits/package/hpkg/PackageWriterImpl.cpp | 12 ++++++++++++ src/kits/package/hpkg/ReaderImplBase.cpp | 4 ++++ src/kits/package/hpkg/WriterImplBase.cpp | 11 +++++++++++ 12 files changed, 70 insertions(+), 1 deletion(-) diff --git a/headers/os/package/PackageInfo.h b/headers/os/package/PackageInfo.h index 6109a2efa5..e62136dd9d 100644 --- a/headers/os/package/PackageInfo.h +++ b/headers/os/package/PackageInfo.h @@ -60,6 +60,7 @@ public: const BString& Vendor() const; const BString& Packager() const; const BString& Checksum() const; + const BString& InstallPath() const; uint32 Flags() const; @@ -89,6 +90,7 @@ public: void SetVendor(const BString& vendor); void SetPackager(const BString& packager); void SetChecksum(const BString& checksum); + void SetInstallPath(const BString& installPath); void SetFlags(uint32 flags); @@ -174,6 +176,7 @@ private: BObjectList fReplacesList; BString fChecksum; + BString fInstallPath; }; diff --git a/headers/os/package/PackageInfoAttributes.h b/headers/os/package/PackageInfoAttributes.h index d03a21695a..f1b86018ae 100644 --- a/headers/os/package/PackageInfoAttributes.h +++ b/headers/os/package/PackageInfoAttributes.h @@ -37,6 +37,8 @@ enum BPackageInfoAttributeID { B_PACKAGE_INFO_URLS, // list B_PACKAGE_INFO_SOURCE_URLS, // list B_PACKAGE_INFO_CHECKSUM, // sha256-checksum + B_PACKAGE_INFO_INSTALL_PATH, // package install path; only for package + // building // B_PACKAGE_INFO_ENUM_COUNT, }; diff --git a/headers/os/package/hpkg/HPKGDefs.h b/headers/os/package/hpkg/HPKGDefs.h index af83bf3cce..f4e812ef74 100644 --- a/headers/os/package/hpkg/HPKGDefs.h +++ b/headers/os/package/hpkg/HPKGDefs.h @@ -126,6 +126,7 @@ enum BHPKGAttributeID { B_HPKG_ATTRIBUTE_ID_PACKAGE_PROVIDES_COMPATIBLE = 41, B_HPKG_ATTRIBUTE_ID_PACKAGE_URL = 42, B_HPKG_ATTRIBUTE_ID_PACKAGE_SOURCE_URL = 43, + B_HPKG_ATTRIBUTE_ID_PACKAGE_INSTALL_PATH = 44, // B_HPKG_ATTRIBUTE_ID_ENUM_COUNT, }; diff --git a/headers/os/package/hpkg/PackageWriter.h b/headers/os/package/hpkg/PackageWriter.h index 6b3a9be5fc..e3eb30d59b 100644 --- a/headers/os/package/hpkg/PackageWriter.h +++ b/headers/os/package/hpkg/PackageWriter.h @@ -48,6 +48,7 @@ public: ~BPackageWriter(); status_t Init(const char* fileName, uint32 flags = 0); + status_t SetInstallPath(const char* installPath); void SetCheckLicenses(bool checkLicenses); status_t AddEntry(const char* fileName, int fd = -1); status_t Finish(); diff --git a/headers/private/package/hpkg/PackageWriterImpl.h b/headers/private/package/hpkg/PackageWriterImpl.h index 2a24b6638c..88febb119b 100644 --- a/headers/private/package/hpkg/PackageWriterImpl.h +++ b/headers/private/package/hpkg/PackageWriterImpl.h @@ -10,6 +10,8 @@ #include #include +#include + #include #include #include @@ -43,6 +45,7 @@ public: ~PackageWriterImpl(); status_t Init(const char* fileName, uint32 flags); + status_t SetInstallPath(const char* installPath); void SetCheckLicenses(bool checkLicenses); status_t AddEntry(const char* fileName, int fd = -1); status_t Finish(); @@ -148,6 +151,7 @@ private: StringCache fStringCache; BPackageInfo fPackageInfo; + BString fInstallPath; bool fCheckLicenses; }; diff --git a/src/bin/package/command_list.cpp b/src/bin/package/command_list.cpp index efcf33685e..317cec68fd 100644 --- a/src/bin/package/command_list.cpp +++ b/src/bin/package/command_list.cpp @@ -230,6 +230,10 @@ struct PackageContentListHandler : BPackageContentHandler { printf("\treplaces: %s\n", value.string); break; + case B_PACKAGE_INFO_INSTALL_PATH: + printf("\tinstall path: %s\n", value.string); + break; + default: printf( "*** Invalid package attribute section: unexpected " diff --git a/src/kits/package/PackageInfo.cpp b/src/kits/package/PackageInfo.cpp index ee3376e7b8..0f3e3b22f6 100644 --- a/src/kits/package/PackageInfo.cpp +++ b/src/kits/package/PackageInfo.cpp @@ -670,7 +670,7 @@ BPackageInfo::Parser::_Parse(BPackageInfo* packageInfo) BPackageInfoAttributeID attribute = B_PACKAGE_INFO_ENUM_COUNT; for (int i = 0; i < B_PACKAGE_INFO_ENUM_COUNT; i++) { - if (t.text.ICompare(names[i]) == 0) { + if (names[i] != NULL && t.text.ICompare(names[i]) == 0) { attribute = (BPackageInfoAttributeID)i; break; } @@ -803,6 +803,7 @@ const char* BPackageInfo::kElementNames[B_PACKAGE_INFO_ENUM_COUNT] = { "urls", "source-urls", "checksum", // not being parsed, computed externally + NULL, // install-path -- not settable via .PackageInfo }; @@ -948,6 +949,13 @@ BPackageInfo::Checksum() const } +const BString& +BPackageInfo::InstallPath() const +{ + return fInstallPath; +} + + uint32 BPackageInfo::Flags() const { @@ -1081,6 +1089,13 @@ BPackageInfo::SetChecksum(const BString& checksum) } +void +BPackageInfo::SetInstallPath(const BString& installPath) +{ + fInstallPath = installPath; +} + + void BPackageInfo::SetVersion(const BPackageVersion& version) { @@ -1296,6 +1311,7 @@ BPackageInfo::Clear() fVendor.Truncate(0); fPackager.Truncate(0); fChecksum.Truncate(0); + fInstallPath.Truncate(0); fFlags = 0; fArchitecture = B_PACKAGE_ARCHITECTURE_ENUM_COUNT; fVersion.Clear(); diff --git a/src/kits/package/hpkg/PackageContentHandler.cpp b/src/kits/package/hpkg/PackageContentHandler.cpp index 9d344e715c..418e84bf5d 100644 --- a/src/kits/package/hpkg/PackageContentHandler.cpp +++ b/src/kits/package/hpkg/PackageContentHandler.cpp @@ -60,6 +60,7 @@ static const char* kAttributeNames[B_HPKG_ATTRIBUTE_ID_ENUM_COUNT + 1] = { "package:provides.compatible", "package:url", "package:source-url", + "package:install-path", NULL }; diff --git a/src/kits/package/hpkg/PackageWriter.cpp b/src/kits/package/hpkg/PackageWriter.cpp index dd548087ac..3fcbec8e42 100644 --- a/src/kits/package/hpkg/PackageWriter.cpp +++ b/src/kits/package/hpkg/PackageWriter.cpp @@ -39,6 +39,16 @@ BPackageWriter::Init(const char* fileName, uint32 flags) } +status_t +BPackageWriter::SetInstallPath(const char* installPath) +{ + if (fImpl == NULL) + return B_NO_INIT; + + return fImpl->SetInstallPath(installPath); +} + + void BPackageWriter::SetCheckLicenses(bool checkLicenses) { diff --git a/src/kits/package/hpkg/PackageWriterImpl.cpp b/src/kits/package/hpkg/PackageWriterImpl.cpp index db8a9b7ce8..06710867a3 100644 --- a/src/kits/package/hpkg/PackageWriterImpl.cpp +++ b/src/kits/package/hpkg/PackageWriterImpl.cpp @@ -485,6 +485,16 @@ PackageWriterImpl::Init(const char* fileName, uint32 flags) } +status_t +PackageWriterImpl::SetInstallPath(const char* installPath) +{ + fInstallPath = installPath; + return installPath == NULL + || (size_t)fInstallPath.Length() == strlen(installPath) + ? B_OK : B_NO_MEMORY; +} + + void PackageWriterImpl::SetCheckLicenses(bool checkLicenses) { @@ -575,6 +585,8 @@ PackageWriterImpl::Finish() return B_BAD_DATA; } + fPackageInfo.SetInstallPath(fInstallPath); + RegisterPackageInfo(PackageAttributes(), fPackageInfo); if (fCheckLicenses) { diff --git a/src/kits/package/hpkg/ReaderImplBase.cpp b/src/kits/package/hpkg/ReaderImplBase.cpp index 727991d764..7f2c3fd94d 100644 --- a/src/kits/package/hpkg/ReaderImplBase.cpp +++ b/src/kits/package/hpkg/ReaderImplBase.cpp @@ -441,6 +441,10 @@ ReaderImplBase::PackageAttributeHandler::HandleAttribute( fPackageInfoValue.SetTo(B_PACKAGE_INFO_CHECKSUM, value.string); break; + case B_HPKG_ATTRIBUTE_ID_PACKAGE_INSTALL_PATH: + fPackageInfoValue.SetTo(B_PACKAGE_INFO_INSTALL_PATH, value.string); + break; + default: context->errorOutput->PrintError( "Error: Invalid package attribute section: unexpected " diff --git a/src/kits/package/hpkg/WriterImplBase.cpp b/src/kits/package/hpkg/WriterImplBase.cpp index 74224ff23a..e308190f8c 100644 --- a/src/kits/package/hpkg/WriterImplBase.cpp +++ b/src/kits/package/hpkg/WriterImplBase.cpp @@ -527,6 +527,17 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList, = fPackageStringCache.Get(packageInfo.Checksum().String()); attributeList.Add(checksum); } + + // install path (optional) + if (!packageInfo.InstallPath().IsEmpty()) { + PackageAttribute* installPath = new PackageAttribute( + B_HPKG_ATTRIBUTE_ID_PACKAGE_INSTALL_PATH, + B_HPKG_ATTRIBUTE_TYPE_STRING, + B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE); + installPath->string = fPackageStringCache.Get( + packageInfo.InstallPath().String()); + attributeList.Add(installPath); + } }