[haiku-commits] r40290 - in haiku/trunk: headers/os/package headers/private/package src/bin/pkgman src/kits/package src/tests/kits/package

  • From: zooey@xxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 25 Jan 2011 20:36:09 +0100 (CET)

Author: zooey
Date: 2011-01-25 20:36:09 +0100 (Tue, 25 Jan 2011)
New Revision: 40290
Changeset: http://dev.haiku-os.org/changeset/40290

Added:
   haiku/trunk/headers/os/package/DropRepositoryRequest.h
   haiku/trunk/headers/os/package/RepositoryHeader.h
   haiku/trunk/headers/private/package/RemoveRepositoryJob.h
   haiku/trunk/src/bin/pkgman/command_drop_repo.cpp
   haiku/trunk/src/kits/package/DropRepositoryRequest.cpp
   haiku/trunk/src/kits/package/RemoveRepositoryJob.cpp
   haiku/trunk/src/kits/package/RepositoryHeader.cpp
Modified:
   haiku/trunk/headers/os/package/RepositoryCache.h
   haiku/trunk/headers/os/package/RepositoryConfig.h
   haiku/trunk/headers/private/package/ActivateRepositoryCacheJob.h
   haiku/trunk/headers/private/package/ActivateRepositoryConfigJob.h
   haiku/trunk/headers/private/package/FetchFileJob.h
   haiku/trunk/headers/private/package/ValidateChecksumJob.h
   haiku/trunk/src/bin/pkgman/Jamfile
   haiku/trunk/src/bin/pkgman/pkgman.cpp
   haiku/trunk/src/kits/package/ActivateRepositoryConfigJob.cpp
   haiku/trunk/src/kits/package/Jamfile
   haiku/trunk/src/kits/package/RefreshRepositoryRequest.cpp
   haiku/trunk/src/kits/package/RepositoryCache.cpp
   haiku/trunk/src/kits/package/RepositoryConfig.cpp
   haiku/trunk/src/tests/kits/package/make_repo.cpp
Log:
more work on package kit:
* rip BRepositoryHeader out of BRepositoryConfig and add support
  for it to BRepositoryCache
* implement repository removal
* some minor cleanups


Added: haiku/trunk/headers/os/package/DropRepositoryRequest.h
===================================================================
--- haiku/trunk/headers/os/package/DropRepositoryRequest.h                      
        (rev 0)
+++ haiku/trunk/headers/os/package/DropRepositoryRequest.h      2011-01-25 
19:36:09 UTC (rev 40290)
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2011, Haiku, Inc.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef _PACKAGE__DROP_REPOSITORY_REQUEST_H_
+#define _PACKAGE__DROP_REPOSITORY_REQUEST_H_
+
+
+#include <String.h>
+
+#include <package/Context.h>
+#include <package/Request.h>
+
+
+namespace BPackageKit {
+
+
+class DropRepositoryRequest : public BRequest {
+       typedef BRequest                                inherited;
+
+public:
+                                                               
DropRepositoryRequest(const BContext& context,
+                                                                       const 
BString& repositoryName);
+       virtual                                         
~DropRepositoryRequest();
+
+       virtual status_t                        CreateInitialJobs();
+
+private:
+                       BString                         fRepositoryName;
+};
+
+
+}      // namespace BPackageKit
+
+
+#endif // _PACKAGE__ADD_REPOSITORY_REQUEST_H_

Modified: haiku/trunk/headers/os/package/RepositoryCache.h
===================================================================
--- haiku/trunk/headers/os/package/RepositoryCache.h    2011-01-25 19:14:31 UTC 
(rev 40289)
+++ haiku/trunk/headers/os/package/RepositoryCache.h    2011-01-25 19:36:09 UTC 
(rev 40290)
@@ -9,10 +9,9 @@
 #include <Entry.h>
 #include <String.h>
 
+#include <package/RepositoryHeader.h>
 
-class BEntry;
 
-
 namespace BPackageKit {
 
 
@@ -28,7 +27,7 @@
                        status_t                        SetTo(const BEntry& 
entry);
                        status_t                        InitCheck() const;
 
-//                     const RepositoryHeader* Header() const;
+                       const BRepositoryHeader&        Header() const;
                        const BEntry&           Entry() const;
                        bool                            IsUserSpecific() const;
 
@@ -38,7 +37,7 @@
                        status_t                        fInitStatus;
 
                        BEntry                          fEntry;
-//                     RepositoryHeader*       fHeader;
+                       BRepositoryHeader       fHeader;
                        bool                            fIsUserSpecific;
 };
 

Modified: haiku/trunk/headers/os/package/RepositoryConfig.h
===================================================================
--- haiku/trunk/headers/os/package/RepositoryConfig.h   2011-01-25 19:14:31 UTC 
(rev 40289)
+++ haiku/trunk/headers/os/package/RepositoryConfig.h   2011-01-25 19:36:09 UTC 
(rev 40290)
@@ -6,62 +6,46 @@
 #define _PACKAGE__REPOSITORY_CONFIG_H_
 
 
-#include <Archivable.h>
 #include <Entry.h>
 #include <String.h>
 
 
-class BEntry;
-
-
 namespace BPackageKit {
 
 
-class BRepositoryConfig : public BArchivable {
-       typedef BArchivable                     inherited;
-
+class BRepositoryConfig {
 public:
                                                                
BRepositoryConfig();
                                                                
BRepositoryConfig(const BString& name,
-                                                                       const 
BString& url,
-                                                                       uint8 
priority = kDefaultPriority);
+                                                                       const 
BString& url, uint8 priority);
                                                                
BRepositoryConfig(const BEntry& entry);
-                                                               
BRepositoryConfig(BMessage* data);
        virtual                                         ~BRepositoryConfig();
 
-       virtual status_t                        Archive(BMessage* data, bool 
deep = true) const;
+                       status_t                        Store(const BEntry& 
entry) const;
 
-                       status_t                        StoreAsConfigFile(const 
BEntry& entry) const;
-
                        status_t                        SetTo(const BEntry& 
entry);
-                       status_t                        SetTo(const BMessage* 
data);
                        status_t                        InitCheck() const;
 
                        const BString&          Name() const;
-                       const BString&          URL() const;
+                       const BString&          BaseURL() const;
                        uint8                           Priority() const;
                        bool                            IsUserSpecific() const;
 
                        const BEntry&           Entry() const;
 
                        void                            SetName(const BString& 
name);
-                       void                            SetURL(const BString& 
url);
+                       void                            SetBaseURL(const 
BString& url);
                        void                            SetPriority(uint8 
priority);
                        void                            SetIsUserSpecific(bool 
isUserSpecific);
 
 public:
-       static  BRepositoryConfig*      Instantiate(BMessage* data);
+       static  const uint8                     kUnsetPriority = 0;
 
-       static  const uint8                     kDefaultPriority;
-       static  const char*                     kNameField;
-       static  const char*                     kURLField;
-       static  const char*                     kPriorityField;
-
 private:
                        status_t                        fInitStatus;
 
                        BString                         fName;
-                       BString                         fURL;
+                       BString                         fBaseURL;
                        uint8                           fPriority;
                        bool                            fIsUserSpecific;
 

Added: haiku/trunk/headers/os/package/RepositoryHeader.h
===================================================================
--- haiku/trunk/headers/os/package/RepositoryHeader.h                           
(rev 0)
+++ haiku/trunk/headers/os/package/RepositoryHeader.h   2011-01-25 19:36:09 UTC 
(rev 40290)
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2011, Haiku, Inc.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef _PACKAGE__REPOSITORY_HEADER_H_
+#define _PACKAGE__REPOSITORY_HEADER_H_
+
+
+#include <Archivable.h>
+#include <String.h>
+
+
+namespace BPackageKit {
+
+
+class BRepositoryHeader : public BArchivable {
+       typedef BArchivable                     inherited;
+
+public:
+                                                               
BRepositoryHeader();
+                                                               
BRepositoryHeader(BMessage* data);
+       virtual                                         ~BRepositoryHeader();
+
+       virtual status_t                        Archive(BMessage* data, bool 
deep = true) const;
+
+                       status_t                        SetTo(const BMessage* 
data);
+                       status_t                        InitCheck() const;
+
+                       const BString&          Name() const;
+                       const BString&          OriginalBaseURL() const;
+                       const BString&          Vendor() const;
+                       const BString&          ShortDescription() const;
+                       const BString&          LongDescription() const;
+                       uint8                           Priority() const;
+
+                       void                            SetName(const BString& 
name);
+                       void                            
SetOriginalBaseURL(const BString& url);
+                       void                            SetVendor(const 
BString& vendor);
+                       void                            
SetShortDescription(const BString& description);
+                       void                            
SetLongDescription(const BString& description);
+                       void                            SetPriority(uint8 
priority);
+
+public:
+       static  BRepositoryHeader*      Instantiate(BMessage* data);
+
+       static  const uint8                     kDefaultPriority;
+
+       static  const char*                     kNameField;
+       static  const char*                     kURLField;
+       static  const char*                     kVendorField;
+       static  const char*                     kShortDescriptionField;
+       static  const char*                     kLongDescriptionField;
+       static  const char*                     kPriorityField;
+
+private:
+                       status_t                        fInitStatus;
+
+                       BString                         fName;
+                       BString                         fOriginalBaseURL;
+                       BString                         fVendor;
+                       BString                         fShortDescription;
+                       BString                         fLongDescription;
+                       uint8                           fPriority;
+};
+
+
+}      // namespace BPackageKit
+
+
+#endif // _PACKAGE__REPOSITORY_HEADER_H_

Modified: haiku/trunk/headers/private/package/ActivateRepositoryCacheJob.h
===================================================================
--- haiku/trunk/headers/private/package/ActivateRepositoryCacheJob.h    
2011-01-25 19:14:31 UTC (rev 40289)
+++ haiku/trunk/headers/private/package/ActivateRepositoryCacheJob.h    
2011-01-25 19:36:09 UTC (rev 40290)
@@ -19,7 +19,7 @@
 
 
 class ActivateRepositoryCacheJob : public BJob {
-       typedef BJob                                    inherited;
+       typedef BJob                            inherited;
 
 public:
                                                                
ActivateRepositoryCacheJob(

Modified: haiku/trunk/headers/private/package/ActivateRepositoryConfigJob.h
===================================================================
--- haiku/trunk/headers/private/package/ActivateRepositoryConfigJob.h   
2011-01-25 19:14:31 UTC (rev 40289)
+++ haiku/trunk/headers/private/package/ActivateRepositoryConfigJob.h   
2011-01-25 19:36:09 UTC (rev 40290)
@@ -19,13 +19,13 @@
 
 
 class ActivateRepositoryConfigJob : public BJob {
-       typedef BJob                                    inherited;
+       typedef BJob                            inherited;
 
 public:
                                                                
ActivateRepositoryConfigJob(
                                                                        const 
BContext& context,
                                                                        const 
BString& title,
-                                                                       const 
BEntry& archivedRepoConfigEntry,
+                                                                       const 
BEntry& archivedRepoHeaderEntry,
                                                                        const 
BString& repositoryBaseURL,
                                                                        const 
BDirectory& targetDirectory);
        virtual                                         
~ActivateRepositoryConfigJob();
@@ -37,7 +37,7 @@
        virtual void                            Cleanup(status_t jobResult);
 
 private:
-                       BEntry                          
fArchivedRepoConfigEntry;
+                       BEntry                          
fArchivedRepoHeaderEntry;
                        BString                         fRepositoryBaseURL;
                        BDirectory                      fTargetDirectory;
                        BEntry                          fTargetEntry;

Modified: haiku/trunk/headers/private/package/FetchFileJob.h
===================================================================
--- haiku/trunk/headers/private/package/FetchFileJob.h  2011-01-25 19:14:31 UTC 
(rev 40289)
+++ haiku/trunk/headers/private/package/FetchFileJob.h  2011-01-25 19:36:09 UTC 
(rev 40290)
@@ -18,7 +18,7 @@
 
 
 class FetchFileJob : public BJob {
-       typedef BJob                                    inherited;
+       typedef BJob                            inherited;
 
 public:
                                                                
FetchFileJob(const BContext& context,

Added: haiku/trunk/headers/private/package/RemoveRepositoryJob.h
===================================================================
--- haiku/trunk/headers/private/package/RemoveRepositoryJob.h                   
        (rev 0)
+++ haiku/trunk/headers/private/package/RemoveRepositoryJob.h   2011-01-25 
19:36:09 UTC (rev 40290)
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2011, Oliver Tappe <zooey@xxxxxxxxxxxxxxx>
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef _PACKAGE__PRIVATE__REMOVE_REPOSITORY_JOB_H_
+#define _PACKAGE__PRIVATE__REMOVE_REPOSITORY_JOB_H_
+
+
+#include <String.h>
+
+#include <package/Job.h>
+
+
+namespace BPackageKit {
+
+namespace BPrivate {
+
+
+class RemoveRepositoryJob : public BJob {
+       typedef BJob                            inherited;
+
+public:
+                                                               
RemoveRepositoryJob(
+                                                                       const 
BContext& context,
+                                                                       const 
BString& title,
+                                                                       const 
BString& repositoryName);
+       virtual                                         ~RemoveRepositoryJob();
+
+protected:
+       virtual status_t                        Execute();
+
+private:
+                       BString                         fRepositoryName;
+};
+
+
+}      // namespace BPrivate
+
+}      // namespace BPackageKit
+
+
+#endif // _PACKAGE__PRIVATE__REMOVE_REPOSITORY_JOB_H_

Modified: haiku/trunk/headers/private/package/ValidateChecksumJob.h
===================================================================
--- haiku/trunk/headers/private/package/ValidateChecksumJob.h   2011-01-25 
19:14:31 UTC (rev 40289)
+++ haiku/trunk/headers/private/package/ValidateChecksumJob.h   2011-01-25 
19:36:09 UTC (rev 40290)
@@ -20,7 +20,7 @@
 
 
 class ValidateChecksumJob : public BJob {
-       typedef BJob                                    inherited;
+       typedef BJob                            inherited;
 
 public:
                                                                
ValidateChecksumJob(

Modified: haiku/trunk/src/bin/pkgman/Jamfile
===================================================================
--- haiku/trunk/src/bin/pkgman/Jamfile  2011-01-25 19:14:31 UTC (rev 40289)
+++ haiku/trunk/src/bin/pkgman/Jamfile  2011-01-25 19:36:09 UTC (rev 40290)
@@ -4,6 +4,7 @@
 
 BinCommand pkgman :
        command_add_repo.cpp
+       command_drop_repo.cpp
        command_list_repos.cpp
        command_refresh.cpp
        DecisionProvider.cpp

Added: haiku/trunk/src/bin/pkgman/command_drop_repo.cpp
===================================================================
--- haiku/trunk/src/bin/pkgman/command_drop_repo.cpp                            
(rev 0)
+++ haiku/trunk/src/bin/pkgman/command_drop_repo.cpp    2011-01-25 19:36:09 UTC 
(rev 40290)
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2011, Oliver Tappe <zooey@xxxxxxxxxxxxxxxx>
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <Errors.h>
+#include <SupportDefs.h>
+
+#include <package/DropRepositoryRequest.h>
+#include <package/Context.h>
+
+#include "DecisionProvider.h"
+#include "JobStateListener.h"
+#include "pkgman.h"
+
+
+using namespace BPackageKit;
+
+
+// TODO: internationalization!
+
+
+static const char* kCommandUsage =
+       "Usage: %s drop-repo <repo-name>\n"
+       "Drops (i.e. removes) the repository with the given name.\n"
+       "\n"
+;
+
+
+static void
+print_command_usage_and_exit(bool error)
+{
+    fprintf(error ? stderr : stdout, kCommandUsage, kProgramName);
+    exit(error ? 1 : 0);
+}
+
+
+int
+command_drop_repo(int argc, const char* const* argv)
+{
+       bool yesMode = false;
+
+       while (true) {
+               static struct option sLongOptions[] = {
+                       { "help", no_argument, 0, 'h' },
+                       { "yes", no_argument, 0, 'y' },
+                       { 0, 0, 0, 0 }
+               };
+
+               opterr = 0; // don't print errors
+               int c = getopt_long(argc, (char**)argv, "hu", sLongOptions, 
NULL);
+               if (c == -1)
+                       break;
+
+               switch (c) {
+                       case 'h':
+                               print_command_usage_and_exit(false);
+                               break;
+
+                       case 'y':
+                               yesMode = true;
+                               break;
+
+                       default:
+                               print_command_usage_and_exit(true);
+                               break;
+               }
+       }
+
+       // The remaining argument is a repo name, i. e. one more argument.
+       if (argc != optind + 1)
+               print_command_usage_and_exit(true);
+
+       const char* repoName = argv[optind];
+
+       DecisionProvider decisionProvider;
+//     if (yesMode)
+//             decisionProvider.SetAcceptEverything(true);
+       JobStateListener listener;
+       BContext context(decisionProvider, listener);
+
+       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;
+       }
+
+       return 0;
+}

Modified: haiku/trunk/src/bin/pkgman/pkgman.cpp
===================================================================
--- haiku/trunk/src/bin/pkgman/pkgman.cpp       2011-01-25 19:14:31 UTC (rev 
40289)
+++ haiku/trunk/src/bin/pkgman/pkgman.cpp       2011-01-25 19:36:09 UTC (rev 
40290)
@@ -53,16 +53,16 @@
                print_usage_and_exit(true);
 
        const char* command = argv[1];
-       if (strcmp(command, "add-repo") == 0 || strcmp(command, "ar") == 0)
+       if (strncmp(command, "add-r", 5) == 0)
                return command_add_repo(argc - 1, argv + 1);
 
-//     if (strcmp(command, "drop-repo") == 0)
-//             return command_drop_repo(argc - 1, argv + 1);
+       if (strncmp(command, "drop-r", 6) == 0)
+               return command_drop_repo(argc - 1, argv + 1);
 
-       if (strcmp(command, "list-repos") == 0 || strcmp(command, "lr") == 0)
+       if (strncmp(command, "list-r", 6) == 0)
                return command_list_repos(argc - 1, argv + 1);
 
-       if (strcmp(command, "refresh") == 0)
+       if (strncmp(command, "refr", 4) == 0)
                return command_refresh(argc - 1, argv + 1);
 
 //     if (strcmp(command, "search") == 0)

Modified: haiku/trunk/src/kits/package/ActivateRepositoryConfigJob.cpp
===================================================================
--- haiku/trunk/src/kits/package/ActivateRepositoryConfigJob.cpp        
2011-01-25 19:14:31 UTC (rev 40289)
+++ haiku/trunk/src/kits/package/ActivateRepositoryConfigJob.cpp        
2011-01-25 19:36:09 UTC (rev 40290)
@@ -10,9 +10,13 @@
 #include <package/ActivateRepositoryConfigJob.h>
 
 #include <File.h>
+#include <Message.h>
 
+#include <AutoDeleter.h>
+
 #include <package/Context.h>
 #include <package/RepositoryConfig.h>
+#include <package/RepositoryHeader.h>
 
 
 namespace BPackageKit {
@@ -22,11 +26,11 @@
 
 ActivateRepositoryConfigJob::ActivateRepositoryConfigJob(
        const BContext& context, const BString& title,
-       const BEntry& archivedRepoConfigEntry, const BString& repositoryBaseURL,
+       const BEntry& archivedRepoHeaderEntry, const BString& repositoryBaseURL,
        const BDirectory& targetDirectory)
        :
        inherited(context, title),
-       fArchivedRepoConfigEntry(archivedRepoConfigEntry),
+       fArchivedRepoHeaderEntry(archivedRepoHeaderEntry),
        fRepositoryBaseURL(repositoryBaseURL),
        fTargetDirectory(targetDirectory)
 {
@@ -41,7 +45,7 @@
 status_t
 ActivateRepositoryConfigJob::Execute()
 {
-       BFile archiveFile(&fArchivedRepoConfigEntry, B_READ_ONLY);
+       BFile archiveFile(&fArchivedRepoHeaderEntry, B_READ_ONLY);
        status_t result = archiveFile.InitCheck();
        if (result != B_OK)
                return result;
@@ -50,16 +54,17 @@
        if ((result = archive.Unflatten(&archiveFile)) != B_OK)
                return result;
 
-       BRepositoryConfig* repoConfig = 
BRepositoryConfig::Instantiate(&archive);
-       if (repoConfig == NULL)
+       BRepositoryHeader* repoHeader = 
BRepositoryHeader::Instantiate(&archive);
+       if (repoHeader == NULL)
                return B_BAD_DATA;
-       if ((result = repoConfig->InitCheck()) != B_OK)
+       ObjectDeleter<BRepositoryHeader> repoHeaderDeleter(repoHeader);
+       if ((result = repoHeader->InitCheck()) != B_OK)
                return result;
 
-       fTargetEntry.SetTo(&fTargetDirectory, repoConfig->Name().String());
+       fTargetEntry.SetTo(&fTargetDirectory, repoHeader->Name().String());
        if (fTargetEntry.Exists()) {
                BString description = BString("A repository configuration for ")
-                       << repoConfig->Name() << " already exists.";
+                       << repoHeader->Name() << " already exists.";
                BString question("overwrite?");
                bool yes = fContext.DecisionProvider().YesNoDecisionNeeded(
                        description, question, "yes", "no", "no");
@@ -69,13 +74,17 @@
                }
        }
 
-       // inject the URL that was actually used and write the config file
-       repoConfig->SetURL(fRepositoryBaseURL);
-       if ((result = repoConfig->StoreAsConfigFile(fTargetEntry)) != B_OK)
+       // create and store the configuration (injecting the BaseURL that was
+       // actually used)
+       BRepositoryConfig repoConfig;
+       repoConfig.SetName(repoHeader->Name());
+       repoConfig.SetBaseURL(fRepositoryBaseURL);
+       repoConfig.SetPriority(repoHeader->Priority());
+       if ((result = repoConfig.Store(fTargetEntry)) != B_OK)
                return result;
 
        // store name of activated repository as result
-       fRepositoryName = repoConfig->Name();
+       fRepositoryName = repoConfig.Name();
 
        return B_OK;
 }

Added: haiku/trunk/src/kits/package/DropRepositoryRequest.cpp
===================================================================
--- haiku/trunk/src/kits/package/DropRepositoryRequest.cpp                      
        (rev 0)
+++ haiku/trunk/src/kits/package/DropRepositoryRequest.cpp      2011-01-25 
19:36:09 UTC (rev 40290)
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2011, Haiku, Inc. All Rights Reserved.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             Oliver Tappe <zooey@xxxxxxxxxxxxxxx>
+ */
+
+
+#include <package/DropRepositoryRequest.h>
+
+#include <Directory.h>
+#include <Path.h>
+
+#include <package/RemoveRepositoryJob.h>
+#include <package/JobQueue.h>
+
+
+namespace BPackageKit {
+
+
+using namespace BPrivate;
+
+
+DropRepositoryRequest::DropRepositoryRequest(const BContext& context,
+       const BString& repositoryName)
+       :
+       inherited(context),
+       fRepositoryName(repositoryName)
+{
+}
+
+
+DropRepositoryRequest::~DropRepositoryRequest()
+{
+}
+
+
+status_t
+DropRepositoryRequest::CreateInitialJobs()
+{
+       status_t result = InitCheck();
+       if (result != B_OK)
+               return B_NO_INIT;
+
+       RemoveRepositoryJob* removeRepoJob
+               = new (std::nothrow) RemoveRepositoryJob(fContext,
+                       BString("Removing repository ") << fRepositoryName,
+                       fRepositoryName);
+       if (removeRepoJob == NULL)
+               return B_NO_MEMORY;
+       if ((result = QueueJob(removeRepoJob)) != B_OK) {
+               delete removeRepoJob;
+               return result;
+       }
+
+       return B_OK;
+}
+
+
+}      // namespace BPackageKit

Modified: haiku/trunk/src/kits/package/Jamfile
===================================================================
--- haiku/trunk/src/kits/package/Jamfile        2011-01-25 19:14:31 UTC (rev 
40289)
+++ haiku/trunk/src/kits/package/Jamfile        2011-01-25 19:36:09 UTC (rev 
40290)
@@ -10,14 +10,16 @@
        Attributes.cpp
        ChecksumAccessors.cpp
        Context.cpp
+       DropRepositoryRequest.cpp
        FetchFileJob.cpp
        Job.cpp
        JobQueue.cpp
        PackageRoster.cpp
        RefreshRepositoryRequest.cpp
+       RemoveRepositoryJob.cpp
        RepositoryCache.cpp
        RepositoryConfig.cpp
-#      RepositoryHeader.cpp
+       RepositoryHeader.cpp
        Request.cpp
        TempfileManager.cpp
        ValidateChecksumJob.cpp

Modified: haiku/trunk/src/kits/package/RefreshRepositoryRequest.cpp
===================================================================
--- haiku/trunk/src/kits/package/RefreshRepositoryRequest.cpp   2011-01-25 
19:14:31 UTC (rev 40289)
+++ haiku/trunk/src/kits/package/RefreshRepositoryRequest.cpp   2011-01-25 
19:36:09 UTC (rev 40290)
@@ -58,10 +58,10 @@
        if (result != B_OK)
                return result;
        BString repoChecksumURL
-               = BString(fRepoConfig.URL()) << "/" << "repo.sha256";
+               = BString(fRepoConfig.BaseURL()) << "/" << "repo.sha256";
        FetchFileJob* fetchChecksumJob = new (std::nothrow) FetchFileJob(
                fContext,
-               BString("Fetching repository checksum from ") << 
fRepoConfig.URL(),
+               BString("Fetching repository checksum from ") << 
fRepoConfig.BaseURL(),
                repoChecksumURL, fFetchedChecksumFile);
        if (fetchChecksumJob == NULL)
                return B_NO_MEMORY;
@@ -119,9 +119,9 @@
        status_t result = fContext.GetNewTempfile("repocache-", &tempRepoCache);
        if (result != B_OK)
                return result;
-       BString repoCacheURL = BString(fRepoConfig.URL()) << "/" << "repo";
+       BString repoCacheURL = BString(fRepoConfig.BaseURL()) << "/" << "repo";
        FetchFileJob* fetchCacheJob = new (std::nothrow) FetchFileJob(fContext,
-               BString("Fetching repository-cache from ") << fRepoConfig.URL(),
+               BString("Fetching repository-cache from ") << 
fRepoConfig.BaseURL(),
                repoCacheURL, tempRepoCache);
        if (fetchCacheJob == NULL)
                return B_NO_MEMORY;

Added: haiku/trunk/src/kits/package/RemoveRepositoryJob.cpp
===================================================================
--- haiku/trunk/src/kits/package/RemoveRepositoryJob.cpp                        
        (rev 0)
+++ haiku/trunk/src/kits/package/RemoveRepositoryJob.cpp        2011-01-25 
19:36:09 UTC (rev 40290)
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2011, Haiku, Inc. All Rights Reserved.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             Oliver Tappe <zooey@xxxxxxxxxxxxxxx>
+ */
+
+
+#include <package/RemoveRepositoryJob.h>
+
+#include <Entry.h>
+
+#include <package/Context.h>
+#include <package/PackageRoster.h>
+#include <package/RepositoryCache.h>
+#include <package/RepositoryConfig.h>
+
+
+namespace BPackageKit {
+
+namespace BPrivate {
+
+
+RemoveRepositoryJob::RemoveRepositoryJob(const BContext& context,
+       const BString& title, const BString& repositoryName)
+       :
+       inherited(context, title),
+       fRepositoryName(repositoryName)
+{
+}
+
+
+RemoveRepositoryJob::~RemoveRepositoryJob()
+{
+}
+
+
+status_t
+RemoveRepositoryJob::Execute()
+{
+       BPackageRoster roster;
+       BRepositoryConfig repoConfig;
+       status_t result = roster.GetRepositoryConfig(fRepositoryName, 
&repoConfig);
+       if (result != B_OK) {
+               if (result == B_ENTRY_NOT_FOUND) {
+                       BString error = BString("repository '") << 
fRepositoryName
+                               << "' not found!";
+                       SetErrorString(error);
+               }
+               return result;
+       }
+
+       BString question = BString("Really remove the repository '")
+               << fRepositoryName << "'?";
+       bool yes = fContext.DecisionProvider().YesNoDecisionNeeded("", question,
+               "yes", "no", "no");
+       if (!yes)
+               return B_CANCELED;
+
+       BEntry repoConfigEntry = repoConfig.Entry();
+       if ((result = repoConfigEntry.Remove()) != B_OK)
+               return result;
+
+       BRepositoryCache repoCache;
+       if (roster.GetRepositoryCache(fRepositoryName, &repoCache) == B_OK) {
+               BEntry repoCacheEntry = repoCache.Entry();
+               if ((result = repoCacheEntry.Remove()) != B_OK)
+                       return result;
+       }
+
+       return B_OK;
+}
+
+
+}      // namespace BPrivate
+
+}      // namespace BPackageKit

Modified: haiku/trunk/src/kits/package/RepositoryCache.cpp
===================================================================
--- haiku/trunk/src/kits/package/RepositoryCache.cpp    2011-01-25 19:14:31 UTC 
(rev 40289)
+++ haiku/trunk/src/kits/package/RepositoryCache.cpp    2011-01-25 19:36:09 UTC 
(rev 40290)
@@ -9,8 +9,6 @@
 
 #include <package/RepositoryCache.h>
 
-#include <stdlib.h>
-
 #include <new>
 
 #include <Directory.h>
@@ -31,8 +29,10 @@
 
 
 BRepositoryCache::BRepositoryCache(const BEntry& entry)
+       :
+       fIsUserSpecific(false)
 {
-       SetTo(entry);
+       fInitStatus = SetTo(entry);
 }
 
 
@@ -55,6 +55,13 @@
 }
 
 
+const BRepositoryHeader&
+BRepositoryCache::Header() const
+{
+       return fHeader;
+}
+
+
 bool
 BRepositoryCache::IsUserSpecific() const
 {
@@ -73,7 +80,6 @@
 BRepositoryCache::SetTo(const BEntry& entry)
 {
        fEntry = entry;
-       fInitStatus = B_NO_INIT;
 
        BFile file(&entry, B_READ_ONLY);
        status_t result = file.InitCheck();
@@ -84,7 +90,8 @@
        if ((result = headerMsg.Unflatten(&file)) != B_OK)
                return result;
 
-       // TODO: unarchive header and read packages
+       if ((result = fHeader.SetTo(&headerMsg)) != B_OK)
+               return result;
 
        BPath userSettingsPath;
        if (find_directory(B_USER_SETTINGS_DIRECTORY, &userSettingsPath) == 
B_OK) {
@@ -93,10 +100,30 @@
        } else
                fIsUserSpecific = false;
 
-       fInitStatus = B_OK;
-
        return B_OK;
 }
 
 
+//status_t
+//BRepositoryCache::_ReadPackageHeaders()
+//{
+////   if (fPackageHeaders != NULL)
+////           return B_OK;
+//
+//     BFile file(&fEntry, B_READ_ONLY);
+//     status_t result = file.InitCheck();
+//     if (result != B_OK)
+//             return result;
+//
+//     BMessage headerMsg;
+//     if ((result = headerMsg.Unflatten(&file)) != B_OK)
+//             return result;
+//
+//
+//     // TODO: read packages!
+//
+//     return B_OK;
+//}
+
+
 }      // namespace BPackageKit

Modified: haiku/trunk/src/kits/package/RepositoryConfig.cpp
===================================================================
--- haiku/trunk/src/kits/package/RepositoryConfig.cpp   2011-01-25 19:14:31 UTC 
(rev 40289)
+++ haiku/trunk/src/kits/package/RepositoryConfig.cpp   2011-01-25 19:36:09 UTC 
(rev 40290)
@@ -23,16 +23,10 @@
 namespace BPackageKit {
 
 
-const uint8 BRepositoryConfig::kDefaultPriority        = 50;
-const char* BRepositoryConfig::kNameField              = "name";
-const char* BRepositoryConfig::kURLField               = "url";
-const char* BRepositoryConfig::kPriorityField  = "priority";
-
-
 BRepositoryConfig::BRepositoryConfig()
        :
        fInitStatus(B_NO_INIT),
-       fPriority(kDefaultPriority),
+       fPriority(kUnsetPriority),
        fIsUserSpecific(false)
 {
 }
@@ -44,20 +38,12 @@
 }
 
 
-BRepositoryConfig::BRepositoryConfig(BMessage* data)
+BRepositoryConfig::BRepositoryConfig(const BString& name,
+       const BString& baseURL, uint8 priority)
        :
-       inherited(data)
-{
-       SetTo(data);
-}
-
-
-BRepositoryConfig::BRepositoryConfig(const BString& name, const BString& url,
-       uint8 priority)
-       :
        fInitStatus(B_OK),
        fName(name),
-       fURL(url),
+       fBaseURL(baseURL),
        fPriority(priority),
        fIsUserSpecific(false)
 {
@@ -69,37 +55,9 @@
 }
 
 
-/*static*/ BRepositoryConfig*
-BRepositoryConfig::Instantiate(BMessage* data)
-{
-       if (validate_instantiation(data, "BPackageKit::BRepositoryConfig"))
-               return new (std::nothrow) BRepositoryConfig(data);
-
-       return NULL;
-}
-
-
 status_t
-BRepositoryConfig::Archive(BMessage* data, bool deep) const
+BRepositoryConfig::Store(const BEntry& entry) const
 {
-       status_t result = inherited::Archive(data, deep);
-       if (result != B_OK)
-               return result;
-
-       if ((result = data->AddString(kNameField, fName)) != B_OK)
-               return result;
-       if ((result = data->AddString(kURLField, fURL)) != B_OK)
-               return result;
-       if ((result = data->AddUInt8(kPriorityField, fPriority)) != B_OK)
-               return result;
-
-       return B_OK;
-}
-
-
-status_t
-BRepositoryConfig::StoreAsConfigFile(const BEntry& entry) const
-{
        BFile file(&entry, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
        status_t result = file.InitCheck();
        if (result != B_OK)
@@ -107,7 +65,7 @@
 
        BString configString;
        configString
-               << "url=" << fURL << "\n"
+               << "url=" << fBaseURL << "\n"
                << "priority=" << fPriority << "\n";
 
        int32 size = configString.Length();
@@ -169,9 +127,9 @@
                return result;
 
        fName = name;
-       fURL = url;
+       fBaseURL = url;
        fPriority = priorityString == NULL
-               ? kDefaultPriority : atoi(priorityString);
+               ? kUnsetPriority : atoi(priorityString);
 
        BPath userSettingsPath;
        if (find_directory(B_USER_SETTINGS_DIRECTORY, &userSettingsPath) == 
B_OK) {
@@ -186,30 +144,6 @@
 }
 
 
-status_t
-BRepositoryConfig::SetTo(const BMessage* data)
-{
-       fInitStatus = B_NO_INIT;
-
-       if (data == NULL)
-               return B_BAD_VALUE;
-
-       status_t result;
-       if ((result = data->FindString(kNameField, &fName)) != B_OK)

[... truncated: 308 lines follow ...]

Other related posts:

  • » [haiku-commits] r40290 - in haiku/trunk: headers/os/package headers/private/package src/bin/pkgman src/kits/package src/tests/kits/package - zooey