[280] | 1 | |
---|
| 2 | #include "rcacheactor.h" |
---|
| 3 | #include "rpackagelister.h" |
---|
| 4 | #include "i18n.h" |
---|
| 5 | |
---|
| 6 | #include <apt-pkg/error.h> |
---|
| 7 | #include <apt-pkg/tagfile.h> |
---|
| 8 | #include <apt-pkg/strutl.h> |
---|
| 9 | #include <apt-pkg/configuration.h> |
---|
| 10 | #include <algorithm> |
---|
| 11 | #include <fnmatch.h> |
---|
| 12 | |
---|
| 13 | void RCacheActor::notifyCachePostChange() |
---|
| 14 | { |
---|
| 15 | //cout << "RCacheActor::notifyCachePostChange()" << endl; |
---|
| 16 | vector<RPackage *> toKeep; |
---|
| 17 | vector<RPackage *> toInstall; |
---|
| 18 | vector<RPackage *> toReInstall; |
---|
| 19 | vector<RPackage *> toUpgrade; |
---|
| 20 | vector<RPackage *> toRemove; |
---|
| 21 | vector<RPackage *> toDowngrade; |
---|
| 22 | vector<RPackage *> notAuthenticated; |
---|
| 23 | vector<RPackage *> exclude; // empty |
---|
| 24 | |
---|
| 25 | //cout << "_laststate: " << _laststate << endl; |
---|
| 26 | if (_laststate == NULL) |
---|
| 27 | return; |
---|
| 28 | |
---|
| 29 | if (_lister->getStateChanges(*_laststate, toKeep, toInstall, toReInstall, |
---|
| 30 | toUpgrade, toRemove, toDowngrade, |
---|
| 31 | notAuthenticated, |
---|
| 32 | exclude, false)) { |
---|
| 33 | if (toKeep.empty() == false) |
---|
| 34 | run(toKeep, ACTION_KEEP); |
---|
| 35 | if (toInstall.empty() == false) |
---|
| 36 | run(toInstall, ACTION_INSTALL); |
---|
| 37 | if (toReInstall.empty() == false) |
---|
| 38 | run(toReInstall, ACTION_REINSTALL); |
---|
| 39 | if (toUpgrade.empty() == false) |
---|
| 40 | run(toUpgrade, ACTION_INSTALL); |
---|
| 41 | if (toDowngrade.empty() == false) |
---|
| 42 | run(toDowngrade, ACTION_INSTALL); |
---|
| 43 | if (toRemove.empty() == false) |
---|
| 44 | run(toRemove, ACTION_REMOVE); |
---|
| 45 | } |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | RCacheActorRecommends::RCacheActorRecommends(RPackageLister *lister, |
---|
| 53 | string FileName) |
---|
| 54 | : RCacheActor(lister) |
---|
| 55 | { |
---|
| 56 | FileFd F(FileName, FileFd::ReadOnly); |
---|
| 57 | if (_error->PendingError()) { |
---|
| 58 | _error->Error("could not open recommends file %s", FileName.c_str()); |
---|
| 59 | return; |
---|
| 60 | } |
---|
| 61 | pkgTagFile Tags(&F); |
---|
| 62 | pkgTagSection Section; |
---|
| 63 | |
---|
| 64 | string Name; |
---|
| 65 | string Match; |
---|
| 66 | string Recommends; |
---|
| 67 | while (Tags.Step(Section)) { |
---|
| 68 | string Name = Section.FindS("Name"); |
---|
| 69 | string Match = Section.FindS("Match"); |
---|
| 70 | string Recommends = Section.FindS("Recommends"); |
---|
| 71 | if (Name.empty() == true || Recommends.empty() == true) |
---|
| 72 | continue; |
---|
| 73 | |
---|
| 74 | ListType *List = NULL; |
---|
| 75 | if (Match.empty() == true || Match == "exact") { |
---|
| 76 | List = &_map[Name]; |
---|
| 77 | } else if (Match == "wildcard") { |
---|
| 78 | List = &_map_wildcard[Name]; |
---|
| 79 | } else if (Match == "regex") { |
---|
| 80 | regex_t *ptrn = new regex_t; |
---|
| 81 | if (regcomp(ptrn, Name.c_str(), |
---|
| 82 | REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0) { |
---|
| 83 | _error-> |
---|
| 84 | Warning("Bad regular expression '%s' in Recommends file.", |
---|
| 85 | Name.c_str()); |
---|
| 86 | delete ptrn; |
---|
| 87 | } else |
---|
| 88 | List = &_map_regex[ptrn]; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | if (List != NULL) { |
---|
| 92 | const char *C = Recommends.c_str(); |
---|
| 93 | string S; |
---|
| 94 | while (*C != 0) { |
---|
| 95 | if (ParseQuoteWord(C, S)) |
---|
| 96 | List->push_back(S); |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | RCacheActorRecommends::~RCacheActorRecommends() |
---|
| 103 | { |
---|
| 104 | for (RegexMapType::const_iterator RMapI = _map_regex.begin(); |
---|
| 105 | RMapI != _map_regex.end(); RMapI++) { |
---|
| 106 | delete RMapI->first; |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | void RCacheActorRecommends::setLanguageCache() |
---|
| 111 | { |
---|
| 112 | string LangList = _config->Find("Volatile::Languages", ""); |
---|
| 113 | if (LangList == _langLast) |
---|
| 114 | return; |
---|
| 115 | |
---|
| 116 | _langCache.clear(); |
---|
| 117 | |
---|
| 118 | if (LangList.empty()) |
---|
| 119 | return; |
---|
| 120 | |
---|
| 121 | _langLast = LangList; |
---|
| 122 | |
---|
| 123 | const char *C = LangList.c_str(); |
---|
| 124 | string S; |
---|
| 125 | while (*C != 0) { |
---|
| 126 | if (ParseQuoteWord(C, S)) { |
---|
| 127 | string::size_type end; |
---|
| 128 | end = S.find('@'); |
---|
| 129 | if (end != string::npos) |
---|
| 130 | S.erase(end, string::npos); |
---|
| 131 | _langCache.push_back(S); |
---|
| 132 | end = S.rfind('_'); |
---|
| 133 | if (end != string::npos) { |
---|
| 134 | S.erase(end, string::npos); |
---|
| 135 | _langCache.push_back(S); |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | void RCacheActorRecommends::notifyCachePostChange() |
---|
| 142 | { |
---|
| 143 | if (_config->FindB("Synaptic::UseRecommends", true) == true) |
---|
| 144 | RCacheActor::notifyCachePostChange(); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | void RCacheActorRecommends::run(vector<RPackage *> &PkgList, int Action) |
---|
| 148 | { |
---|
| 149 | setLanguageCache(); |
---|
| 150 | const char *name; |
---|
| 151 | const ListType *List; |
---|
| 152 | MapType::const_iterator MapI; |
---|
| 153 | for (vector<RPackage *>::const_iterator PkgI = PkgList.begin(); |
---|
| 154 | PkgI != PkgList.end(); PkgI++) { |
---|
| 155 | name = (*PkgI)->name(); |
---|
| 156 | List = NULL; |
---|
| 157 | MapI = _map.find(name); |
---|
| 158 | if (MapI != _map.end()) { |
---|
| 159 | List = &MapI->second; |
---|
| 160 | } else { |
---|
| 161 | if (_map_wildcard.empty() == false) { |
---|
| 162 | for (MapI = _map_wildcard.begin(); |
---|
| 163 | MapI != _map_wildcard.end(); MapI++) { |
---|
| 164 | if (fnmatch(MapI->first.c_str(), name, 0) == 0) { |
---|
| 165 | List = &MapI->second; |
---|
| 166 | break; |
---|
| 167 | } |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | if (List == NULL && _map_regex.empty() == false) { |
---|
| 171 | for (RegexMapType::const_iterator RMapI = _map_regex.begin(); |
---|
| 172 | RMapI != _map_regex.end(); RMapI++) { |
---|
| 173 | if (regexec(RMapI->first, name, 0, 0, 0) == 0) { |
---|
| 174 | List = &RMapI->second; |
---|
| 175 | break; |
---|
| 176 | } |
---|
| 177 | } |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | if (List != NULL) { |
---|
| 181 | for (ListType::const_iterator ListI = List->begin(); |
---|
| 182 | ListI != List->end(); ListI++) { |
---|
| 183 | const string &Recommends = *ListI; |
---|
| 184 | if (actOnPkg(Recommends, Action) == false |
---|
| 185 | && Recommends.find("$(LANG)") != string::npos) { |
---|
| 186 | for (vector < string >::const_iterator LI = _langCache.begin(); |
---|
| 187 | LI != _langCache.end(); LI++) { |
---|
| 188 | string Parsed = SubstVar(Recommends, "$(LANG)", *LI); |
---|
| 189 | actOnPkg(Parsed, Action); |
---|
| 190 | } |
---|
| 191 | } |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | // vim:sts=3:sw=3 |
---|