From 6dc1f7eb1ecc2cf77673cee673c25dd207a12cba Mon Sep 17 00:00:00 2001 From: Hrishi Hiraskar Date: Thu, 15 Feb 2018 17:47:56 +0530 Subject: [PATCH] [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 --- src/bin/pkgman/command_install.cpp | 36 +++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) 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 +#include +#include +#include +#include +#include #include #include @@ -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 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( + 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; }