pkgman: Add full-sync command
* BSolver/LibsolvSolver: Add FullSync() method. It uses libsolv's SOLVER_DISTUPGRADE mode. * BPackageManager: Add FullSync() using the new solver mode. * pkgman: Add full-sync command. The new command is similar to the update command without arguments, just more aggressive, allowing downgrading or even removal of packages, to match the state of the repositories. Just like "update" it doesn't work properly yet.
This commit is contained in:
parent
e08720f8f2
commit
6ef57ae2a9
@ -72,6 +72,7 @@ public:
|
||||
bool installNotYetInstalled,
|
||||
const BSolverPackageSpecifier** _unmatched
|
||||
= NULL) = 0;
|
||||
virtual status_t FullSync() = 0;
|
||||
virtual status_t VerifyInstallation(uint32 flags = 0) = 0;
|
||||
|
||||
bool HasProblems() const
|
||||
|
@ -90,6 +90,7 @@ public:
|
||||
int packageCount);
|
||||
void Update(const BSolverPackageSpecifierList&
|
||||
packages);
|
||||
void FullSync();
|
||||
|
||||
void VerifyInstallation();
|
||||
|
||||
|
@ -6,6 +6,7 @@ BinCommand pkgman :
|
||||
Command.cpp
|
||||
command_add_repo.cpp
|
||||
command_drop_repo.cpp
|
||||
command_full_sync.cpp
|
||||
command_install.cpp
|
||||
command_list_repos.cpp
|
||||
command_update.cpp
|
||||
|
97
src/bin/pkgman/command_full_sync.cpp
Normal file
97
src/bin/pkgman/command_full_sync.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2013-2014, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Ingo Weinhold <ingo_weinhold@gmx.de>
|
||||
*/
|
||||
|
||||
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Command.h"
|
||||
#include "pkgman.h"
|
||||
#include "PackageManager.h"
|
||||
|
||||
|
||||
// TODO: internationalization!
|
||||
|
||||
|
||||
using namespace BPackageKit;
|
||||
using namespace BPackageKit::BPrivate;
|
||||
|
||||
|
||||
static const char* const kShortUsage =
|
||||
" %command%\n"
|
||||
" Synchronizes the installed packages with the repositories.\n";
|
||||
|
||||
static const char* const kLongUsage =
|
||||
"Usage: %program% %command%\n"
|
||||
"Synchronizes the installed packages with the repositories. The command\n"
|
||||
"is similar to the \"update\" command, but more aggressive. It also\n"
|
||||
"downgrades or removes packages, if necessary.\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" -H, --home\n"
|
||||
" Synchronizes the packages in the user's home directory. Default is\n"
|
||||
" to synchronize the packages in the system directory.\n"
|
||||
" -y\n"
|
||||
" Non-interactive mode. Automatically confirm changes, but fail when\n"
|
||||
" encountering problems.\n"
|
||||
"\n";
|
||||
|
||||
|
||||
DEFINE_COMMAND(FullSyncCommand, "full-sync", kShortUsage, kLongUsage,
|
||||
kCommandCategoryPackages)
|
||||
|
||||
|
||||
int
|
||||
FullSyncCommand::Execute(int argc, const char* const* argv)
|
||||
{
|
||||
BPackageInstallationLocation location
|
||||
= B_PACKAGE_INSTALLATION_LOCATION_SYSTEM;
|
||||
bool interactive = true;
|
||||
|
||||
while (true) {
|
||||
static struct option sLongOptions[] = {
|
||||
{ "help", no_argument, 0, 'h' },
|
||||
{ "home", no_argument, 0, 'H' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
opterr = 0; // don't print errors
|
||||
int c = getopt_long(argc, (char**)argv, "hHy", sLongOptions, NULL);
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
PrintUsageAndExit(false);
|
||||
break;
|
||||
|
||||
case 'H':
|
||||
location = B_PACKAGE_INSTALLATION_LOCATION_HOME;
|
||||
break;
|
||||
|
||||
case 'y':
|
||||
interactive = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
PrintUsageAndExit(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// no remaining arguments
|
||||
if (optind < argc)
|
||||
PrintUsageAndExit(true);
|
||||
|
||||
// perform the sync
|
||||
PackageManager packageManager(location, interactive);
|
||||
packageManager.FullSync();
|
||||
|
||||
return 0;
|
||||
}
|
@ -288,6 +288,26 @@ BPackageManager::Update(const BSolverPackageSpecifierList& packages)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageManager::FullSync()
|
||||
{
|
||||
Init(B_ADD_INSTALLED_REPOSITORIES | B_ADD_REMOTE_REPOSITORIES
|
||||
| B_REFRESH_REPOSITORIES);
|
||||
|
||||
// solve
|
||||
status_t error = fSolver->FullSync();
|
||||
if (error != B_OK)
|
||||
DIE(error, "failed to compute packages to synchronize");
|
||||
|
||||
_HandleProblems();
|
||||
|
||||
// install/uninstall packages
|
||||
_AnalyzeResult();
|
||||
_ConfirmChanges();
|
||||
_ApplyPackageChanges();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageManager::VerifyInstallation()
|
||||
{
|
||||
|
@ -426,6 +426,29 @@ LibsolvSolver::Update(const BSolverPackageSpecifierList& packages,
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
LibsolvSolver::FullSync()
|
||||
{
|
||||
// add repositories to pool
|
||||
status_t error = _AddRepositories();
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
// Init the job queue and specify that all packages shall be updated.
|
||||
error = _InitJobQueue();
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
queue_push2(fJobs, SOLVER_SOLVABLE_ALL, 0);
|
||||
|
||||
// set jobs' solver mode and solve
|
||||
_SetJobsSolverMode(SOLVER_DISTUPGRADE);
|
||||
|
||||
_InitSolver();
|
||||
return _Solve();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
LibsolvSolver::VerifyInstallation(uint32 flags)
|
||||
{
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
bool installNotYetInstalled,
|
||||
const BSolverPackageSpecifier** _unmatched
|
||||
= NULL);
|
||||
virtual status_t FullSync();
|
||||
virtual status_t VerifyInstallation(uint32 flags = 0);
|
||||
|
||||
virtual int32 CountProblems() const;
|
||||
|
Loading…
Reference in New Issue
Block a user