1 /* 2 * Copyright 2011, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Oliver Tappe <zooey@hirschkaefer.de> 7 */ 8 9 10 #include <package/RemoveRepositoryJob.h> 11 12 #include <Entry.h> 13 14 #include <package/Context.h> 15 #include <package/PackageRoster.h> 16 #include <package/RepositoryCache.h> 17 #include <package/RepositoryConfig.h> 18 19 20 namespace BPackageKit { 21 22 namespace BPrivate { 23 24 25 RemoveRepositoryJob::RemoveRepositoryJob(const BContext& context, 26 const BString& title, const BString& repositoryName) 27 : 28 inherited(context, title), 29 fRepositoryName(repositoryName) 30 { 31 } 32 33 34 RemoveRepositoryJob::~RemoveRepositoryJob() 35 { 36 } 37 38 39 status_t 40 RemoveRepositoryJob::Execute() 41 { 42 BPackageRoster roster; 43 BRepositoryConfig repoConfig; 44 status_t result = roster.GetRepositoryConfig(fRepositoryName, &repoConfig); 45 if (result != B_OK) { 46 if (result == B_ENTRY_NOT_FOUND) { 47 BString error = BString("repository '") << fRepositoryName 48 << "' not found!"; 49 SetErrorString(error); 50 } 51 return result; 52 } 53 54 BString question = BString("Really remove the repository '") 55 << fRepositoryName << "'?"; 56 bool yes = fContext.DecisionProvider().YesNoDecisionNeeded("", question, 57 "yes", "no", "no"); 58 if (!yes) 59 return B_CANCELED; 60 61 BEntry repoConfigEntry = repoConfig.Entry(); 62 if ((result = repoConfigEntry.Remove()) != B_OK) 63 return result; 64 65 BRepositoryCache repoCache; 66 if (roster.GetRepositoryCache(fRepositoryName, &repoCache) == B_OK) { 67 BEntry repoCacheEntry = repoCache.Entry(); 68 if ((result = repoCacheEntry.Remove()) != B_OK) 69 return result; 70 } 71 72 return B_OK; 73 } 74 75 76 } // namespace BPrivate 77 78 } // namespace BPackageKit 79