From 7466fa2d4901461dea3fc89a9229e0e04707124a Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 21 Apr 2013 10:36:19 +0200 Subject: [PATCH] pkgman install: Simplify transaction creation --- src/bin/pkgman/command_install.cpp | 78 +++++++++++++----------------- 1 file changed, 34 insertions(+), 44 deletions(-) diff --git a/src/bin/pkgman/command_install.cpp b/src/bin/pkgman/command_install.cpp index 0554cea1b8..1bcbeff777 100644 --- a/src/bin/pkgman/command_install.cpp +++ b/src/bin/pkgman/command_install.cpp @@ -357,54 +357,44 @@ InstallCommand::Execute(int argc, const char* const* argv) DIE(error, "failed to create transaction"); // download the new packages and prepare the transaction - for (int32 i = 0; const BSolverResultElement* element = result.ElementAt(i); - i++) { - BSolverPackage* package = element->Package(); + for (int32 i = 0; BSolverPackage* package = packagesToActivate.ItemAt(i); + i++) { + // get package URL and target entry + Repository* repository + = static_cast(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()) { - case BSolverResultElement::B_TYPE_INSTALL: - { - if (installedRepositories.HasItem(package->Repository())) - continue; + BEntry entry; + error = entry.SetTo(&transactionDirectory, fileName); + if (error != B_OK) + DIE(error, "failed to create package entry"); - // get package URL and target entry - Repository* repository - = static_cast(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; + // download the package + DownloadFileRequest downloadRequest(context, url, entry, + package->Info().Checksum()); + error = downloadRequest.Process(); + if (error != B_OK) + DIE(error, "failed to download package"); - BEntry entry; - error = entry.SetTo(&transactionDirectory, fileName); - if (error != B_OK) - DIE(error, "failed to create package entry"); + // add package to transaction + if (!transaction.AddPackageToActivate( + package->Info().CanonicalFileName())) { + DIE(B_NO_MEMORY, + "failed to add package to activate to transaction"); + } + } - // download the package - DownloadFileRequest downloadRequest(context, url, entry, - package->Info().Checksum()); - error = downloadRequest.Process(); - if (error != B_OK) - DIE(error, "failed to download package"); - - // 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; + for (int32 i = 0; BSolverPackage* package = packagesToDeactivate.ItemAt(i); + i++) { + // add package to transaction + if (!transaction.AddPackageToDeactivate( + package->Info().CanonicalFileName())) { + DIE(B_NO_MEMORY, + "failed to add package to deactivate to transaction"); } }