2 * Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Oliver Tappe <zooey@hirschkaefer.de>
10 #include <package/AddRepositoryRequest.h>
12 #include <Directory.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
)
31 fRepositoryBaseURL(repositoryBaseURL
),
32 fAsUserRepository(asUserRepository
),
38 AddRepositoryRequest::~AddRepositoryRequest()
44 AddRepositoryRequest::CreateInitialJobs()
46 status_t result
= InitCheck();
51 result
= fContext
.GetNewTempfile("repoinfo-", &tempEntry
);
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
);
60 if ((result
= QueueJob(fetchJob
)) != B_OK
) {
65 BPackageRoster roster
;
66 BPath targetRepoConfigPath
;
67 result
= fAsUserRepository
68 ? roster
.GetUserRepositoryConfigPath(&targetRepoConfigPath
, true)
69 : roster
.GetCommonRepositoryConfigPath(&targetRepoConfigPath
, true);
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
)
79 activateJob
->AddDependency(fetchJob
);
80 if ((result
= QueueJob(activateJob
)) != B_OK
) {
84 fActivateJob
= activateJob
;
91 AddRepositoryRequest::JobSucceeded(BSupportKit::BJob
* job
)
93 if (job
== fActivateJob
)
94 fRepositoryName
= fActivateJob
->RepositoryName();
99 AddRepositoryRequest::RepositoryName() const
101 return fRepositoryName
;
105 } // namespace BPackageKit