From f1e5a6c914a9341f2b874f43b8f945db7c895d4c Mon Sep 17 00:00:00 2001 From: Leorize Date: Sun, 22 Mar 2020 12:28:48 -0500 Subject: [PATCH] Installer: supports installing .hpkg-based optional packages Most of Installer was designed for old-style optional packages (files in a folder that's copied to the target volume). This commit modifies Installer so that it can process and install .hpkg packages. Change-Id: Ib7d69a04ccb7879b956b5c3f0df1241c56e4987d Reviewed-on: https://review.haiku-os.org/c/haiku/+/2400 Reviewed-by: waddlesplash --- src/apps/installer/PackageViews.cpp | 6 +++--- src/apps/installer/PackageViews.h | 13 +++++++------ src/apps/installer/WorkerThread.cpp | 26 ++++++++++++++++++++------ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/apps/installer/PackageViews.cpp b/src/apps/installer/PackageViews.cpp index af39586ed0..25c2b827b6 100644 --- a/src/apps/installer/PackageViews.cpp +++ b/src/apps/installer/PackageViews.cpp @@ -34,13 +34,13 @@ #define ICON_ATTRIBUTE "INSTALLER PACKAGE: ICON" -Package::Package(const char *folder) +Package::Package(const BPath &path) : Group(), fSize(0), fIcon(NULL) { - SetFolder(folder); + SetPath(path); } @@ -62,7 +62,7 @@ Package::PackageFromEntry(BEntry &entry) if (info.InitCheck() != B_OK) return NULL; - Package *package = new Package(path.Path()); + Package *package = new Package(path); package->fName = info.Name(); package->fDescription = info.Summary(); diff --git a/src/apps/installer/PackageViews.h b/src/apps/installer/PackageViews.h index 26c3f22736..6709b87b52 100644 --- a/src/apps/installer/PackageViews.h +++ b/src/apps/installer/PackageViews.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -31,11 +32,11 @@ private: class Package : public Group { public: - Package(const char* folder); + Package(const BPath &path); virtual ~Package(); - void SetFolder(BString folder) - { fFolder = folder; } + void SetPath(const BPath &path) + { fPath = path; } void SetName(const BString name) { fName = name; } void SetDescription(const BString description) @@ -48,8 +49,8 @@ public: { fOnByDefault = onByDefault; } void SetAlwaysOn(bool alwaysOn) { fAlwaysOn = alwaysOn; } - BString Folder() const - { return fFolder; } + BPath Path() const + { return fPath; } BString Name() const { return fName; } BString Description() const @@ -68,7 +69,7 @@ public: static Package* PackageFromEntry(BEntry &dir); private: - BString fFolder; + BPath fPath; BString fName; BString fDescription; int32 fSize; diff --git a/src/apps/installer/WorkerThread.cpp b/src/apps/installer/WorkerThread.cpp index 9cb87e0010..07d92d9c22 100644 --- a/src/apps/installer/WorkerThread.cpp +++ b/src/apps/installer/WorkerThread.cpp @@ -514,12 +514,14 @@ WorkerThread::_PerformInstall(partition_id sourcePartitionID, // Collect selected packages also if (fPackages) { - BPath pkgRootDir(srcDirectory.Path(), kPackagesDirectoryPath); int32 count = fPackages->CountItems(); for (int32 i = 0; i < count; i++) { Package *p = static_cast(fPackages->ItemAt(i)); - BPath packageDir(pkgRootDir.Path(), p->Folder()); - err = engine.CollectTargets(packageDir.Path(), fCancelSemaphore); + const BPath& pkgPath = p->Path(); + err = pkgPath.InitCheck(); + if (err != B_OK) + return _InstallationError(err); + err = engine.CollectTargets(pkgPath.Path(), fCancelSemaphore); if (err != B_OK) return _InstallationError(err); } @@ -541,12 +543,24 @@ WorkerThread::_PerformInstall(partition_id sourcePartitionID, // copy selected packages if (fPackages) { - BPath pkgRootDir(srcDirectory.Path(), kPackagesDirectoryPath); int32 count = fPackages->CountItems(); + // FIXME: find_directory doesn't return the folder in the target volume, + // so we are hard coding this for now. + BPath targetPkgDir(targetDirectory.Path(), "system/packages"); + err = targetPkgDir.InitCheck(); + if (err != B_OK) + return _InstallationError(err); for (int32 i = 0; i < count; i++) { Package *p = static_cast(fPackages->ItemAt(i)); - BPath packageDir(pkgRootDir.Path(), p->Folder()); - err = engine.Copy(packageDir.Path(), targetDirectory.Path(), + const BPath& pkgPath = p->Path(); + err = pkgPath.InitCheck(); + if (err != B_OK) + return _InstallationError(err); + BPath targetPath(targetPkgDir.Path(), pkgPath.Leaf()); + err = targetPath.InitCheck(); + if (err != B_OK) + return _InstallationError(err); + err = engine.Copy(pkgPath.Path(), targetPath.Path(), fCancelSemaphore); if (err != B_OK) return _InstallationError(err);