[haiku-commits] haiku: hrev51813 - src/bin/pkgman

  • From: jerome.duval@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 26 Feb 2018 13:34:07 -0500 (EST)

hrev51813 adds 1 changeset to branch 'master'
old head: 0bb9fd3868a01d4da9ac0fb1250d883e6873b70f
new head: 6dc1f7eb1ecc2cf77673cee673c25dd207a12cba
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=6dc1f7eb1ecc+%5E0bb9fd3868a0

----------------------------------------------------------------------------

6dc1f7eb1ecc: [pkgman] pkgman informs if package is already installed.
  
  While installing packages through pkgman, it will inform if specific
  package is already installed. Fixes #12447 : [pkgman] inform if a
  package is already installed.
  Change-Id: I194bc849c42ba52a696a6cb52d87aebaff530f35

                              [ Hrishi Hiraskar <hrishihiraskar@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev51813
Commit:      6dc1f7eb1ecc2cf77673cee673c25dd207a12cba
URL:         http://cgit.haiku-os.org/haiku/commit/?id=6dc1f7eb1ecc
Author:      Hrishi Hiraskar <hrishihiraskar@xxxxxxxxx>
Date:        Thu Feb 15 12:17:56 2018 UTC
Committer:   Jérôme Duval <jerome.duval@xxxxxxxxx>
Commit-Date: Mon Feb 26 18:33:58 2018 UTC

Ticket:      https://dev.haiku-os.org/ticket/12447

----------------------------------------------------------------------------

1 file changed, 35 insertions(+), 1 deletion(-)
src/bin/pkgman/command_install.cpp | 36 +++++++++++++++++++++++++++++++++-

----------------------------------------------------------------------------

diff --git a/src/bin/pkgman/command_install.cpp 
b/src/bin/pkgman/command_install.cpp
index e26207bb3e..8a49fada12 100644
--- a/src/bin/pkgman/command_install.cpp
+++ b/src/bin/pkgman/command_install.cpp
@@ -8,6 +8,11 @@
 
 
 #include <getopt.h>
+#include <package/manager/Exceptions.h>
+#include <ObjectList.h>
+#include <package/solver/SolverPackage.h>
+#include <package/solver/SolverPackageSpecifier.h>
+#include <package/solver/SolverPackageSpecifierList.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -21,6 +26,7 @@
 
 using namespace BPackageKit;
 using namespace BPackageKit::BPrivate;
+using namespace BPackageKit::BManager::BPrivate;
 
 
 static const char* const kShortUsage =
@@ -102,7 +108,35 @@ InstallCommand::Execute(int argc, const char* const* argv)
        // perform the installation
        PackageManager packageManager(location, interactive);
        packageManager.SetDebugLevel(fCommonOptions.DebugLevel());
-       packageManager.Install(packages, packageCount);
+       try {
+               packageManager.Install(packages, packageCount);
+       } catch (BNothingToDoException&) {
+               // Output already installed packages
+               BSolverPackageSpecifierList packagesToInstall;
+               if (!packagesToInstall.AppendSpecifiers(packages, packageCount))
+                       throw std::bad_alloc();
+               // Find the installed packages that match the specification
+               const BSolverPackageSpecifier* unmatchedSpecifier;
+               BObjectList<BSolverPackage> installedPackages;
+               packageManager.Solver()->FindPackages(packagesToInstall,
+                       BSolver::B_FIND_INSTALLED_ONLY,
+                       installedPackages, &unmatchedSpecifier);
+
+               for (int32 i = 0; BSolverPackage* package = 
installedPackages.ItemAt(i);
+                       i++) {
+                       BString repository;
+                       if (dynamic_cast<PackageManager::MiscLocalRepository*>(
+                                       package->Repository()) != NULL)
+                               repository = "local file";
+                       else
+                               repository.SetToFormat(
+                                       "repository %s", 
package->Repository()->Name().String());
+                       fprintf(stderr, "%s from %s is already installed.\n",
+                               package->VersionedName().String(),
+                               repository.String());
+               }
+               throw;
+       }
 
        return 0;
 }


Other related posts:

  • » [haiku-commits] haiku: hrev51813 - src/bin/pkgman - jerome . duval