pkgman: add support for [un]installing/updating in system

This commit is contained in:
Ingo Weinhold
2013-08-29 23:19:13 +02:00
parent c92aabd434
commit a54a50b48e
5 changed files with 83 additions and 45 deletions
+31 -26
View File
@@ -76,10 +76,14 @@ PackageManager::RemoteRepository::Config() const
// #pragma mark - InstalledRepository // #pragma mark - InstalledRepository
PackageManager::InstalledRepository::InstalledRepository() PackageManager::InstalledRepository::InstalledRepository(const char* name,
BPackageInstallationLocation location, int32 priority)
: :
BSolverRepository(), BSolverRepository(),
fDisabledPackages(10, true) fDisabledPackages(10, true),
fInitialName(name),
fLocation(location),
fInitialPriority(priority)
{ {
} }
@@ -115,9 +119,12 @@ PackageManager::PackageManager(BPackageInstallationLocation location,
: :
fLocation(location), fLocation(location),
fSolver(NULL), fSolver(NULL),
fSystemRepository(new (std::nothrow) InstalledRepository), fSystemRepository(new (std::nothrow) InstalledRepository("system",
fCommonRepository(new (std::nothrow) InstalledRepository), B_PACKAGE_INSTALLATION_LOCATION_SYSTEM, -1)),
fHomeRepository(new (std::nothrow) InstalledRepository), fCommonRepository(new (std::nothrow) InstalledRepository("common",
B_PACKAGE_INSTALLATION_LOCATION_COMMON, -2)),
fHomeRepository(new (std::nothrow) InstalledRepository("home",
B_PACKAGE_INSTALLATION_LOCATION_HOME, -3)),
fInstalledRepositories(10), fInstalledRepositories(10),
fOtherRepositories(10, true), fOtherRepositories(10, true),
fDecisionProvider(), fDecisionProvider(),
@@ -145,29 +152,13 @@ PackageManager::PackageManager(BPackageInstallationLocation location,
// one. Instead any requirement that is already installed in a more // one. Instead any requirement that is already installed in a more
// general installation location will turn up as to be installed as // general installation location will turn up as to be installed as
// well. But we can easily filter those out. // well. But we can easily filter those out.
RepositoryBuilder(*fSystemRepository, "system") _AddInstalledRepository(fSystemRepository);
.AddPackages(B_PACKAGE_INSTALLATION_LOCATION_SYSTEM, "system")
.AddToSolver(fSolver, false);
fSystemRepository->SetPriority(-1);
bool installInHome = location == B_PACKAGE_INSTALLATION_LOCATION_HOME; if (!fSystemRepository->IsInstalled()) {
RepositoryBuilder(*fCommonRepository, "common") _AddInstalledRepository(fCommonRepository);
.AddPackages(B_PACKAGE_INSTALLATION_LOCATION_COMMON, "common")
.AddToSolver(fSolver, !installInHome);
if (!fInstalledRepositories.AddItem(fSystemRepository) if (!fCommonRepository->IsInstalled())
|| !fInstalledRepositories.AddItem(fCommonRepository)) { _AddInstalledRepository(fHomeRepository);
DIE(B_NO_MEMORY, "failed to add installed repositories to list");
}
if (installInHome) {
fCommonRepository->SetPriority(-2);
RepositoryBuilder(*fHomeRepository, "home")
.AddPackages(B_PACKAGE_INSTALLATION_LOCATION_HOME, "home")
.AddToSolver(fSolver, true);
if (!fInstalledRepositories.AddItem(fHomeRepository))
DIE(B_NO_MEMORY, "failed to add home repository to list");
} }
} }
@@ -640,3 +631,17 @@ PackageManager::_FindBasePackage(const PackageList& packages,
return -1; return -1;
} }
void
PackageManager::_AddInstalledRepository(InstalledRepository* repository)
{
const char* name = repository->InitialName();
RepositoryBuilder(*repository, name)
.AddPackages(repository->Location(), name)
.AddToSolver(fSolver, repository->Location() == fLocation);
repository->SetPriority(repository->InitialPriority());
if (!fInstalledRepositories.AddItem(repository))
DIE(B_NO_MEMORY, "failed to add %s repository to list", name);
}
+16 -1
View File
@@ -80,6 +80,9 @@ private:
int32 _FindBasePackage(const PackageList& packages, int32 _FindBasePackage(const PackageList& packages,
const BPackageInfo& info) const; const BPackageInfo& info) const;
void _AddInstalledRepository(
InstalledRepository* repository);
private: private:
BPackageInstallationLocation fLocation; BPackageInstallationLocation fLocation;
BSolver* fSolver; BSolver* fSolver;
@@ -110,7 +113,16 @@ private:
struct PackageManager::InstalledRepository : public BSolverRepository { struct PackageManager::InstalledRepository : public BSolverRepository {
InstalledRepository(); InstalledRepository(const char* name,
BPackageInstallationLocation location,
int32 priority);
BPackageInstallationLocation Location() const
{ return fLocation; }
const char* InitialName() const
{ return fInitialName; }
int32 InitialPriority() const
{ return fInitialPriority; }
void DisablePackage(BSolverPackage* package); void DisablePackage(BSolverPackage* package);
@@ -119,6 +131,9 @@ private:
private: private:
PackageList fDisabledPackages; PackageList fDisabledPackages;
const char* fInitialName;
BPackageInstallationLocation fLocation;
int32 fInitialPriority;
}; };
+12 -6
View File
@@ -35,6 +35,9 @@ static const char* const kLongUsage =
" -H, --home\n" " -H, --home\n"
" Install the packages in the user's home directory. Default is to\n" " Install the packages in the user's home directory. Default is to\n"
" install in the common directory.\n" " install in the common directory.\n"
" -S, --system\n"
" Install the packages in the system directory. Default is to\n"
" install in the common directory.\n"
"\n"; "\n";
@@ -45,17 +48,19 @@ DEFINE_COMMAND(InstallCommand, "install", kShortUsage, kLongUsage,
int int
InstallCommand::Execute(int argc, const char* const* argv) InstallCommand::Execute(int argc, const char* const* argv)
{ {
bool installInHome = false; BPackageInstallationLocation location
= B_PACKAGE_INSTALLATION_LOCATION_COMMON;
while (true) { while (true) {
static struct option sLongOptions[] = { static struct option sLongOptions[] = {
{ "help", no_argument, 0, 'h' }, { "help", no_argument, 0, 'h' },
{ "home", no_argument, 0, 'H' }, { "home", no_argument, 0, 'H' },
{ "system", no_argument, 0, 'S' },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
opterr = 0; // don't print errors opterr = 0; // don't print errors
int c = getopt_long(argc, (char**)argv, "hH", sLongOptions, NULL); int c = getopt_long(argc, (char**)argv, "hHS", sLongOptions, NULL);
if (c == -1) if (c == -1)
break; break;
@@ -65,7 +70,11 @@ InstallCommand::Execute(int argc, const char* const* argv)
break; break;
case 'H': case 'H':
installInHome = true; location = B_PACKAGE_INSTALLATION_LOCATION_HOME;
break;
case 'S':
location = B_PACKAGE_INSTALLATION_LOCATION_SYSTEM;
break; break;
default: default:
@@ -82,9 +91,6 @@ InstallCommand::Execute(int argc, const char* const* argv)
const char* const* packages = argv + optind; const char* const* packages = argv + optind;
// perform the installation // perform the installation
BPackageInstallationLocation location = installInHome
? B_PACKAGE_INSTALLATION_LOCATION_HOME
: B_PACKAGE_INSTALLATION_LOCATION_COMMON;
PackageManager packageManager(location, PackageManager packageManager(location,
PackageManager::ADD_INSTALLED_REPOSITORIES PackageManager::ADD_INSTALLED_REPOSITORIES
| PackageManager::ADD_REMOTE_REPOSITORIES | PackageManager::ADD_REMOTE_REPOSITORIES
+12 -6
View File
@@ -35,6 +35,9 @@ static const char* const kLongUsage =
" -H, --home\n" " -H, --home\n"
" Uninstall the packages from the user's home directory. Default is to\n" " Uninstall the packages from the user's home directory. Default is to\n"
" uninstall from the common directory.\n" " uninstall from the common directory.\n"
" -S, --system\n"
" Uninstall the packages from the system directory. Default is to\n"
" uninstall from the common directory.\n"
"\n"; "\n";
@@ -45,17 +48,19 @@ DEFINE_COMMAND(UninstallCommand, "uninstall", kShortUsage, kLongUsage,
int int
UninstallCommand::Execute(int argc, const char* const* argv) UninstallCommand::Execute(int argc, const char* const* argv)
{ {
bool uninstallFromHome = false; BPackageInstallationLocation location
= B_PACKAGE_INSTALLATION_LOCATION_COMMON;
while (true) { while (true) {
static struct option sLongOptions[] = { static struct option sLongOptions[] = {
{ "help", no_argument, 0, 'h' }, { "help", no_argument, 0, 'h' },
{ "home", no_argument, 0, 'H' }, { "home", no_argument, 0, 'H' },
{ "system", no_argument, 0, 'S' },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
opterr = 0; // don't print errors opterr = 0; // don't print errors
int c = getopt_long(argc, (char**)argv, "hH", sLongOptions, NULL); int c = getopt_long(argc, (char**)argv, "hHS", sLongOptions, NULL);
if (c == -1) if (c == -1)
break; break;
@@ -65,7 +70,11 @@ UninstallCommand::Execute(int argc, const char* const* argv)
break; break;
case 'H': case 'H':
uninstallFromHome = true; location = B_PACKAGE_INSTALLATION_LOCATION_HOME;
break;
case 'S':
location = B_PACKAGE_INSTALLATION_LOCATION_SYSTEM;
break; break;
default: default:
@@ -82,9 +91,6 @@ UninstallCommand::Execute(int argc, const char* const* argv)
const char* const* packages = argv + optind; const char* const* packages = argv + optind;
// perform the installation // perform the installation
BPackageInstallationLocation location = uninstallFromHome
? B_PACKAGE_INSTALLATION_LOCATION_HOME
: B_PACKAGE_INSTALLATION_LOCATION_COMMON;
PackageManager packageManager(location, PackageManager packageManager(location,
PackageManager::ADD_INSTALLED_REPOSITORIES); PackageManager::ADD_INSTALLED_REPOSITORIES);
packageManager.Uninstall(packages, packageCount); packageManager.Uninstall(packages, packageCount);
+12 -6
View File
@@ -36,6 +36,9 @@ static const char* const kLongUsage =
" -H, --home\n" " -H, --home\n"
" Update the packages in the user's home directory. Default is to\n" " Update the packages in the user's home directory. Default is to\n"
" update in the common directory.\n" " update in the common directory.\n"
" -S, --system\n"
" Update the packages in the system directory. Default is to\n"
" update in the common directory.\n"
"\n"; "\n";
@@ -46,17 +49,19 @@ DEFINE_COMMAND(UpdateCommand, "update", kShortUsage, kLongUsage,
int int
UpdateCommand::Execute(int argc, const char* const* argv) UpdateCommand::Execute(int argc, const char* const* argv)
{ {
bool installInHome = false; BPackageInstallationLocation location
= B_PACKAGE_INSTALLATION_LOCATION_COMMON;
while (true) { while (true) {
static struct option sLongOptions[] = { static struct option sLongOptions[] = {
{ "help", no_argument, 0, 'h' }, { "help", no_argument, 0, 'h' },
{ "home", no_argument, 0, 'H' }, { "home", no_argument, 0, 'H' },
{ "system", no_argument, 0, 'S' },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
opterr = 0; // don't print errors opterr = 0; // don't print errors
int c = getopt_long(argc, (char**)argv, "hu", sLongOptions, NULL); int c = getopt_long(argc, (char**)argv, "hHS", sLongOptions, NULL);
if (c == -1) if (c == -1)
break; break;
@@ -66,7 +71,11 @@ UpdateCommand::Execute(int argc, const char* const* argv)
break; break;
case 'H': case 'H':
installInHome = true; location = B_PACKAGE_INSTALLATION_LOCATION_HOME;
break;
case 'S':
location = B_PACKAGE_INSTALLATION_LOCATION_SYSTEM;
break; break;
default: default:
@@ -80,9 +89,6 @@ UpdateCommand::Execute(int argc, const char* const* argv)
const char* const* packages = argv + optind; const char* const* packages = argv + optind;
// perform the update // perform the update
BPackageInstallationLocation location = installInHome
? B_PACKAGE_INSTALLATION_LOCATION_HOME
: B_PACKAGE_INSTALLATION_LOCATION_COMMON;
PackageManager packageManager(location, PackageManager packageManager(location,
PackageManager::ADD_INSTALLED_REPOSITORIES PackageManager::ADD_INSTALLED_REPOSITORIES
| PackageManager::ADD_REMOTE_REPOSITORIES | PackageManager::ADD_REMOTE_REPOSITORIES