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/ActivateRepositoryConfigJob.h>
12 #include <package/Context.h>
13 #include <package/RepositoryConfig.h>
14 #include <package/RepositoryInfo.h>
17 namespace BPackageKit
{
22 ActivateRepositoryConfigJob::ActivateRepositoryConfigJob(
23 const BContext
& context
, const BString
& title
,
24 const BEntry
& archivedRepoInfoEntry
, const BString
& repositoryBaseURL
,
25 const BDirectory
& targetDirectory
)
27 inherited(context
, title
),
28 fArchivedRepoInfoEntry(archivedRepoInfoEntry
),
29 fRepositoryBaseURL(repositoryBaseURL
),
30 fTargetDirectory(targetDirectory
)
35 ActivateRepositoryConfigJob::~ActivateRepositoryConfigJob()
41 ActivateRepositoryConfigJob::Execute()
43 BRepositoryInfo
repoInfo(fArchivedRepoInfoEntry
);
44 status_t result
= repoInfo
.InitCheck();
48 fTargetEntry
.SetTo(&fTargetDirectory
, repoInfo
.Name().String());
49 if (fTargetEntry
.Exists()) {
50 BString description
= BString("A repository configuration for ")
51 << repoInfo
.Name() << " already exists.";
52 BString
question("overwrite?");
53 bool yes
= fContext
.DecisionProvider().YesNoDecisionNeeded(
54 description
, question
, "yes", "no", "no");
61 // create and store the configuration (injecting the BaseURL that was
63 BRepositoryConfig repoConfig
;
64 repoConfig
.SetName(repoInfo
.Name());
65 repoConfig
.SetBaseURL(fRepositoryBaseURL
);
66 repoConfig
.SetPriority(repoInfo
.Priority());
67 if ((result
= repoConfig
.Store(fTargetEntry
)) != B_OK
)
70 // store name of activated repository as result
71 fRepositoryName
= repoConfig
.Name();
78 ActivateRepositoryConfigJob::Cleanup(status_t jobResult
)
80 if (jobResult
!= B_OK
&& State() != BSupportKit::B_JOB_STATE_ABORTED
81 && fTargetEntry
.InitCheck() == B_OK
)
82 fTargetEntry
.Remove();
87 ActivateRepositoryConfigJob::RepositoryName() const
89 return fRepositoryName
;
93 } // namespace BPrivate
95 } // namespace BPackageKit