[haiku-commits] BRANCH HaikuPM-github.package-management - in src: bin/pkgman kits/package

  • From: HaikuPM-github.package-management <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 20 Apr 2013 13:30:38 +0200 (CEST)

added 2 changesets to branch 'refs/remotes/HaikuPM-github/package-management'
old head: 85d2badf007cb152215485db7916578ed6700504
new head: e0d4161d42a235f3e365787ee0470fc61c8e668d
overview: https://github.com/haiku/HaikuPM/compare/85d2bad...e0d4161

----------------------------------------------------------------------------

f71be99: BRequest: Add Process()
  
  The method creates the initial jobs for the request and processes the
  jobs from the job queue until empty or an error occurs.

e0d4161: pkgman: Make use of BRequest::Process()

                                    [ Ingo Weinhold <ingo_weinhold@xxxxxx> ]

----------------------------------------------------------------------------

5 files changed, 55 insertions(+), 53 deletions(-)
headers/os/package/Request.h         |  2 ++
src/bin/pkgman/command_add_repo.cpp  | 39 ++++++++++++--------------------
src/bin/pkgman/command_drop_repo.cpp | 19 ++++++----------
src/bin/pkgman/command_refresh.cpp   | 24 ++++++--------------
src/kits/package/Request.cpp         | 24 ++++++++++++++++++++

############################################################################

Commit:      f71be99bd913f8cc8aab59b97f656dec32f06837
Author:      Ingo Weinhold <ingo_weinhold@xxxxxx>
Date:        Sat Apr 20 11:26:34 2013 UTC

BRequest: Add Process()

The method creates the initial jobs for the request and processes the
jobs from the job queue until empty or an error occurs.

----------------------------------------------------------------------------

diff --git a/headers/os/package/Request.h b/headers/os/package/Request.h
index 57ae1af..5414201 100644
--- a/headers/os/package/Request.h
+++ b/headers/os/package/Request.h
@@ -32,6 +32,8 @@ public:
 
                        BJob*                           PopRunnableJob();
 
+                       status_t                        Process(bool 
failIfCanceledOnly = false);
+
 protected:
                        status_t                        QueueJob(BJob* job);
 
diff --git a/src/kits/package/Request.cpp b/src/kits/package/Request.cpp
index 7005c5e..35c4058 100644
--- a/src/kits/package/Request.cpp
+++ b/src/kits/package/Request.cpp
@@ -50,6 +50,30 @@ BRequest::PopRunnableJob()
 
 
 status_t
+BRequest::Process(bool failIfCanceledOnly)
+{
+       status_t error = InitCheck();
+       if (error != B_OK)
+               return error;
+
+       error = CreateInitialJobs();
+       if (error != B_OK)
+               return error;
+
+       while (BJob* job = PopRunnableJob()) {
+               error = job->Run();
+               delete job;
+               if (error != B_OK) {
+                       if (!failIfCanceledOnly || error == B_CANCELED)
+                               return error;
+               }
+       }
+
+       return B_OK;
+}
+
+
+status_t
 BRequest::QueueJob(BJob* job)
 {
        if (fJobQueue == NULL)

############################################################################

Commit:      e0d4161d42a235f3e365787ee0470fc61c8e668d
Author:      Ingo Weinhold <ingo_weinhold@xxxxxx>
Date:        Sat Apr 20 11:28:36 2013 UTC

pkgman: Make use of BRequest::Process()

----------------------------------------------------------------------------

diff --git a/src/bin/pkgman/command_add_repo.cpp 
b/src/bin/pkgman/command_add_repo.cpp
index b63583b..798ae6a 100644
--- a/src/bin/pkgman/command_add_repo.cpp
+++ b/src/bin/pkgman/command_add_repo.cpp
@@ -87,18 +87,13 @@ AddRepoCommand::Execute(int argc, const char* const* argv)
        status_t result;
        for (int i = 0; i < urlCount; ++i) {
                AddRepositoryRequest addRequest(context, repoURLs[i], 
asUserRepository);
-               result = addRequest.InitCheck();
-               if (result != B_OK)
-                       DIE(result, "unable to create request for adding 
repository");
-               result = addRequest.CreateInitialJobs();
-               if (result != B_OK)
-                       DIE(result, "unable to create necessary jobs");
-
-               while (BJob* job = addRequest.PopRunnableJob()) {
-                       result = job->Run();
-                       delete job;
-                       if (result == B_CANCELED)
-                               return 1;
+               result = addRequest.Process(true);
+               if (result != B_OK) {
+                       if (result != B_CANCELED) {
+                               DIE(result, "request for adding repository 
\"%s\" failed",
+                                       repoURLs[i]);
+                       }
+                       return 1;
                }
 
                // now refresh the repo-cache of the new repository
@@ -106,19 +101,15 @@ AddRepoCommand::Execute(int argc, const char* const* argv)
                BPackageRoster roster;
                BRepositoryConfig repoConfig;
                roster.GetRepositoryConfig(repoName, &repoConfig);
+               
                BRefreshRepositoryRequest refreshRequest(context, repoConfig);
-               result = refreshRequest.InitCheck();
-               if (result != B_OK)
-                       DIE(result, "unable to create request for refreshing 
repository");
-               result = refreshRequest.CreateInitialJobs();
-               if (result != B_OK)
-                       DIE(result, "unable to create necessary jobs");
-
-               while (BJob* job = refreshRequest.PopRunnableJob()) {
-                       result = job->Run();
-                       delete job;
-                       if (result == B_CANCELED)
-                               return 1;
+               result = refreshRequest.Process(true);
+               if (result != B_OK) {
+                       if (result != B_CANCELED) {
+                               DIE(result, "request for refreshing repository 
\"%s\" failed",
+                                       repoName.String());
+                       }
+                       return 1;
                }
        }
 
diff --git a/src/bin/pkgman/command_drop_repo.cpp 
b/src/bin/pkgman/command_drop_repo.cpp
index e026757..0703fb1 100644
--- a/src/bin/pkgman/command_drop_repo.cpp
+++ b/src/bin/pkgman/command_drop_repo.cpp
@@ -85,18 +85,13 @@ DropRepoCommand::Execute(int argc, const char* const* argv)
 
        status_t result;
        DropRepositoryRequest dropRequest(context, repoName);
-       result = dropRequest.InitCheck();
-       if (result != B_OK)
-               DIE(result, "unable to create request for dropping repository");
-       result = dropRequest.CreateInitialJobs();
-       if (result != B_OK)
-               DIE(result, "unable to create necessary jobs");
-
-       while (BJob* job = dropRequest.PopRunnableJob()) {
-               result = job->Run();
-               delete job;
-               if (result == B_CANCELED)
-                       return 1;
+       result = dropRequest.Process(true);
+       if (result != B_OK) {
+               if (result != B_CANCELED) {
+                       DIE(result, "request for dropping repository \"%s\" 
failed",
+                               repoName);
+               }
+               return 1;
        }
 
        return 0;
diff --git a/src/bin/pkgman/command_refresh.cpp 
b/src/bin/pkgman/command_refresh.cpp
index 50764c9..6023edc 100644
--- a/src/bin/pkgman/command_refresh.cpp
+++ b/src/bin/pkgman/command_refresh.cpp
@@ -40,7 +40,6 @@ static const char* const kLongUsage =
 DEFINE_COMMAND(RefreshCommand, "refresh", kShortUsage, kLongUsage)
 
 
-
 int
 RefreshCommand::Execute(int argc, const char* const* argv)
 {
@@ -70,10 +69,6 @@ RefreshCommand::Execute(int argc, const char* const* argv)
        const char* const* repoArgs = argv + optind;
        int nameCount = argc - optind;
 
-       DecisionProvider decisionProvider;
-       JobStateListener listener;
-       BContext context(decisionProvider, listener);
-
        BStringList repositoryNames(20);
 
        BPackageRoster roster;
@@ -88,6 +83,10 @@ RefreshCommand::Execute(int argc, const char* const* argv)
                }
        }
 
+       DecisionProvider decisionProvider;
+       JobStateListener listener;
+       BContext context(decisionProvider, listener);
+
        status_t result;
        for (int i = 0; i < repositoryNames.CountStrings(); ++i) {
                const BString& repoName = repositoryNames.StringAt(i);
@@ -99,20 +98,11 @@ RefreshCommand::Execute(int argc, const char* const* argv)
                        WARN(result, "skipping repository-config '%s'", 
path.Path());
                        continue;
                }
+
                BRefreshRepositoryRequest refreshRequest(context, repoConfig);
-               result = refreshRequest.InitCheck();
+               result = refreshRequest.Process();
                if (result != B_OK)
-                       DIE(result, "unable to create request for refreshing 
repository");
-               result = refreshRequest.CreateInitialJobs();
-               if (result != B_OK)
-                       DIE(result, "unable to create necessary jobs");
-
-               while (BJob* job = refreshRequest.PopRunnableJob()) {
-                       result = job->Run();
-                       delete job;
-                       if (result != B_OK)
-                               return 1;
-               }
+                       DIE(result, "request for refreshing repository failed");
        }
 
        return 0;


Other related posts:

  • » [haiku-commits] BRANCH HaikuPM-github.package-management - in src: bin/pkgman kits/package - HaikuPM-github . package-management