BPicture: Fix archive constructor.
[haiku.git] / src / kits / package / ActivateRepositoryConfigJob.cpp
bloba1aadb4a8b8ebffe24cf72939e2a6e10402f4e1c
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/ActivateRepositoryConfigJob.h>
12 #include <package/Context.h>
13 #include <package/RepositoryConfig.h>
14 #include <package/RepositoryInfo.h>
17 namespace BPackageKit {
19 namespace BPrivate {
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()
40 status_t
41 ActivateRepositoryConfigJob::Execute()
43 BRepositoryInfo repoInfo(fArchivedRepoInfoEntry);
44 status_t result = repoInfo.InitCheck();
45 if (result != B_OK)
46 return result;
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");
55 if (!yes) {
56 fTargetEntry.Unset();
57 return B_CANCELED;
61 // create and store the configuration (injecting the BaseURL that was
62 // actually used)
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)
68 return result;
70 // store name of activated repository as result
71 fRepositoryName = repoConfig.Name();
73 return B_OK;
77 void
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();
86 const BString&
87 ActivateRepositoryConfigJob::RepositoryName() const
89 return fRepositoryName;
93 } // namespace BPrivate
95 } // namespace BPackageKit