[280] | 1 | /* rpackagecache.cc - package cache wrapper |
---|
| 2 | * |
---|
| 3 | * Copyright (c) 2000-2003 Conectiva S/A |
---|
| 4 | * |
---|
| 5 | * Author: Alfredo K. Kojima <kojima@conectiva.com.br> |
---|
| 6 | * |
---|
| 7 | * This program is free software; you can redistribute it and/or |
---|
| 8 | * modify it under the terms of the GNU General Public License as |
---|
| 9 | * published by the Free Software Foundation; either version 2 of the |
---|
| 10 | * License, or (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program; if not, write to the Free Software |
---|
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
---|
| 20 | * USA |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | #include "config.h" |
---|
| 25 | |
---|
| 26 | #include "rpackagecache.h" |
---|
| 27 | #include "rconfiguration.h" |
---|
| 28 | #include "i18n.h" |
---|
| 29 | |
---|
| 30 | #include <assert.h> |
---|
| 31 | #include <algorithm> |
---|
| 32 | #include <apt-pkg/error.h> |
---|
| 33 | #include <apt-pkg/sourcelist.h> |
---|
| 34 | #include <apt-pkg/pkgcachegen.h> |
---|
| 35 | #include <apt-pkg/configuration.h> |
---|
| 36 | #include <apt-pkg/policy.h> |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | bool RPkgPolicy::IsImportantDep(pkgCache::DepIterator dep) |
---|
| 40 | { |
---|
| 41 | if(pkgPolicy::IsImportantDep(dep)) |
---|
| 42 | return true; |
---|
| 43 | |
---|
| 44 | if(dep->Type==pkgCache::Dep::Recommends) { |
---|
| 45 | return _config->FindB("Synaptic::UseRecommends", false); |
---|
| 46 | } else if(dep->Type==pkgCache::Dep::Suggests) { |
---|
| 47 | return _config->FindB("Synaptic::UseSuggests", false); |
---|
| 48 | } else { |
---|
| 49 | return false; |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | bool RPackageCache::open(OpProgress &progress, bool locking) |
---|
| 54 | { |
---|
| 55 | if(locking) |
---|
| 56 | lock(); |
---|
| 57 | |
---|
| 58 | if (_error->PendingError()) |
---|
| 59 | return false; |
---|
| 60 | |
---|
| 61 | // delete any old structures |
---|
| 62 | if(_dcache != NULL) |
---|
| 63 | delete _dcache; |
---|
| 64 | if(_map != NULL) |
---|
| 65 | delete _map; |
---|
| 66 | |
---|
| 67 | // Read the source list |
---|
| 68 | //pkgSourceList list; |
---|
| 69 | assert(_list != NULL); |
---|
| 70 | if (!_list->ReadMainList()) |
---|
| 71 | return _error->Error(_("The list of sources could not be read.\n\ |
---|
| 72 | Go to the repository dialog to correct the problem.")); |
---|
| 73 | |
---|
| 74 | if(locking) |
---|
| 75 | pkgMakeStatusCache(*_list, progress); |
---|
| 76 | else |
---|
| 77 | pkgMakeStatusCache(*_list, progress, 0, true); |
---|
| 78 | |
---|
| 79 | if (_error->PendingError()) |
---|
| 80 | return _error-> |
---|
| 81 | Error(_ |
---|
| 82 | ("The package lists or status file could not be parsed or opened.")); |
---|
| 83 | |
---|
| 84 | // Open the cache file |
---|
| 85 | FileFd File(_config->FindFile("Dir::Cache::pkgcache"), FileFd::ReadOnly); |
---|
| 86 | if (_error->PendingError()) |
---|
| 87 | return false; |
---|
| 88 | |
---|
| 89 | _map = new MMap(File, MMap::Public | MMap::ReadOnly); |
---|
| 90 | if (_error->PendingError()) |
---|
| 91 | return false; |
---|
| 92 | |
---|
| 93 | // Create the dependency cache |
---|
| 94 | _cache = new pkgCache(_map); |
---|
| 95 | if (_error->PendingError()) |
---|
| 96 | return false; |
---|
| 97 | |
---|
| 98 | // The policy engine |
---|
| 99 | if (_policy != NULL) |
---|
| 100 | delete _policy; |
---|
| 101 | _policy = new RPkgPolicy(_cache); |
---|
| 102 | if (_error->PendingError() == true) |
---|
| 103 | return false; |
---|
| 104 | if (ReadPinFile(*_policy) == false) |
---|
| 105 | return false; |
---|
| 106 | |
---|
| 107 | if (ReadPinFile(*_policy, RStateDir() + "/preferences") == false) |
---|
| 108 | return false; |
---|
| 109 | |
---|
| 110 | _dcache = new pkgDepCache(_cache, _policy); |
---|
| 111 | |
---|
| 112 | _dcache->Init(&progress); |
---|
| 113 | |
---|
| 114 | //progress.Done(); |
---|
| 115 | if (_error->PendingError()) |
---|
| 116 | return false; |
---|
| 117 | |
---|
| 118 | // Check that the system is OK |
---|
| 119 | if (_dcache->DelCount() != 0 || _dcache->InstCount() != 0) |
---|
| 120 | return _error->Error(_("Internal Error, non-zero counts")); |
---|
| 121 | |
---|
| 122 | return true; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | vector<string> RPackageCache::getPolicyArchives(bool filenames_only=false) |
---|
| 126 | { |
---|
| 127 | //std::cout << "RPackageCache::getPolicyComponents() " << std::endl; |
---|
| 128 | |
---|
| 129 | vector<string> archives; |
---|
| 130 | for (pkgCache::PkgFileIterator F = _cache->FileBegin(); F.end() == false; |
---|
| 131 | F++) { |
---|
| 132 | pkgIndexFile *Indx; |
---|
| 133 | _list->FindIndex(F, Indx); |
---|
| 134 | _system->FindIndex(F, Indx); |
---|
| 135 | |
---|
| 136 | if(filenames_only) { |
---|
| 137 | if(F.FileName()) |
---|
| 138 | archives.push_back(F.FileName()); |
---|
| 139 | } else { |
---|
| 140 | if (!F.RelStr().empty()) { |
---|
| 141 | //printf("Archive: %s, Origin: %s, Component: %s, Filename: %s\n", |
---|
| 142 | // F.Archive(), F.Origin(), F.Component(), F.FileName()); |
---|
| 143 | if (F.Archive() != NULL) { |
---|
| 144 | if (find(archives.begin(), archives.end(), F.Archive()) |
---|
| 145 | == archives.end()) { |
---|
| 146 | archives.push_back(F.Archive()); |
---|
| 147 | } |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | return archives; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | bool RPackageCache::lock() |
---|
| 157 | { |
---|
| 158 | if (_locked) |
---|
| 159 | return true; |
---|
| 160 | |
---|
| 161 | _system->Lock(); |
---|
| 162 | _locked = true; |
---|
| 163 | |
---|
| 164 | //FIXME: should depend on the result of _system->lock() |
---|
| 165 | return true; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | void RPackageCache::releaseLock() |
---|
| 170 | { |
---|
| 171 | if (!_locked) |
---|
| 172 | return; |
---|
| 173 | |
---|
| 174 | _system->UnLock(); |
---|
| 175 | _locked = false; |
---|
| 176 | } |
---|