BPicture: Fix archive constructor.
[haiku.git] / src / kits / package / AddRepositoryRequest.cpp
blob05df47e70370656f3d0f7f3658eeea5e48a4e481
1 /*
2 * Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Oliver Tappe <zooey@hirschkaefer.de>
7 */
10 #include <package/AddRepositoryRequest.h>
12 #include <Directory.h>
13 #include <JobQueue.h>
14 #include <Path.h>
16 #include <package/ActivateRepositoryConfigJob.h>
17 #include <package/FetchFileJob.h>
18 #include <package/PackageRoster.h>
21 namespace BPackageKit {
24 using namespace BPrivate;
27 AddRepositoryRequest::AddRepositoryRequest(const BContext& context,
28 const BString& repositoryBaseURL, bool asUserRepository)
30 inherited(context),
31 fRepositoryBaseURL(repositoryBaseURL),
32 fAsUserRepository(asUserRepository),
33 fActivateJob(NULL)
38 AddRepositoryRequest::~AddRepositoryRequest()
43 status_t
44 AddRepositoryRequest::CreateInitialJobs()
46 status_t result = InitCheck();
47 if (result != B_OK)
48 return B_NO_INIT;
50 BEntry tempEntry;
51 result = fContext.GetNewTempfile("repoinfo-", &tempEntry);
52 if (result != B_OK)
53 return result;
54 BString repoInfoURL = BString(fRepositoryBaseURL) << "/" << "repo.info";
55 FetchFileJob* fetchJob = new (std::nothrow) FetchFileJob(fContext,
56 BString("Fetching repository info from ") << fRepositoryBaseURL,
57 repoInfoURL, tempEntry);
58 if (fetchJob == NULL)
59 return B_NO_MEMORY;
60 if ((result = QueueJob(fetchJob)) != B_OK) {
61 delete fetchJob;
62 return result;
65 BPackageRoster roster;
66 BPath targetRepoConfigPath;
67 result = fAsUserRepository
68 ? roster.GetUserRepositoryConfigPath(&targetRepoConfigPath, true)
69 : roster.GetCommonRepositoryConfigPath(&targetRepoConfigPath, true);
70 if (result != B_OK)
71 return result;
72 BDirectory targetDirectory(targetRepoConfigPath.Path());
73 ActivateRepositoryConfigJob* activateJob
74 = new (std::nothrow) ActivateRepositoryConfigJob(fContext,
75 BString("Activating repository config from ") << fRepositoryBaseURL,
76 tempEntry, fRepositoryBaseURL, targetDirectory);
77 if (activateJob == NULL)
78 return B_NO_MEMORY;
79 activateJob->AddDependency(fetchJob);
80 if ((result = QueueJob(activateJob)) != B_OK) {
81 delete activateJob;
82 return result;
84 fActivateJob = activateJob;
86 return B_OK;
90 void
91 AddRepositoryRequest::JobSucceeded(BSupportKit::BJob* job)
93 if (job == fActivateJob)
94 fRepositoryName = fActivateJob->RepositoryName();
98 const BString&
99 AddRepositoryRequest::RepositoryName() const
101 return fRepositoryName;
105 } // namespace BPackageKit