pkgman install: Simplify transaction creation

This commit is contained in:
Ingo Weinhold
2013-04-21 10:36:19 +02:00
parent 2f028e9a2d
commit 7466fa2d49
+34 -44
View File
@@ -357,54 +357,44 @@ InstallCommand::Execute(int argc, const char* const* argv)
DIE(error, "failed to create transaction"); DIE(error, "failed to create transaction");
// download the new packages and prepare the transaction // download the new packages and prepare the transaction
for (int32 i = 0; const BSolverResultElement* element = result.ElementAt(i); for (int32 i = 0; BSolverPackage* package = packagesToActivate.ItemAt(i);
i++) { i++) {
BSolverPackage* package = element->Package(); // get package URL and target entry
Repository* repository
= static_cast<Repository*>(package->Repository());
BString url = repository->Config().BaseURL();
BString fileName(package->Info().CanonicalFileName());
if (fileName.IsEmpty())
DIE(B_NO_MEMORY, "failed to allocate file name");
url << '/' << fileName;
switch (element->Type()) { BEntry entry;
case BSolverResultElement::B_TYPE_INSTALL: error = entry.SetTo(&transactionDirectory, fileName);
{ if (error != B_OK)
if (installedRepositories.HasItem(package->Repository())) DIE(error, "failed to create package entry");
continue;
// get package URL and target entry // download the package
Repository* repository DownloadFileRequest downloadRequest(context, url, entry,
= static_cast<Repository*>(package->Repository()); package->Info().Checksum());
BString url = repository->Config().BaseURL(); error = downloadRequest.Process();
BString fileName(package->Info().CanonicalFileName()); if (error != B_OK)
if (fileName.IsEmpty()) DIE(error, "failed to download package");
DIE(B_NO_MEMORY, "failed to allocate file name");
url << '/' << fileName;
BEntry entry; // add package to transaction
error = entry.SetTo(&transactionDirectory, fileName); if (!transaction.AddPackageToActivate(
if (error != B_OK) package->Info().CanonicalFileName())) {
DIE(error, "failed to create package entry"); DIE(B_NO_MEMORY,
"failed to add package to activate to transaction");
}
}
// download the package for (int32 i = 0; BSolverPackage* package = packagesToDeactivate.ItemAt(i);
DownloadFileRequest downloadRequest(context, url, entry, i++) {
package->Info().Checksum()); // add package to transaction
error = downloadRequest.Process(); if (!transaction.AddPackageToDeactivate(
if (error != B_OK) package->Info().CanonicalFileName())) {
DIE(error, "failed to download package"); DIE(B_NO_MEMORY,
"failed to add package to deactivate to transaction");
// add package to transaction
if (!transaction.AddPackageToActivate(
package->Info().CanonicalFileName())) {
DIE(B_NO_MEMORY,
"failed to add package to activate to transaction");
}
break;
}
case BSolverResultElement::B_TYPE_UNINSTALL:
// add package to transaction
if (!transaction.AddPackageToDeactivate(
package->Info().CanonicalFileName())) {
DIE(B_NO_MEMORY,
"failed to add package to deactivate to transaction");
}
break;
} }
} }