]>
Commit | Line | Data |
---|---|---|
5ec427c2 AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
640c5d94 | 3 | // $Id: apt-get.cc,v 1.156 2004/08/28 01:05:16 mdz Exp $ |
5ec427c2 AL |
4 | /* ###################################################################### |
5 | ||
6 | apt-get - Cover for dpkg | |
7 | ||
8 | This is an allout cover for dpkg implementing a safer front end. It is | |
9 | based largely on libapt-pkg. | |
10 | ||
11 | The syntax is different, | |
12 | apt-get [opt] command [things] | |
13 | Where command is: | |
14 | update - Resyncronize the package files from their sources | |
15 | upgrade - Smart-Download the newest versions of all packages | |
16 | dselect-upgrade - Follows dselect's changes to the Status: field | |
17 | and installes new and removes old packages | |
1e3f4083 | 18 | dist-upgrade - Powerful upgrader designed to handle the issues with |
5ec427c2 AL |
19 | a new distribution. |
20 | install - Download and install a given package (by name, not by .deb) | |
21 | check - Update the package cache and check for broken packages | |
22 | clean - Erase the .debs downloaded to /var/cache/apt/archives and | |
23 | the partial dir too | |
24 | ||
25 | ##################################################################### */ | |
26 | /*}}}*/ | |
27 | // Include Files /*{{{*/ | |
ea542140 DK |
28 | #include <config.h> |
29 | ||
453b82a3 DK |
30 | #include <apt-pkg/acquire-item.h> |
31 | #include <apt-pkg/algorithms.h> | |
086bb6d7 | 32 | #include <apt-pkg/aptconfiguration.h> |
453b82a3 DK |
33 | #include <apt-pkg/cachefile.h> |
34 | #include <apt-pkg/cacheset.h> | |
35 | #include <apt-pkg/clean.h> | |
0a8e3465 | 36 | #include <apt-pkg/cmndline.h> |
453b82a3 | 37 | #include <apt-pkg/debmetaindex.h> |
0a8e3465 | 38 | #include <apt-pkg/depcache.h> |
453b82a3 | 39 | #include <apt-pkg/error.h> |
472ff00e | 40 | #include <apt-pkg/fileutl.h> |
453b82a3 | 41 | #include <apt-pkg/indexfile.h> |
453b82a3 | 42 | #include <apt-pkg/init.h> |
092ae175 | 43 | #include <apt-pkg/md5.h> |
453b82a3 | 44 | #include <apt-pkg/metaindex.h> |
472ff00e | 45 | #include <apt-pkg/pkgrecords.h> |
453b82a3 DK |
46 | #include <apt-pkg/pkgsystem.h> |
47 | #include <apt-pkg/progress.h> | |
48 | #include <apt-pkg/sourcelist.h> | |
49 | #include <apt-pkg/srcrecords.h> | |
50 | #include <apt-pkg/strutl.h> | |
51 | #include <apt-pkg/version.h> | |
52 | #include <apt-pkg/acquire.h> | |
53 | #include <apt-pkg/configuration.h> | |
54 | #include <apt-pkg/macros.h> | |
55 | #include <apt-pkg/pkgcache.h> | |
56 | #include <apt-pkg/cacheiterators.h> | |
82e369c4 | 57 | #include <apt-pkg/upgrade.h> |
6cfadda1 | 58 | #include <apt-pkg/sptr.h> |
ffee1c2b | 59 | |
453b82a3 DK |
60 | #include <apt-private/acqprogress.h> |
61 | #include <apt-private/private-cacheset.h> | |
62 | #include <apt-private/private-cachefile.h> | |
63 | #include <apt-private/private-cmndline.h> | |
866893a6 | 64 | #include <apt-private/private-download.h> |
b9179170 | 65 | #include <apt-private/private-install.h> |
453b82a3 DK |
66 | #include <apt-private/private-main.h> |
67 | #include <apt-private/private-moo.h> | |
b9179170 | 68 | #include <apt-private/private-output.h> |
b9179170 | 69 | #include <apt-private/private-update.h> |
453b82a3 | 70 | #include <apt-private/private-upgrade.h> |
cfacba52 | 71 | #include <apt-private/private-utils.h> |
b9179170 | 72 | |
453b82a3 DK |
73 | #include <errno.h> |
74 | #include <signal.h> | |
75 | #include <stddef.h> | |
76 | #include <stdio.h> | |
77 | #include <stdlib.h> | |
78 | #include <string.h> | |
a3f1d60c | 79 | #include <sys/ioctl.h> |
1bc849af | 80 | #include <sys/stat.h> |
453b82a3 | 81 | #include <unistd.h> |
03aa0847 DK |
82 | #include <pwd.h> |
83 | #include <grp.h> | |
84 | ||
453b82a3 DK |
85 | #include <algorithm> |
86 | #include <fstream> | |
87 | #include <iostream> | |
8881b11e | 88 | #include <sstream> |
453b82a3 DK |
89 | #include <set> |
90 | #include <string> | |
91 | #include <vector> | |
5ec427c2 | 92 | |
b9179170 MV |
93 | #include <apti18n.h> |
94 | /*}}}*/ | |
afb1e2e3 | 95 | |
b9179170 | 96 | using namespace std; |
642ebc1a | 97 | |
b8ad5512 | 98 | // TryToInstallBuildDep - Try to install a single package /*{{{*/ |
c373c37a AL |
99 | // --------------------------------------------------------------------- |
100 | /* This used to be inlined in DoInstall, but with the advent of regex package | |
101 | name matching it was split out.. */ | |
c3ccac92 | 102 | static bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache, |
c373c37a | 103 | pkgProblemResolver &Fix,bool Remove,bool BrokenFix, |
70e706ad | 104 | bool AllowFail = true) |
c373c37a | 105 | { |
21d4c9f1 | 106 | if (Cache[Pkg].CandidateVer == 0 && Pkg->ProvidesList != 0) |
c373c37a | 107 | { |
21d4c9f1 | 108 | CacheSetHelperAPTGet helper(c1out); |
4caf8231 | 109 | helper.showErrors(false); |
21d4c9f1 DK |
110 | pkgCache::VerIterator Ver = helper.canNotFindNewestVer(Cache, Pkg); |
111 | if (Ver.end() == false) | |
112 | Pkg = Ver.ParentPkg(); | |
113 | else if (helper.showVirtualPackageErrors(Cache) == false) | |
114 | return AllowFail; | |
c373c37a | 115 | } |
61d6a8de | 116 | |
ac321486 DK |
117 | if (_config->FindB("Debug::BuildDeps",false) == true) |
118 | { | |
119 | if (Remove == true) | |
120 | cout << " Trying to remove " << Pkg << endl; | |
121 | else | |
122 | cout << " Trying to install " << Pkg << endl; | |
123 | } | |
124 | ||
c373c37a AL |
125 | if (Remove == true) |
126 | { | |
71d73928 | 127 | TryToRemove RemoveAction(Cache, &Fix); |
21d4c9f1 DK |
128 | RemoveAction(Pkg.VersionList()); |
129 | } else if (Cache[Pkg].CandidateVer != 0) { | |
71d73928 | 130 | TryToInstall InstallAction(Cache, &Fix, BrokenFix); |
21d4c9f1 | 131 | InstallAction(Cache[Pkg].CandidateVerIter(Cache)); |
6806db8a | 132 | InstallAction.doAutoInstall(); |
21d4c9f1 DK |
133 | } else |
134 | return AllowFail; | |
60681f93 | 135 | |
b2e465d6 AL |
136 | return true; |
137 | } | |
138 | /*}}}*/ | |
5ad0096a DK |
139 | // GetReleaseFileForSourceRecord - Return Suite for the given srcrecord /*{{{*/ |
140 | static pkgCache::RlsFileIterator GetReleaseFileForSourceRecord(CacheFile &CacheFile, | |
141 | pkgSourceList *SrcList, pkgSrcRecords::Parser *Parse) | |
7014e148 MV |
142 | { |
143 | // try to find release | |
144 | const pkgIndexFile& CurrentIndexFile = Parse->Index(); | |
145 | ||
146 | for (pkgSourceList::const_iterator S = SrcList->begin(); | |
147 | S != SrcList->end(); ++S) | |
148 | { | |
149 | vector<pkgIndexFile *> *Indexes = (*S)->GetIndexFiles(); | |
150 | for (vector<pkgIndexFile *>::const_iterator IF = Indexes->begin(); | |
151 | IF != Indexes->end(); ++IF) | |
152 | { | |
153 | if (&CurrentIndexFile == (*IF)) | |
5ad0096a | 154 | return (*S)->FindInCache(CacheFile, false); |
7014e148 MV |
155 | } |
156 | } | |
5ad0096a | 157 | return pkgCache::RlsFileIterator(CacheFile); |
7014e148 MV |
158 | } |
159 | /*}}}*/ | |
b2e465d6 AL |
160 | // FindSrc - Find a source record /*{{{*/ |
161 | // --------------------------------------------------------------------- | |
162 | /* */ | |
a221efc3 | 163 | static pkgSrcRecords::Parser *FindSrc(const char *Name, |
b2e465d6 | 164 | pkgSrcRecords &SrcRecs,string &Src, |
7014e148 | 165 | CacheFile &CacheFile) |
b2e465d6 | 166 | { |
adf379e7 MV |
167 | string VerTag, UserRequestedVerTag; |
168 | string ArchTag = ""; | |
7014e148 | 169 | string RelTag = _config->Find("APT::Default-Release"); |
b2e465d6 | 170 | string TmpSrc = Name; |
7014e148 | 171 | pkgDepCache *Cache = CacheFile.GetDepCache(); |
aca056a9 | 172 | |
adf379e7 MV |
173 | // extract release |
174 | size_t found = TmpSrc.find_last_of("/"); | |
175 | if (found != string::npos) | |
176 | { | |
177 | RelTag = TmpSrc.substr(found+1); | |
178 | TmpSrc = TmpSrc.substr(0,found); | |
179 | } | |
180 | // extract the version | |
181 | found = TmpSrc.find_last_of("="); | |
182 | if (found != string::npos) | |
183 | { | |
184 | VerTag = UserRequestedVerTag = TmpSrc.substr(found+1); | |
185 | TmpSrc = TmpSrc.substr(0,found); | |
186 | } | |
187 | // extract arch | |
188 | found = TmpSrc.find_last_of(":"); | |
189 | if (found != string::npos) | |
190 | { | |
191 | ArchTag = TmpSrc.substr(found+1); | |
ebf6c42d DK |
192 | TmpSrc = TmpSrc.substr(0,found); |
193 | } | |
aca056a9 | 194 | |
fb3dc579 MV |
195 | /* Lookup the version of the package we would install if we were to |
196 | install a version and determine the source package name, then look | |
197 | in the archive for a source package of the same name. */ | |
198 | bool MatchSrcOnly = _config->FindB("APT::Get::Only-Source"); | |
adf379e7 MV |
199 | pkgCache::PkgIterator Pkg; |
200 | if (ArchTag != "") | |
201 | Pkg = Cache->FindPkg(TmpSrc, ArchTag); | |
202 | else | |
203 | Pkg = Cache->FindPkg(TmpSrc); | |
204 | ||
205 | // if we can't find a package but the user qualified with a arch, | |
206 | // error out here | |
207 | if (Pkg.end() && ArchTag != "") | |
208 | { | |
209 | Src = Name; | |
210 | _error->Error(_("Can not find a package for architecture '%s'"), | |
211 | ArchTag.c_str()); | |
212 | return 0; | |
213 | } | |
214 | ||
fb3dc579 | 215 | if (MatchSrcOnly == false && Pkg.end() == false) |
aca056a9 | 216 | { |
adf379e7 | 217 | if(VerTag != "" || RelTag != "" || ArchTag != "") |
aca056a9 | 218 | { |
e84adb76 | 219 | bool fuzzy = false; |
fb3dc579 MV |
220 | // we have a default release, try to locate the pkg. we do it like |
221 | // this because GetCandidateVer() will not "downgrade", that means | |
222 | // "apt-get source -t stable apt" won't work on a unstable system | |
f7f0d6c7 | 223 | for (pkgCache::VerIterator Ver = Pkg.VersionList();; ++Ver) |
aca056a9 | 224 | { |
e84adb76 DK |
225 | // try first only exact matches, later fuzzy matches |
226 | if (Ver.end() == true) | |
227 | { | |
228 | if (fuzzy == true) | |
229 | break; | |
230 | fuzzy = true; | |
231 | Ver = Pkg.VersionList(); | |
259f688a MV |
232 | // exit right away from the Pkg.VersionList() loop if we |
233 | // don't have any versions | |
234 | if (Ver.end() == true) | |
235 | break; | |
e84adb76 | 236 | } |
adf379e7 | 237 | |
37f45a57 MV |
238 | // ignore arches that are not for us |
239 | if (ArchTag != "" && Ver.Arch() != ArchTag) | |
240 | continue; | |
241 | ||
adf379e7 MV |
242 | // pick highest version for the arch unless the user wants |
243 | // something else | |
244 | if (ArchTag != "" && VerTag == "" && RelTag == "") | |
adf379e7 MV |
245 | if(Cache->VS().CmpVersion(VerTag, Ver.VerStr()) < 0) |
246 | VerTag = Ver.VerStr(); | |
adf379e7 | 247 | |
e84adb76 DK |
248 | // We match against a concrete version (or a part of this version) |
249 | if (VerTag.empty() == false && | |
7014e148 | 250 | (fuzzy == true || Cache->VS().CmpVersion(VerTag, Ver.VerStr()) != 0) && // exact match |
e84adb76 DK |
251 | (fuzzy == false || strncmp(VerTag.c_str(), Ver.VerStr(), VerTag.size()) != 0)) // fuzzy match |
252 | continue; | |
253 | ||
fb3dc579 | 254 | for (pkgCache::VerFileIterator VF = Ver.FileList(); |
f7f0d6c7 | 255 | VF.end() == false; ++VF) |
aca056a9 | 256 | { |
fb3dc579 MV |
257 | /* If this is the status file, and the current version is not the |
258 | version in the status file (ie it is not installed, or somesuch) | |
259 | then it is not a candidate for installation, ever. This weeds | |
260 | out bogus entries that may be due to config-file states, or | |
261 | other. */ | |
262 | if ((VF.File()->Flags & pkgCache::Flag::NotSource) == | |
263 | pkgCache::Flag::NotSource && Pkg.CurrentVer() != Ver) | |
264 | continue; | |
265 | ||
fb3dc579 MV |
266 | // or we match against a release |
267 | if(VerTag.empty() == false || | |
7014e148 MV |
268 | (VF.File().Archive() != 0 && VF.File().Archive() == RelTag) || |
269 | (VF.File().Codename() != 0 && VF.File().Codename() == RelTag)) | |
fb3dc579 | 270 | { |
e84adb76 | 271 | // the Version we have is possibly fuzzy or includes binUploads, |
765190e4 | 272 | // so we use the Version of the SourcePkg (empty if same as package) |
765190e4 | 273 | Src = Ver.SourcePkgName(); |
a221efc3 | 274 | VerTag = Ver.SourceVerStr(); |
fb3dc579 MV |
275 | break; |
276 | } | |
aca056a9 | 277 | } |
61690a7e MV |
278 | if (Src.empty() == false) |
279 | break; | |
aca056a9 | 280 | } |
026f60e2 | 281 | } |
adf379e7 | 282 | |
37f45a57 MV |
283 | if (Src == "" && ArchTag != "") |
284 | { | |
c9829e07 MV |
285 | if (VerTag != "") |
286 | _error->Error(_("Can not find a package '%s' with version '%s'"), | |
287 | Pkg.FullName().c_str(), VerTag.c_str()); | |
288 | if (RelTag != "") | |
289 | _error->Error(_("Can not find a package '%s' with release '%s'"), | |
290 | Pkg.FullName().c_str(), RelTag.c_str()); | |
37f45a57 MV |
291 | Src = Name; |
292 | return 0; | |
293 | } | |
294 | ||
295 | ||
61690a7e | 296 | if (Src.empty() == true) |
b2e465d6 | 297 | { |
61690a7e MV |
298 | // if we don't have found a fitting package yet so we will |
299 | // choose a good candidate and proceed with that. | |
300 | // Maybe we will find a source later on with the right VerTag | |
7014e148 MV |
301 | // or RelTag |
302 | pkgCache::VerIterator Ver = Cache->GetCandidateVer(Pkg); | |
fb3dc579 | 303 | if (Ver.end() == false) |
b2e465d6 | 304 | { |
a221efc3 DK |
305 | if (strcmp(Ver.SourcePkgName(),Ver.ParentPkg().Name()) != 0) |
306 | Src = Ver.SourcePkgName(); | |
307 | if (VerTag.empty() == true && strcmp(Ver.SourceVerStr(),Ver.VerStr()) != 0) | |
308 | VerTag = Ver.SourceVerStr(); | |
b2e465d6 | 309 | } |
fb3dc579 MV |
310 | } |
311 | } | |
312 | ||
313 | if (Src.empty() == true) | |
7014e148 | 314 | { |
fb3dc579 | 315 | Src = TmpSrc; |
7014e148 | 316 | } |
fb3dc579 MV |
317 | else |
318 | { | |
319 | /* if we have a source pkg name, make sure to only search | |
320 | for srcpkg names, otherwise apt gets confused if there | |
321 | is a binary package "pkg1" and a source package "pkg1" | |
322 | with the same name but that comes from different packages */ | |
323 | MatchSrcOnly = true; | |
324 | if (Src != TmpSrc) | |
325 | { | |
326 | ioprintf(c1out, _("Picking '%s' as source package instead of '%s'\n"), Src.c_str(), TmpSrc.c_str()); | |
327 | } | |
b2e465d6 | 328 | } |
89ad8e7c | 329 | |
b2e465d6 AL |
330 | // The best hit |
331 | pkgSrcRecords::Parser *Last = 0; | |
332 | unsigned long Offset = 0; | |
333 | string Version; | |
7014e148 | 334 | pkgSourceList *SrcList = CacheFile.GetSourceList(); |
89ad8e7c | 335 | |
b2e465d6 AL |
336 | /* Iterate over all of the hits, which includes the resulting |
337 | binary packages in the search */ | |
338 | pkgSrcRecords::Parser *Parse; | |
fb3dc579 | 339 | while (true) |
b2e465d6 | 340 | { |
fb3dc579 MV |
341 | SrcRecs.Restart(); |
342 | while ((Parse = SrcRecs.Find(Src.c_str(), MatchSrcOnly)) != 0) | |
b2e465d6 | 343 | { |
fb3dc579 MV |
344 | const string Ver = Parse->Version(); |
345 | ||
7014e148 | 346 | // See if we need to look for a specific release tag |
65dcff55 | 347 | if (RelTag != "" && UserRequestedVerTag == "") |
7014e148 | 348 | { |
5ad0096a DK |
349 | pkgCache::RlsFileIterator const Rls = GetReleaseFileForSourceRecord(CacheFile, SrcList, Parse); |
350 | if (Rls.end() == false) | |
7014e148 | 351 | { |
5ad0096a DK |
352 | if ((Rls->Archive != 0 && RelTag == Rls.Archive()) || |
353 | (Rls->Codename != 0 && RelTag == Rls.Codename())) | |
354 | { | |
355 | Last = Parse; | |
356 | Offset = Parse->Offset(); | |
357 | Version = Ver; | |
358 | } | |
7014e148 MV |
359 | } |
360 | } | |
361 | ||
fb3dc579 | 362 | // Ignore all versions which doesn't fit |
e84adb76 | 363 | if (VerTag.empty() == false && |
7014e148 | 364 | Cache->VS().CmpVersion(VerTag, Ver) != 0) // exact match |
b2e465d6 | 365 | continue; |
fb3dc579 MV |
366 | |
367 | // Newer version or an exact match? Save the hit | |
7014e148 | 368 | if (Last == 0 || Cache->VS().CmpVersion(Version,Ver) < 0) { |
fb3dc579 MV |
369 | Last = Parse; |
370 | Offset = Parse->Offset(); | |
371 | Version = Ver; | |
372 | } | |
373 | ||
7014e148 MV |
374 | // was the version check above an exact match? |
375 | // If so, we don't need to look further | |
376 | if (VerTag.empty() == false && (VerTag == Ver)) | |
fb3dc579 | 377 | break; |
b2e465d6 | 378 | } |
65dcff55 | 379 | if (UserRequestedVerTag == "" && Version != "" && RelTag != "") |
bfa7bfc8 | 380 | ioprintf(c1out, "Selected version '%s' (%s) for %s\n", |
651ae5ce MV |
381 | Version.c_str(), RelTag.c_str(), Src.c_str()); |
382 | ||
fb3dc579 MV |
383 | if (Last != 0 || VerTag.empty() == true) |
384 | break; | |
017d3f3b | 385 | _error->Error(_("Can not find version '%s' of package '%s'"), VerTag.c_str(), TmpSrc.c_str()); |
ddff663f | 386 | return 0; |
b2e465d6 | 387 | } |
fb3dc579 | 388 | |
ce6162be | 389 | if (Last == 0 || Last->Jump(Offset) == false) |
b2e465d6 | 390 | return 0; |
fb3dc579 | 391 | |
b2e465d6 AL |
392 | return Last; |
393 | } | |
394 | /*}}}*/ | |
182a6a55 | 395 | /* mark packages as automatically/manually installed. {{{*/ |
c3ccac92 | 396 | static bool DoMarkAuto(CommandLine &CmdL) |
d63a1458 JAK |
397 | { |
398 | bool Action = true; | |
399 | int AutoMarkChanged = 0; | |
400 | OpTextProgress progress; | |
401 | CacheFile Cache; | |
402 | if (Cache.Open() == false) | |
403 | return false; | |
404 | ||
405 | if (strcasecmp(CmdL.FileList[0],"markauto") == 0) | |
406 | Action = true; | |
407 | else if (strcasecmp(CmdL.FileList[0],"unmarkauto") == 0) | |
408 | Action = false; | |
409 | ||
410 | for (const char **I = CmdL.FileList + 1; *I != 0; I++) | |
411 | { | |
412 | const char *S = *I; | |
413 | // Locate the package | |
414 | pkgCache::PkgIterator Pkg = Cache->FindPkg(S); | |
415 | if (Pkg.end() == true) { | |
416 | return _error->Error(_("Couldn't find package %s"),S); | |
417 | } | |
418 | else | |
419 | { | |
420 | if (!Action) | |
421 | ioprintf(c1out,_("%s set to manually installed.\n"), Pkg.Name()); | |
422 | else | |
423 | ioprintf(c1out,_("%s set to automatically installed.\n"), | |
424 | Pkg.Name()); | |
425 | ||
426 | Cache->MarkAuto(Pkg,Action); | |
427 | AutoMarkChanged++; | |
428 | } | |
429 | } | |
182a6a55 DK |
430 | |
431 | _error->Notice(_("This command is deprecated. Please use 'apt-mark auto' and 'apt-mark manual' instead.")); | |
432 | ||
d63a1458 JAK |
433 | if (AutoMarkChanged && ! _config->FindB("APT::Get::Simulate",false)) |
434 | return Cache->writeStateFile(NULL); | |
435 | return false; | |
436 | } | |
0a8e3465 | 437 | /*}}}*/ |
0a8e3465 AL |
438 | // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/ |
439 | // --------------------------------------------------------------------- | |
440 | /* Follows dselect's selections */ | |
65512241 | 441 | static bool DoDSelectUpgrade(CommandLine &) |
0a8e3465 AL |
442 | { |
443 | CacheFile Cache; | |
c37b9502 | 444 | if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false) |
0a8e3465 AL |
445 | return false; |
446 | ||
a4decc40 MV |
447 | pkgDepCache::ActionGroup group(Cache); |
448 | ||
0a8e3465 AL |
449 | // Install everything with the install flag set |
450 | pkgCache::PkgIterator I = Cache->PkgBegin(); | |
f7f0d6c7 | 451 | for (;I.end() != true; ++I) |
0a8e3465 AL |
452 | { |
453 | /* Install the package only if it is a new install, the autoupgrader | |
454 | will deal with the rest */ | |
455 | if (I->SelectedState == pkgCache::State::Install) | |
456 | Cache->MarkInstall(I,false); | |
457 | } | |
458 | ||
459 | /* Now install their deps too, if we do this above then order of | |
460 | the status file is significant for | groups */ | |
f7f0d6c7 | 461 | for (I = Cache->PkgBegin();I.end() != true; ++I) |
0a8e3465 AL |
462 | { |
463 | /* Install the package only if it is a new install, the autoupgrader | |
464 | will deal with the rest */ | |
465 | if (I->SelectedState == pkgCache::State::Install) | |
2f45c76a | 466 | Cache->MarkInstall(I,true); |
0a8e3465 AL |
467 | } |
468 | ||
469 | // Apply erasures now, they override everything else. | |
f7f0d6c7 | 470 | for (I = Cache->PkgBegin();I.end() != true; ++I) |
0a8e3465 AL |
471 | { |
472 | // Remove packages | |
473 | if (I->SelectedState == pkgCache::State::DeInstall || | |
474 | I->SelectedState == pkgCache::State::Purge) | |
d556d1a1 | 475 | Cache->MarkDelete(I,I->SelectedState == pkgCache::State::Purge); |
0a8e3465 AL |
476 | } |
477 | ||
2f45c76a | 478 | /* Resolve any problems that dselect created, allupgrade cannot handle |
1e3f4083 | 479 | such things. We do so quite aggressively too.. */ |
2f45c76a AL |
480 | if (Cache->BrokenCount() != 0) |
481 | { | |
482 | pkgProblemResolver Fix(Cache); | |
483 | ||
484 | // Hold back held packages. | |
b2e465d6 | 485 | if (_config->FindB("APT::Ignore-Hold",false) == false) |
2f45c76a | 486 | { |
f7f0d6c7 | 487 | for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() == false; ++I) |
2f45c76a AL |
488 | { |
489 | if (I->SelectedState == pkgCache::State::Hold) | |
490 | { | |
491 | Fix.Protect(I); | |
492 | Cache->MarkKeep(I); | |
493 | } | |
494 | } | |
495 | } | |
496 | ||
497 | if (Fix.Resolve() == false) | |
498 | { | |
421c8d10 | 499 | ShowBroken(c1out,Cache,false); |
2a7e07c7 | 500 | return _error->Error(_("Internal error, problem resolver broke stuff")); |
2f45c76a AL |
501 | } |
502 | } | |
503 | ||
504 | // Now upgrade everything | |
67caa2e6 | 505 | if (APT::Upgrade::Upgrade(Cache, APT::Upgrade::FORBID_REMOVE_PACKAGES | APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES) == false) |
0a8e3465 | 506 | { |
421c8d10 | 507 | ShowBroken(c1out,Cache,false); |
2a7e07c7 | 508 | return _error->Error(_("Internal error, problem resolver broke stuff")); |
0a8e3465 AL |
509 | } |
510 | ||
511 | return InstallPackages(Cache,false); | |
512 | } | |
513 | /*}}}*/ | |
514 | // DoClean - Remove download archives /*{{{*/ | |
515 | // --------------------------------------------------------------------- | |
516 | /* */ | |
65512241 | 517 | static bool DoClean(CommandLine &) |
0a8e3465 | 518 | { |
657ecd4a | 519 | std::string const archivedir = _config->FindDir("Dir::Cache::archives"); |
20e6965a | 520 | std::string const listsdir = _config->FindDir("Dir::state::lists"); |
657ecd4a | 521 | |
8b067c22 AL |
522 | if (_config->FindB("APT::Get::Simulate") == true) |
523 | { | |
20e6965a DK |
524 | std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache"); |
525 | std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache"); | |
657ecd4a | 526 | cout << "Del " << archivedir << "* " << archivedir << "partial/*"<< endl |
20e6965a | 527 | << "Del " << listsdir << "partial/*" << endl |
657ecd4a | 528 | << "Del " << pkgcache << " " << srcpkgcache << endl; |
8b067c22 AL |
529 | return true; |
530 | } | |
20e6965a | 531 | |
7a1b1f8b | 532 | pkgAcquire Fetcher; |
7e04a6bf | 533 | Fetcher.GetLock(archivedir); |
657ecd4a DK |
534 | Fetcher.Clean(archivedir); |
535 | Fetcher.Clean(archivedir + "partial/"); | |
536 | ||
7e04a6bf | 537 | Fetcher.GetLock(listsdir); |
20e6965a DK |
538 | Fetcher.Clean(listsdir + "partial/"); |
539 | ||
8de79b68 | 540 | pkgCacheFile::RemoveCaches(); |
657ecd4a | 541 | |
0a8e3465 AL |
542 | return true; |
543 | } | |
544 | /*}}}*/ | |
1bc849af AL |
545 | // DoAutoClean - Smartly remove downloaded archives /*{{{*/ |
546 | // --------------------------------------------------------------------- | |
547 | /* This is similar to clean but it only purges things that cannot be | |
548 | downloaded, that is old versions of cached packages. */ | |
65a1e968 AL |
549 | class LogCleaner : public pkgArchiveCleaner |
550 | { | |
551 | protected: | |
3b302846 | 552 | virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St) APT_OVERRIDE |
65a1e968 | 553 | { |
4cc8bab0 | 554 | c1out << "Del " << Pkg << " " << Ver << " [" << SizeToStr(St.st_size) << "B]" << endl; |
c1e78ee5 AL |
555 | |
556 | if (_config->FindB("APT::Get::Simulate") == false) | |
557 | unlink(File); | |
65a1e968 AL |
558 | }; |
559 | }; | |
560 | ||
65512241 | 561 | static bool DoAutoClean(CommandLine &) |
1bc849af | 562 | { |
1b6d659c AL |
563 | // Lock the archive directory |
564 | FileFd Lock; | |
565 | if (_config->FindB("Debug::NoLocking",false) == false) | |
566 | { | |
de24f8ce MV |
567 | int lock_fd = GetLock(_config->FindDir("Dir::Cache::Archives") + "lock"); |
568 | if (lock_fd < 0) | |
b2e465d6 | 569 | return _error->Error(_("Unable to lock the download directory")); |
de24f8ce | 570 | Lock.Fd(lock_fd); |
1b6d659c AL |
571 | } |
572 | ||
1bc849af | 573 | CacheFile Cache; |
2d11135a | 574 | if (Cache.Open() == false) |
1bc849af AL |
575 | return false; |
576 | ||
65a1e968 | 577 | LogCleaner Cleaner; |
1bc849af AL |
578 | |
579 | return Cleaner.Go(_config->FindDir("Dir::Cache::archives"),*Cache) && | |
580 | Cleaner.Go(_config->FindDir("Dir::Cache::archives") + "partial/",*Cache); | |
581 | } | |
582 | /*}}}*/ | |
0e3e112e MV |
583 | // DoDownload - download a binary /*{{{*/ |
584 | // --------------------------------------------------------------------- | |
c3ccac92 | 585 | static bool DoDownload(CommandLine &CmdL) |
0e3e112e MV |
586 | { |
587 | CacheFile Cache; | |
588 | if (Cache.ReadOnlyOpen() == false) | |
589 | return false; | |
d57f6084 | 590 | |
353c135e | 591 | APT::CacheSetHelper helper; |
8f3594c3 | 592 | APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache, |
43acd019 | 593 | CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper); |
0e3e112e MV |
594 | |
595 | if (verset.empty() == true) | |
596 | return false; | |
597 | ||
0e3e112e MV |
598 | pkgRecords Recs(Cache); |
599 | pkgSourceList *SrcList = Cache.GetSourceList(); | |
567785b9 | 600 | |
d57f6084 DK |
601 | // reuse the usual acquire methods for deb files, but don't drop them into |
602 | // the usual directories - keep everything in the current directory | |
2b0660b5 | 603 | aptAcquireWithTextStatus Fetcher; |
d57f6084 DK |
604 | std::vector<std::string> storefile(verset.size()); |
605 | std::string const cwd = SafeGetCWD(); | |
606 | _config->Set("Dir::Cache::Archives", cwd); | |
607 | int i = 0; | |
8f3594c3 | 608 | for (APT::VersionSet::const_iterator Ver = verset.begin(); |
d57f6084 | 609 | Ver != verset.end(); ++Ver, ++i) |
0e3e112e | 610 | { |
d57f6084 | 611 | pkgAcquire::Item *I = new pkgAcqArchive(&Fetcher, SrcList, &Recs, *Ver, storefile[i]); |
03aa0847 DK |
612 | if (storefile[i].empty()) |
613 | continue; | |
d57f6084 DK |
614 | std::string const filename = cwd + flNotDir(storefile[i]); |
615 | storefile[i].assign(filename); | |
616 | I->DestFile.assign(filename); | |
0e3e112e MV |
617 | } |
618 | ||
42d41ddb DK |
619 | // Just print out the uris and exit if the --print-uris flag was used |
620 | if (_config->FindB("APT::Get::Print-URIs") == true) | |
621 | { | |
622 | pkgAcquire::UriIterator I = Fetcher.UriBegin(); | |
f7f0d6c7 | 623 | for (; I != Fetcher.UriEnd(); ++I) |
b0f4b486 | 624 | cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << |
42d41ddb DK |
625 | I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl; |
626 | return true; | |
627 | } | |
628 | ||
d57f6084 DK |
629 | if (_error->PendingError() == true || CheckAuth(Fetcher, false) == false) |
630 | return false; | |
631 | ||
632 | bool Failed = false; | |
633 | if (AcquireRun(Fetcher, 0, &Failed, NULL) == false) | |
634 | return false; | |
635 | ||
636 | // copy files in local sources to the current directory | |
637 | for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I) | |
6ae22905 MV |
638 | { |
639 | std::string const filename = cwd + flNotDir((*I)->DestFile); | |
640 | if ((*I)->Local == true && | |
641 | filename != (*I)->DestFile && | |
642 | (*I)->Status == pkgAcquire::Item::StatDone) | |
d57f6084 | 643 | { |
d57f6084 DK |
644 | std::ifstream src((*I)->DestFile.c_str(), std::ios::binary); |
645 | std::ofstream dst(filename.c_str(), std::ios::binary); | |
646 | dst << src.rdbuf(); | |
647 | } | |
6ae22905 | 648 | } |
d57f6084 | 649 | return Failed == false; |
0e3e112e MV |
650 | } |
651 | /*}}}*/ | |
0a8e3465 AL |
652 | // DoCheck - Perform the check operation /*{{{*/ |
653 | // --------------------------------------------------------------------- | |
654 | /* Opening automatically checks the system, this command is mostly used | |
655 | for debugging */ | |
65512241 | 656 | static bool DoCheck(CommandLine &) |
0a8e3465 AL |
657 | { |
658 | CacheFile Cache; | |
659 | Cache.Open(); | |
2d11135a | 660 | Cache.CheckDeps(); |
0a8e3465 AL |
661 | |
662 | return true; | |
663 | } | |
664 | /*}}}*/ | |
36375005 AL |
665 | // DoSource - Fetch a source archive /*{{{*/ |
666 | // --------------------------------------------------------------------- | |
2d11135a | 667 | /* Fetch souce packages */ |
fb0ee66e AL |
668 | struct DscFile |
669 | { | |
670 | string Package; | |
671 | string Version; | |
672 | string Dsc; | |
673 | }; | |
674 | ||
c3ccac92 | 675 | static bool DoSource(CommandLine &CmdL) |
36375005 AL |
676 | { |
677 | CacheFile Cache; | |
2d11135a | 678 | if (Cache.Open(false) == false) |
36375005 AL |
679 | return false; |
680 | ||
2d11135a | 681 | if (CmdL.FileSize() <= 1) |
b2e465d6 | 682 | return _error->Error(_("Must specify at least one package to fetch source for")); |
2d11135a | 683 | |
36375005 | 684 | // Read the source list |
1bb8cd67 DK |
685 | if (Cache.BuildSourceList() == false) |
686 | return false; | |
687 | pkgSourceList *List = Cache.GetSourceList(); | |
36375005 AL |
688 | |
689 | // Create the text record parsers | |
1bb8cd67 | 690 | pkgSrcRecords SrcRecs(*List); |
36375005 AL |
691 | if (_error->PendingError() == true) |
692 | return false; | |
693 | ||
98cc7fd2 | 694 | std::unique_ptr<DscFile[]> Dsc(new DscFile[CmdL.FileSize()]); |
36375005 | 695 | |
092ae175 MV |
696 | // insert all downloaded uris into this set to avoid downloading them |
697 | // twice | |
698 | set<string> queued; | |
8545b536 DK |
699 | |
700 | // Diff only mode only fetches .diff files | |
701 | bool const diffOnly = _config->FindB("APT::Get::Diff-Only", false); | |
702 | // Tar only mode only fetches .tar files | |
703 | bool const tarOnly = _config->FindB("APT::Get::Tar-Only", false); | |
704 | // Dsc only mode only fetches .dsc files | |
705 | bool const dscOnly = _config->FindB("APT::Get::Dsc-Only", false); | |
706 | ||
36375005 | 707 | // Load the requestd sources into the fetcher |
2b0660b5 | 708 | aptAcquireWithTextStatus Fetcher; |
fb0ee66e | 709 | unsigned J = 0; |
9112f777 | 710 | std::vector<std::string> UntrustedList; |
fb0ee66e | 711 | for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++) |
36375005 AL |
712 | { |
713 | string Src; | |
a221efc3 | 714 | pkgSrcRecords::Parser *Last = FindSrc(*I,SrcRecs,Src,Cache); |
6070a346 | 715 | if (Last == 0) { |
b2e465d6 | 716 | return _error->Error(_("Unable to find a source package for %s"),Src.c_str()); |
6070a346 | 717 | } |
a3f1d60c MV |
718 | |
719 | if (Last->Index().IsTrusted() == false) | |
9112f777 DK |
720 | UntrustedList.push_back(Src); |
721 | ||
3238423f MV |
722 | string srec = Last->AsStr(); |
723 | string::size_type pos = srec.find("\nVcs-"); | |
774a6687 | 724 | while (pos != string::npos) |
3238423f MV |
725 | { |
726 | pos += strlen("\nVcs-"); | |
727 | string vcs = srec.substr(pos,srec.find(":",pos)-pos); | |
774a6687 MV |
728 | if(vcs == "Browser") |
729 | { | |
730 | pos = srec.find("\nVcs-", pos); | |
731 | continue; | |
732 | } | |
3238423f MV |
733 | pos += vcs.length()+2; |
734 | string::size_type epos = srec.find("\n", pos); | |
7c4f1ca5 | 735 | string const uri = srec.substr(pos,epos-pos); |
b799e134 | 736 | ioprintf(c1out, _("NOTICE: '%s' packaging is maintained in " |
3238423f | 737 | "the '%s' version control system at:\n" |
8756297c | 738 | "%s\n"), |
3238423f | 739 | Src.c_str(), vcs.c_str(), uri.c_str()); |
7c4f1ca5 DK |
740 | std::string vcscmd; |
741 | if (vcs == "Bzr") | |
742 | vcscmd = "bzr branch " + uri; | |
743 | else if (vcs == "Git") | |
744 | vcscmd = "git clone " + uri; | |
745 | ||
746 | if (vcscmd.empty() == false) | |
747 | ioprintf(c1out,_("Please use:\n%s\n" | |
748 | "to retrieve the latest (possibly unreleased) " | |
749 | "updates to the package.\n"), | |
750 | vcscmd.c_str()); | |
b799e134 | 751 | break; |
3238423f MV |
752 | } |
753 | ||
36375005 | 754 | // Back track |
3a2b39ee DK |
755 | vector<pkgSrcRecords::File2> Lst; |
756 | if (Last->Files2(Lst) == false) { | |
36375005 | 757 | return false; |
6070a346 | 758 | } |
36375005 AL |
759 | |
760 | // Load them into the fetcher | |
3a2b39ee | 761 | for (vector<pkgSrcRecords::File2>::const_iterator I = Lst.begin(); |
f7f0d6c7 | 762 | I != Lst.end(); ++I) |
36375005 AL |
763 | { |
764 | // Try to guess what sort of file it is we are getting. | |
b2e465d6 | 765 | if (I->Type == "dsc") |
fb0ee66e | 766 | { |
fb0ee66e AL |
767 | Dsc[J].Package = Last->Package(); |
768 | Dsc[J].Version = Last->Version(); | |
769 | Dsc[J].Dsc = flNotDir(I->Path); | |
770 | } | |
092ae175 | 771 | |
8545b536 DK |
772 | // Handle the only options so that multiple can be used at once |
773 | if (diffOnly == true || tarOnly == true || dscOnly == true) | |
774 | { | |
775 | if ((diffOnly == true && I->Type == "diff") || | |
776 | (tarOnly == true && I->Type == "tar") || | |
777 | (dscOnly == true && I->Type == "dsc")) | |
778 | ; // Fine, we want this file downloaded | |
779 | else | |
780 | continue; | |
781 | } | |
1979e742 | 782 | |
092ae175 MV |
783 | // don't download the same uri twice (should this be moved to |
784 | // the fetcher interface itself?) | |
785 | if(queued.find(Last->Index().ArchiveURI(I->Path)) != queued.end()) | |
786 | continue; | |
787 | queued.insert(Last->Index().ArchiveURI(I->Path)); | |
cb6a2b3e | 788 | |
092ae175 | 789 | // check if we have a file with that md5 sum already localy |
1262d358 DK |
790 | std::string localFile = flNotDir(I->Path); |
791 | if (FileExists(localFile) == true) | |
792 | if(I->Hashes.VerifyFile(localFile) == true) | |
092ae175 | 793 | { |
443cb67c | 794 | ioprintf(c1out,_("Skipping already downloaded file '%s'\n"), |
1262d358 | 795 | localFile.c_str()); |
092ae175 MV |
796 | continue; |
797 | } | |
1262d358 DK |
798 | |
799 | // see if we have a hash (Acquire::ForceHash is the only way to have none) | |
b3501edb | 800 | if (I->Hashes.usable() == false && _config->FindB("APT::Get::AllowUnauthenticated",false) == false) |
1262d358 DK |
801 | { |
802 | ioprintf(c1out, "Skipping download of file '%s' as requested hashsum is not available for authentication\n", | |
803 | localFile.c_str()); | |
804 | continue; | |
092ae175 MV |
805 | } |
806 | ||
b2e465d6 | 807 | new pkgAcqFile(&Fetcher,Last->Index().ArchiveURI(I->Path), |
d61960d9 | 808 | I->Hashes, I->FileSize, Last->Index().SourceInfo(*Last,*I), Src); |
36375005 AL |
809 | } |
810 | } | |
a3f1d60c | 811 | |
36375005 | 812 | // Display statistics |
3a882565 DK |
813 | unsigned long long FetchBytes = Fetcher.FetchNeeded(); |
814 | unsigned long long FetchPBytes = Fetcher.PartialPresent(); | |
815 | unsigned long long DebBytes = Fetcher.TotalNeeded(); | |
36375005 | 816 | |
9c81f8de DK |
817 | if (CheckFreeSpaceBeforeDownload(".", (FetchBytes - FetchPBytes)) == false) |
818 | return false; | |
819 | ||
36375005 | 820 | // Number of bytes |
36375005 | 821 | if (DebBytes != FetchBytes) |
4d8d8112 DK |
822 | //TRANSLATOR: The required space between number and unit is already included |
823 | // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB | |
b2e465d6 AL |
824 | ioprintf(c1out,_("Need to get %sB/%sB of source archives.\n"), |
825 | SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str()); | |
36375005 | 826 | else |
4d8d8112 DK |
827 | //TRANSLATOR: The required space between number and unit is already included |
828 | // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB | |
b2e465d6 AL |
829 | ioprintf(c1out,_("Need to get %sB of source archives.\n"), |
830 | SizeToStr(DebBytes).c_str()); | |
831 | ||
2c0c53b3 AL |
832 | if (_config->FindB("APT::Get::Simulate",false) == true) |
833 | { | |
834 | for (unsigned I = 0; I != J; I++) | |
db0db9fe | 835 | ioprintf(cout,_("Fetch source %s\n"),Dsc[I].Package.c_str()); |
2c0c53b3 AL |
836 | return true; |
837 | } | |
460601d5 | 838 | |
36375005 AL |
839 | // Just print out the uris an exit if the --print-uris flag was used |
840 | if (_config->FindB("APT::Get::Print-URIs") == true) | |
841 | { | |
842 | pkgAcquire::UriIterator I = Fetcher.UriBegin(); | |
f7f0d6c7 | 843 | for (; I != Fetcher.UriEnd(); ++I) |
36375005 | 844 | cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << |
495e5cb2 | 845 | I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl; |
36375005 AL |
846 | return true; |
847 | } | |
36375005 | 848 | |
460601d5 | 849 | // check authentication status of the source as well |
9112f777 | 850 | if (UntrustedList.empty() == false && AuthPrompt(UntrustedList, false) == false) |
460601d5 DK |
851 | return false; |
852 | ||
866893a6 | 853 | // Run it |
fb0ee66e | 854 | bool Failed = false; |
866893a6 | 855 | if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true) |
6070a346 | 856 | { |
b2e465d6 | 857 | return _error->Error(_("Failed to fetch some archives.")); |
6070a346 DK |
858 | } |
859 | ||
fb0ee66e | 860 | if (_config->FindB("APT::Get::Download-only",false) == true) |
b2e465d6 AL |
861 | { |
862 | c1out << _("Download complete and in download only mode") << endl; | |
fb0ee66e | 863 | return true; |
b2e465d6 AL |
864 | } |
865 | ||
fb0ee66e | 866 | // Unpack the sources |
54676e1a AL |
867 | pid_t Process = ExecFork(); |
868 | ||
869 | if (Process == 0) | |
fb0ee66e | 870 | { |
827d04d3 | 871 | bool const fixBroken = _config->FindB("APT::Get::Fix-Broken", false); |
f7f0d6c7 | 872 | for (unsigned I = 0; I != J; ++I) |
fb0ee66e | 873 | { |
b2e465d6 | 874 | string Dir = Dsc[I].Package + '-' + Cache->VS().UpstreamVersion(Dsc[I].Version.c_str()); |
fb0ee66e | 875 | |
17c0e8e1 AL |
876 | // Diff only mode only fetches .diff files |
877 | if (_config->FindB("APT::Get::Diff-Only",false) == true || | |
a3eaf954 AL |
878 | _config->FindB("APT::Get::Tar-Only",false) == true || |
879 | Dsc[I].Dsc.empty() == true) | |
17c0e8e1 | 880 | continue; |
a3eaf954 | 881 | |
54676e1a AL |
882 | // See if the package is already unpacked |
883 | struct stat Stat; | |
827d04d3 | 884 | if (fixBroken == false && stat(Dir.c_str(),&Stat) == 0 && |
54676e1a AL |
885 | S_ISDIR(Stat.st_mode) != 0) |
886 | { | |
b2e465d6 AL |
887 | ioprintf(c0out ,_("Skipping unpack of already unpacked source in %s\n"), |
888 | Dir.c_str()); | |
54676e1a AL |
889 | } |
890 | else | |
891 | { | |
892 | // Call dpkg-source | |
c53cf70d DK |
893 | std::string const sourceopts = _config->Find("DPkg::Source-Options", "-x"); |
894 | std::string S; | |
895 | strprintf(S, "%s %s %s", | |
54676e1a | 896 | _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(), |
c53cf70d DK |
897 | sourceopts.c_str(), Dsc[I].Dsc.c_str()); |
898 | if (system(S.c_str()) != 0) | |
54676e1a | 899 | { |
c53cf70d DK |
900 | fprintf(stderr, _("Unpack command '%s' failed.\n"), S.c_str()); |
901 | fprintf(stderr, _("Check if the 'dpkg-dev' package is installed.\n")); | |
54676e1a | 902 | _exit(1); |
c53cf70d | 903 | } |
54676e1a | 904 | } |
c53cf70d | 905 | |
54676e1a AL |
906 | // Try to compile it with dpkg-buildpackage |
907 | if (_config->FindB("APT::Get::Compile",false) == true) | |
908 | { | |
234675b7 DK |
909 | string buildopts = _config->Find("APT::Get::Host-Architecture"); |
910 | if (buildopts.empty() == false) | |
c5102538 | 911 | buildopts = "-a" + buildopts + " "; |
ce7f128c DK |
912 | |
913 | // get all active build profiles | |
914 | std::string const profiles = APT::Configuration::getBuildProfilesString(); | |
915 | if (profiles.empty() == false) | |
916 | buildopts.append(" -P").append(profiles).append(" "); | |
917 | ||
234675b7 DK |
918 | buildopts.append(_config->Find("DPkg::Build-Options","-b -uc")); |
919 | ||
54676e1a | 920 | // Call dpkg-buildpackage |
c53cf70d DK |
921 | std::string S; |
922 | strprintf(S, "cd %s && %s %s", | |
54676e1a AL |
923 | Dir.c_str(), |
924 | _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(), | |
234675b7 | 925 | buildopts.c_str()); |
c53cf70d DK |
926 | |
927 | if (system(S.c_str()) != 0) | |
54676e1a | 928 | { |
c53cf70d | 929 | fprintf(stderr, _("Build command '%s' failed.\n"), S.c_str()); |
54676e1a | 930 | _exit(1); |
c53cf70d DK |
931 | } |
932 | } | |
54676e1a | 933 | } |
c53cf70d | 934 | |
54676e1a AL |
935 | _exit(0); |
936 | } | |
3a4477a4 | 937 | |
7c4f1ca5 | 938 | return ExecWait(Process, "dpkg-source"); |
b2e465d6 AL |
939 | } |
940 | /*}}}*/ | |
941 | // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/ | |
942 | // --------------------------------------------------------------------- | |
943 | /* This function will look at the build depends list of the given source | |
944 | package and install the necessary packages to make it true, or fail. */ | |
c3ccac92 | 945 | static bool DoBuildDep(CommandLine &CmdL) |
b2e465d6 AL |
946 | { |
947 | CacheFile Cache; | |
35180212 JAK |
948 | |
949 | _config->Set("APT::Install-Recommends", false); | |
df53919b JAK |
950 | |
951 | bool WantLock = _config->FindB("APT::Get::Print-URIs", false) == false; | |
35180212 | 952 | |
df53919b | 953 | if (Cache.Open(WantLock) == false) |
b2e465d6 AL |
954 | return false; |
955 | ||
956 | if (CmdL.FileSize() <= 1) | |
957 | return _error->Error(_("Must specify at least one package to check builddeps for")); | |
958 | ||
959 | // Read the source list | |
1bb8cd67 DK |
960 | if (Cache.BuildSourceList() == false) |
961 | return false; | |
962 | pkgSourceList *List = Cache.GetSourceList(); | |
54676e1a | 963 | |
b2e465d6 | 964 | // Create the text record parsers |
1bb8cd67 | 965 | pkgSrcRecords SrcRecs(*List); |
b2e465d6 AL |
966 | if (_error->PendingError() == true) |
967 | return false; | |
968 | ||
234675b7 DK |
969 | bool StripMultiArch; |
970 | string hostArch = _config->Find("APT::Get::Host-Architecture"); | |
971 | if (hostArch.empty() == false) | |
972 | { | |
973 | std::vector<std::string> archs = APT::Configuration::getArchitectures(); | |
974 | if (std::find(archs.begin(), archs.end(), hostArch) == archs.end()) | |
975 | return _error->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch.c_str()); | |
976 | StripMultiArch = false; | |
977 | } | |
978 | else | |
979 | StripMultiArch = true; | |
980 | ||
b2e465d6 AL |
981 | unsigned J = 0; |
982 | for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++) | |
983 | { | |
984 | string Src; | |
feab34c5 | 985 | pkgSrcRecords::Parser *Last = 0; |
6c413b18 | 986 | std::unique_ptr<pkgSrcRecords::Parser> LastOwner; |
feab34c5 | 987 | |
a5bb5e1e MV |
988 | // an unpacked debian source tree |
989 | using APT::String::Startswith; | |
990 | if ((Startswith(*I, "./") || Startswith(*I, "/")) && | |
991 | DirectoryExists(*I)) | |
77da39b9 | 992 | { |
a5bb5e1e | 993 | ioprintf(c1out, _("Note, using directory '%s' to get the build dependencies\n"), *I); |
77da39b9 | 994 | // FIXME: how can we make this more elegant? |
463c8d80 | 995 | std::string TypeName = "Debian control file"; |
77da39b9 MV |
996 | pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str()); |
997 | if(Type != NULL) | |
6c413b18 | 998 | LastOwner.reset(Last = Type->CreateSrcPkgParser(*I)); |
77da39b9 | 999 | } |
a49e7948 | 1000 | // if its a local file (e.g. .dsc) use this |
77da39b9 | 1001 | else if (FileExists(*I)) |
feab34c5 | 1002 | { |
a5bb5e1e MV |
1003 | ioprintf(c1out, _("Note, using file '%s' to get the build dependencies\n"), *I); |
1004 | ||
a49e7948 | 1005 | // see if we can get a parser for this pkgIndexFile type |
463c8d80 | 1006 | string TypeName = "Debian " + flExtension(*I) + " file"; |
a49e7948 MV |
1007 | pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str()); |
1008 | if(Type != NULL) | |
6c413b18 | 1009 | LastOwner.reset(Last = Type->CreateSrcPkgParser(*I)); |
feab34c5 | 1010 | } else { |
a49e7948 | 1011 | // normal case, search the cache for the source file |
765190e4 | 1012 | Last = FindSrc(*I,SrcRecs,Src,Cache); |
feab34c5 | 1013 | } |
a49e7948 | 1014 | |
b2e465d6 AL |
1015 | if (Last == 0) |
1016 | return _error->Error(_("Unable to find a source package for %s"),Src.c_str()); | |
1017 | ||
1018 | // Process the build-dependencies | |
1019 | vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps; | |
65f99834 DK |
1020 | // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary |
1021 | if (hostArch.empty() == false) | |
1022 | { | |
1023 | std::string nativeArch = _config->Find("APT::Architecture"); | |
1024 | _config->Set("APT::Architecture", hostArch); | |
1025 | bool Success = Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch); | |
1026 | _config->Set("APT::Architecture", nativeArch); | |
1027 | if (Success == false) | |
1028 | return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str()); | |
1029 | } | |
1030 | else if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false) | |
1031 | return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str()); | |
feab34c5 | 1032 | |
7d6f9f8f AL |
1033 | // Also ensure that build-essential packages are present |
1034 | Configuration::Item const *Opts = _config->Tree("APT::Build-Essential"); | |
1035 | if (Opts) | |
1036 | Opts = Opts->Child; | |
1037 | for (; Opts; Opts = Opts->Next) | |
1038 | { | |
1039 | if (Opts->Value.empty() == true) | |
1040 | continue; | |
1041 | ||
1042 | pkgSrcRecords::Parser::BuildDepRec rec; | |
1043 | rec.Package = Opts->Value; | |
1044 | rec.Type = pkgSrcRecords::Parser::BuildDependIndep; | |
1045 | rec.Op = 0; | |
58d76831 | 1046 | BuildDeps.push_back(rec); |
7d6f9f8f AL |
1047 | } |
1048 | ||
f7f0d6c7 | 1049 | if (BuildDeps.empty() == true) |
b2e465d6 AL |
1050 | { |
1051 | ioprintf(c1out,_("%s has no build depends.\n"),Src.c_str()); | |
1052 | continue; | |
1053 | } | |
234675b7 | 1054 | |
b2e465d6 | 1055 | // Install the requested packages |
b2e465d6 AL |
1056 | vector <pkgSrcRecords::Parser::BuildDepRec>::iterator D; |
1057 | pkgProblemResolver Fix(Cache); | |
58d76831 | 1058 | bool skipAlternatives = false; // skip remaining alternatives in an or group |
f7f0d6c7 | 1059 | for (D = BuildDeps.begin(); D != BuildDeps.end(); ++D) |
b2e465d6 | 1060 | { |
58d76831 AL |
1061 | bool hasAlternatives = (((*D).Op & pkgCache::Dep::Or) == pkgCache::Dep::Or); |
1062 | ||
1063 | if (skipAlternatives == true) | |
1064 | { | |
3fdb6f83 DK |
1065 | /* |
1066 | * if there are alternatives, we've already picked one, so skip | |
1067 | * the rest | |
1068 | * | |
1069 | * TODO: this means that if there's a build-dep on A|B and B is | |
1070 | * installed, we'll still try to install A; more importantly, | |
1071 | * if A is currently broken, we cannot go back and try B. To fix | |
1072 | * this would require we do a Resolve cycle for each package we | |
1073 | * add to the install list. Ugh | |
1074 | */ | |
58d76831 AL |
1075 | if (!hasAlternatives) |
1076 | skipAlternatives = false; // end of or group | |
1077 | continue; | |
1078 | } | |
1079 | ||
aa2d22be AL |
1080 | if ((*D).Type == pkgSrcRecords::Parser::BuildConflict || |
1081 | (*D).Type == pkgSrcRecords::Parser::BuildConflictIndep) | |
d3fc0061 | 1082 | { |
e3a86238 | 1083 | pkgCache::GrpIterator Grp = Cache->FindGrp((*D).Package); |
aa2d22be | 1084 | // Build-conflicts on unknown packages are silently ignored |
e3a86238 | 1085 | if (Grp.end() == true) |
aa2d22be AL |
1086 | continue; |
1087 | ||
e3a86238 DK |
1088 | for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg)) |
1089 | { | |
1090 | pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache); | |
1091 | /* | |
1092 | * Remove if we have an installed version that satisfies the | |
1093 | * version criteria | |
1094 | */ | |
1095 | if (IV.end() == false && | |
1096 | Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true) | |
1097 | TryToInstallBuildDep(Pkg,Cache,Fix,true,false); | |
1098 | } | |
d3fc0061 | 1099 | } |
aa2d22be AL |
1100 | else // BuildDep || BuildDepIndep |
1101 | { | |
58d76831 AL |
1102 | if (_config->FindB("Debug::BuildDeps",false) == true) |
1103 | cout << "Looking for " << (*D).Package << "...\n"; | |
1104 | ||
234675b7 DK |
1105 | pkgCache::PkgIterator Pkg; |
1106 | ||
1107 | // Cross-Building? | |
c307a4f0 | 1108 | if (StripMultiArch == false && D->Type != pkgSrcRecords::Parser::BuildDependIndep) |
234675b7 DK |
1109 | { |
1110 | size_t const colon = D->Package.find(":"); | |
666faa35 DK |
1111 | if (colon != string::npos) |
1112 | { | |
1113 | if (strcmp(D->Package.c_str() + colon, ":any") == 0 || strcmp(D->Package.c_str() + colon, ":native") == 0) | |
1114 | Pkg = Cache->FindPkg(D->Package.substr(0,colon)); | |
1115 | else | |
1116 | Pkg = Cache->FindPkg(D->Package); | |
1117 | } | |
234675b7 | 1118 | else |
666faa35 | 1119 | Pkg = Cache->FindPkg(D->Package, hostArch); |
234675b7 | 1120 | |
234675b7 | 1121 | // a bad version either is invalid or doesn't satify dependency |
d5dea0be DK |
1122 | #define BADVER(Ver) (Ver.end() == true || \ |
1123 | (D->Version.empty() == false && \ | |
1124 | Cache->VS().CheckDep(Ver.VerStr(),D->Op,D->Version.c_str()) == false)) | |
234675b7 | 1125 | |
d5dea0be | 1126 | APT::VersionList verlist; |
234675b7 DK |
1127 | if (Pkg.end() == false) |
1128 | { | |
d5dea0be DK |
1129 | pkgCache::VerIterator Ver = (*Cache)[Pkg].InstVerIter(*Cache); |
1130 | if (BADVER(Ver) == false) | |
1131 | verlist.insert(Ver); | |
1132 | Ver = (*Cache)[Pkg].CandidateVerIter(*Cache); | |
1133 | if (BADVER(Ver) == false) | |
1134 | verlist.insert(Ver); | |
234675b7 | 1135 | } |
d5dea0be | 1136 | if (verlist.empty() == true) |
234675b7 | 1137 | { |
666faa35 DK |
1138 | pkgCache::PkgIterator BuildPkg = Cache->FindPkg(D->Package, "native"); |
1139 | if (BuildPkg.end() == false && Pkg != BuildPkg) | |
234675b7 | 1140 | { |
666faa35 | 1141 | pkgCache::VerIterator Ver = (*Cache)[BuildPkg].InstVerIter(*Cache); |
d5dea0be DK |
1142 | if (BADVER(Ver) == false) |
1143 | verlist.insert(Ver); | |
666faa35 | 1144 | Ver = (*Cache)[BuildPkg].CandidateVerIter(*Cache); |
d5dea0be DK |
1145 | if (BADVER(Ver) == false) |
1146 | verlist.insert(Ver); | |
234675b7 DK |
1147 | } |
1148 | } | |
d5dea0be DK |
1149 | #undef BADVER |
1150 | ||
1151 | string forbidden; | |
1152 | // We need to decide if host or build arch, so find a version we can look at | |
1153 | APT::VersionList::const_iterator Ver = verlist.begin(); | |
1154 | for (; Ver != verlist.end(); ++Ver) | |
234675b7 | 1155 | { |
d5dea0be | 1156 | forbidden.clear(); |
22df31be | 1157 | if (Ver->MultiArch == pkgCache::Version::No || Ver->MultiArch == pkgCache::Version::All) |
737c7a7b SL |
1158 | { |
1159 | if (colon == string::npos) | |
737c7a7b | 1160 | Pkg = Ver.ParentPkg().Group().FindPkg(hostArch); |
a9a370d9 | 1161 | else if (strcmp(D->Package.c_str() + colon, ":any") == 0) |
22df31be | 1162 | forbidden = "Multi-Arch: no"; |
666faa35 DK |
1163 | else if (strcmp(D->Package.c_str() + colon, ":native") == 0) |
1164 | Pkg = Ver.ParentPkg().Group().FindPkg("native"); | |
737c7a7b | 1165 | } |
234675b7 DK |
1166 | else if (Ver->MultiArch == pkgCache::Version::Same) |
1167 | { | |
737c7a7b | 1168 | if (colon == string::npos) |
234675b7 DK |
1169 | Pkg = Ver.ParentPkg().Group().FindPkg(hostArch); |
1170 | else if (strcmp(D->Package.c_str() + colon, ":any") == 0) | |
1171 | forbidden = "Multi-Arch: same"; | |
666faa35 DK |
1172 | else if (strcmp(D->Package.c_str() + colon, ":native") == 0) |
1173 | Pkg = Ver.ParentPkg().Group().FindPkg("native"); | |
234675b7 | 1174 | } |
2a2a7ef4 | 1175 | else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign) |
234675b7 | 1176 | { |
666faa35 DK |
1177 | if (colon == string::npos) |
1178 | Pkg = Ver.ParentPkg().Group().FindPkg("native"); | |
1179 | else if (strcmp(D->Package.c_str() + colon, ":any") == 0 || | |
1180 | strcmp(D->Package.c_str() + colon, ":native") == 0) | |
234675b7 DK |
1181 | forbidden = "Multi-Arch: foreign"; |
1182 | } | |
2a2a7ef4 | 1183 | else if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed) |
234675b7 DK |
1184 | { |
1185 | if (colon == string::npos) | |
1186 | Pkg = Ver.ParentPkg().Group().FindPkg(hostArch); | |
1187 | else if (strcmp(D->Package.c_str() + colon, ":any") == 0) | |
1188 | { | |
1189 | // prefer any installed over preferred non-installed architectures | |
1190 | pkgCache::GrpIterator Grp = Ver.ParentPkg().Group(); | |
1191 | // we don't check for version here as we are better of with upgrading than remove and install | |
1192 | for (Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg)) | |
1193 | if (Pkg.CurrentVer().end() == false) | |
1194 | break; | |
1195 | if (Pkg.end() == true) | |
1196 | Pkg = Grp.FindPreferredPkg(true); | |
1197 | } | |
666faa35 DK |
1198 | else if (strcmp(D->Package.c_str() + colon, ":native") == 0) |
1199 | Pkg = Ver.ParentPkg().Group().FindPkg("native"); | |
234675b7 | 1200 | } |
d5dea0be | 1201 | |
234675b7 DK |
1202 | if (forbidden.empty() == false) |
1203 | { | |
1204 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
d5dea0be DK |
1205 | cout << D->Package.substr(colon, string::npos) << " is not allowed from " << forbidden << " package " << (*D).Package << " (" << Ver.VerStr() << ")" << endl; |
1206 | continue; | |
1207 | } | |
1208 | ||
1209 | //we found a good version | |
1210 | break; | |
1211 | } | |
1212 | if (Ver == verlist.end()) | |
1213 | { | |
1214 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
1215 | cout << " No multiarch info as we have no satisfying installed nor candidate for " << D->Package << " on build or host arch" << endl; | |
1216 | ||
1217 | if (forbidden.empty() == false) | |
1218 | { | |
234675b7 DK |
1219 | if (hasAlternatives) |
1220 | continue; | |
1221 | return _error->Error(_("%s dependency for %s can't be satisfied " | |
1222 | "because %s is not allowed on '%s' packages"), | |
1223 | Last->BuildDepType(D->Type), Src.c_str(), | |
a9a370d9 | 1224 | D->Package.c_str(), forbidden.c_str()); |
234675b7 DK |
1225 | } |
1226 | } | |
234675b7 DK |
1227 | } |
1228 | else | |
1229 | Pkg = Cache->FindPkg(D->Package); | |
1230 | ||
727d8712 | 1231 | if (Pkg.end() == true || (Pkg->VersionList == 0 && Pkg->ProvidesList == 0)) |
aa2d22be | 1232 | { |
58d76831 AL |
1233 | if (_config->FindB("Debug::BuildDeps",false) == true) |
1234 | cout << " (not found)" << (*D).Package << endl; | |
1235 | ||
1236 | if (hasAlternatives) | |
1237 | continue; | |
1238 | ||
1239 | return _error->Error(_("%s dependency for %s cannot be satisfied " | |
1240 | "because the package %s cannot be found"), | |
1241 | Last->BuildDepType((*D).Type),Src.c_str(), | |
1242 | (*D).Package.c_str()); | |
aa2d22be AL |
1243 | } |
1244 | ||
e5002e30 | 1245 | pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache); |
91bee655 DK |
1246 | if (IV.end() == false) |
1247 | { | |
1248 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
1249 | cout << " Is installed\n"; | |
e5002e30 | 1250 | |
91bee655 DK |
1251 | if (D->Version.empty() == true || |
1252 | Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true) | |
1253 | { | |
1254 | skipAlternatives = hasAlternatives; | |
1255 | continue; | |
1256 | } | |
cfa5659c | 1257 | |
91bee655 DK |
1258 | if (_config->FindB("Debug::BuildDeps",false) == true) |
1259 | cout << " ...but the installed version doesn't meet the version requirement\n"; | |
58d76831 | 1260 | |
91bee655 DK |
1261 | if (((*D).Op & pkgCache::Dep::LessEq) == pkgCache::Dep::LessEq) |
1262 | return _error->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"), | |
1263 | Last->BuildDepType((*D).Type), Src.c_str(), Pkg.FullName(true).c_str()); | |
1264 | } | |
58d76831 | 1265 | |
fe027879 DK |
1266 | // Only consider virtual packages if there is no versioned dependency |
1267 | if ((*D).Version.empty() == true) | |
1268 | { | |
1269 | /* | |
1270 | * If this is a virtual package, we need to check the list of | |
1271 | * packages that provide it and see if any of those are | |
1272 | * installed | |
1273 | */ | |
1274 | pkgCache::PrvIterator Prv = Pkg.ProvidesList(); | |
f7f0d6c7 | 1275 | for (; Prv.end() != true; ++Prv) |
fe027879 DK |
1276 | { |
1277 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
1278 | cout << " Checking provider " << Prv.OwnerPkg().FullName() << endl; | |
58d76831 | 1279 | |
fe027879 DK |
1280 | if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false) |
1281 | break; | |
1282 | } | |
58d76831 | 1283 | |
fe027879 DK |
1284 | if (Prv.end() == false) |
1285 | { | |
1286 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
1287 | cout << " Is provided by installed package " << Prv.OwnerPkg().FullName() << endl; | |
1288 | skipAlternatives = hasAlternatives; | |
1289 | continue; | |
1290 | } | |
1291 | } | |
2baf02ca DK |
1292 | else // versioned dependency |
1293 | { | |
1294 | pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache); | |
1295 | if (CV.end() == true || | |
1296 | Cache->VS().CheckDep(CV.VerStr(),(*D).Op,(*D).Version.c_str()) == false) | |
1297 | { | |
1298 | if (hasAlternatives) | |
1299 | continue; | |
1300 | else if (CV.end() == false) | |
1301 | return _error->Error(_("%s dependency for %s cannot be satisfied " | |
1302 | "because candidate version of package %s " | |
1303 | "can't satisfy version requirements"), | |
1304 | Last->BuildDepType(D->Type), Src.c_str(), | |
1305 | D->Package.c_str()); | |
1306 | else | |
1307 | return _error->Error(_("%s dependency for %s cannot be satisfied " | |
1308 | "because package %s has no candidate version"), | |
1309 | Last->BuildDepType(D->Type), Src.c_str(), | |
1310 | D->Package.c_str()); | |
1311 | } | |
1312 | } | |
58d76831 | 1313 | |
f1f874bd | 1314 | if (TryToInstallBuildDep(Pkg,Cache,Fix,false,false,false) == true) |
58d76831 AL |
1315 | { |
1316 | // We successfully installed something; skip remaining alternatives | |
1317 | skipAlternatives = hasAlternatives; | |
d59228b0 | 1318 | if(_config->FindB("APT::Get::Build-Dep-Automatic", false) == true) |
496a05c6 | 1319 | Cache->MarkAuto(Pkg, true); |
58d76831 AL |
1320 | continue; |
1321 | } | |
1322 | else if (hasAlternatives) | |
1323 | { | |
1324 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
1325 | cout << " Unsatisfiable, trying alternatives\n"; | |
1326 | continue; | |
1327 | } | |
1328 | else | |
1329 | { | |
1330 | return _error->Error(_("Failed to satisfy %s dependency for %s: %s"), | |
1331 | Last->BuildDepType((*D).Type), | |
1332 | Src.c_str(), | |
1333 | (*D).Package.c_str()); | |
1334 | } | |
b2e465d6 AL |
1335 | } |
1336 | } | |
f3c736f9 | 1337 | |
b2e465d6 AL |
1338 | if (Fix.Resolve(true) == false) |
1339 | _error->Discard(); | |
1340 | ||
1341 | // Now we check the state of the packages, | |
1342 | if (Cache->BrokenCount() != 0) | |
0dae8ac5 DK |
1343 | { |
1344 | ShowBroken(cout, Cache, false); | |
1345 | return _error->Error(_("Build-dependencies for %s could not be satisfied."),*I); | |
1346 | } | |
b2e465d6 AL |
1347 | } |
1348 | ||
1349 | if (InstallPackages(Cache, false, true) == false) | |
1350 | return _error->Error(_("Failed to process build dependencies")); | |
36375005 AL |
1351 | return true; |
1352 | } | |
1353 | /*}}}*/ | |
a4c40430 | 1354 | // DoChangelog - Get changelog from the command line /*{{{*/ |
c3ccac92 | 1355 | static bool DoChangelog(CommandLine &CmdL) |
a4c40430 MV |
1356 | { |
1357 | CacheFile Cache; | |
1358 | if (Cache.ReadOnlyOpen() == false) | |
1359 | return false; | |
d56e2917 | 1360 | |
353c135e | 1361 | APT::CacheSetHelper helper; |
c4cca791 | 1362 | APT::VersionList verset = APT::VersionList::FromCommandLine(Cache, |
43acd019 | 1363 | CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper); |
72dd5bec DK |
1364 | if (verset.empty() == true) |
1365 | return false; | |
fcb144b9 | 1366 | |
d56e2917 DK |
1367 | bool const downOnly = _config->FindB("APT::Get::Download-Only", false); |
1368 | bool const printOnly = _config->FindB("APT::Get::Print-URIs", false); | |
1369 | ||
2b0660b5 | 1370 | aptAcquireWithTextStatus Fetcher; |
d56e2917 DK |
1371 | for (APT::VersionList::const_iterator Ver = verset.begin(); |
1372 | Ver != verset.end(); | |
1373 | ++Ver) | |
a98b6615 | 1374 | { |
d56e2917 DK |
1375 | if (printOnly) |
1376 | new pkgAcqChangelog(&Fetcher, Ver, "/dev/null"); | |
1377 | else if (downOnly) | |
1378 | new pkgAcqChangelog(&Fetcher, Ver, "."); | |
1379 | else | |
1380 | new pkgAcqChangelog(&Fetcher, Ver); | |
a98b6615 | 1381 | } |
fcb144b9 | 1382 | |
d56e2917 DK |
1383 | if (printOnly == false) |
1384 | { | |
d56e2917 DK |
1385 | bool Failed = false; |
1386 | if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true) | |
1387 | return false; | |
1388 | } | |
72dd5bec | 1389 | |
d56e2917 | 1390 | if (downOnly == false || printOnly == true) |
72dd5bec | 1391 | { |
d56e2917 DK |
1392 | bool Failed = false; |
1393 | for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I) | |
03aa0847 | 1394 | { |
d56e2917 | 1395 | if (printOnly) |
03aa0847 | 1396 | { |
d56e2917 DK |
1397 | if ((*I)->ErrorText.empty() == false) |
1398 | { | |
1399 | Failed = true; | |
1400 | _error->Error("%s", (*I)->ErrorText.c_str()); | |
1401 | } | |
1402 | else | |
1403 | cout << '\'' << (*I)->DescURI() << "' " << flNotDir((*I)->DestFile) << std::endl; | |
03aa0847 | 1404 | } |
d56e2917 DK |
1405 | else |
1406 | DisplayFileInPager((*I)->DestFile); | |
03aa0847 | 1407 | } |
d56e2917 | 1408 | return Failed == false; |
18ae8b29 | 1409 | } |
72dd5bec | 1410 | |
4a6fe09c | 1411 | return true; |
a4c40430 MV |
1412 | } |
1413 | /*}}}*/ | |
c2a4a8dd | 1414 | // DoIndexTargets - Lists all IndexTargets /*{{{*/ |
8881b11e DK |
1415 | static std::string format_key(std::string key) |
1416 | { | |
1417 | // deb822 is case-insensitive, but the human eye prefers candy | |
1418 | std::transform(key.begin(), key.end(), key.begin(), ::tolower); | |
1419 | key[0] = ::toupper(key[0]); | |
1420 | size_t found = key.find("_uri"); | |
1421 | if (found != std::string::npos) | |
1422 | key.replace(found, 4, "-URI"); | |
1423 | while ((found = key.find('_')) != std::string::npos) | |
1424 | { | |
1425 | key[found] = '-'; | |
1426 | key[found + 1] = ::toupper(key[found + 1]); | |
1427 | } | |
1428 | return key; | |
1429 | } | |
c2a4a8dd | 1430 | static bool DoIndexTargets(CommandLine &CmdL) |
8881b11e DK |
1431 | { |
1432 | pkgCacheFile CacheFile; | |
1433 | pkgSourceList *SrcList = CacheFile.GetSourceList(); | |
1434 | ||
1435 | if (SrcList == NULL) | |
1436 | return false; | |
1437 | ||
c2a4a8dd DK |
1438 | std::string const Format = _config->Find("APT::Get::IndexTargets::Format"); |
1439 | bool const ReleaseInfo = _config->FindB("APT::Get::IndexTargets::ReleaseInfo", true); | |
8881b11e DK |
1440 | bool Filtered = CmdL.FileSize() > 1; |
1441 | for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); ++S) | |
1442 | { | |
1443 | std::vector<IndexTarget> const targets = (*S)->GetIndexTargets(); | |
1444 | std::map<std::string, string> AddOptions; | |
3fd89e62 DK |
1445 | if (ReleaseInfo) |
1446 | { | |
1447 | AddOptions.insert(std::make_pair("TRUSTED", ((*S)->IsTrusted() ? "yes" : "no"))); | |
1448 | pkgCache &Cache = *CacheFile.GetPkgCache(); | |
1449 | pkgCache::RlsFileIterator const RlsFile = (*S)->FindInCache(Cache, false); | |
1450 | if (RlsFile.end()) | |
1451 | continue; | |
1452 | #define APT_RELEASE(X,Y) if (RlsFile.Y() != NULL) AddOptions.insert(std::make_pair(X, RlsFile.Y())) | |
1453 | APT_RELEASE("CODENAME", Codename); | |
1454 | APT_RELEASE("SUITE", Archive); | |
1455 | APT_RELEASE("VERSION", Version); | |
1456 | APT_RELEASE("ORIGIN", Origin); | |
1457 | APT_RELEASE("LABEL", Label); | |
1458 | #undef APT_RELEASE | |
1459 | } | |
8881b11e DK |
1460 | |
1461 | for (std::vector<IndexTarget>::const_iterator T = targets.begin(); T != targets.end(); ++T) | |
1462 | { | |
3fd89e62 DK |
1463 | std::string filename = T->Option(ReleaseInfo ? IndexTarget::EXISTING_FILENAME : IndexTarget::FILENAME); |
1464 | if (filename.empty()) | |
1465 | continue; | |
1466 | ||
8881b11e DK |
1467 | std::ostringstream stanza; |
1468 | if (Filtered || Format.empty()) | |
1469 | { | |
1470 | stanza << "MetaKey: " << T->MetaKey << "\n" | |
1471 | << "ShortDesc: " << T->ShortDesc << "\n" | |
1472 | << "Description: " << T->Description << "\n" | |
1473 | << "URI: " << T->URI << "\n" | |
3fd89e62 | 1474 | << "Filename: " << filename << "\n" |
d7a51997 DK |
1475 | << "Optional: " << (T->IsOptional ? "yes" : "no") << "\n" |
1476 | << "KeepCompressed: " << (T->KeepCompressed ? "yes" : "no") << "\n"; | |
8881b11e DK |
1477 | for (std::map<std::string,std::string>::const_iterator O = AddOptions.begin(); O != AddOptions.end(); ++O) |
1478 | stanza << format_key(O->first) << ": " << O->second << "\n"; | |
1479 | for (std::map<std::string,std::string>::const_iterator O = T->Options.begin(); O != T->Options.end(); ++O) | |
1a3a14ac DK |
1480 | { |
1481 | if (O->first == "PDIFFS") | |
1482 | stanza << "PDiffs: " << O->second << "\n"; | |
d7a51997 DK |
1483 | else if (O->first == "COMPRESSIONTYPES") |
1484 | stanza << "CompressionTypes: " << O->second << "\n"; | |
9adb9778 DK |
1485 | else if (O->first == "DEFAULTENABLED") |
1486 | stanza << "DefaultEnabled: " << O->second << "\n"; | |
1a3a14ac DK |
1487 | else |
1488 | stanza << format_key(O->first) << ": " << O->second << "\n"; | |
1489 | } | |
8881b11e DK |
1490 | stanza << "\n"; |
1491 | ||
1492 | if (Filtered) | |
1493 | { | |
1494 | // that is a bit crude, but good enough for now | |
1495 | bool found = true; | |
1496 | std::string haystack = std::string("\n") + stanza.str() + "\n"; | |
1497 | std::transform(haystack.begin(), haystack.end(), haystack.begin(), ::tolower); | |
1498 | size_t const filesize = CmdL.FileSize() - 1; | |
1499 | for (size_t i = 0; i != filesize; ++i) | |
1500 | { | |
1501 | std::string needle = std::string("\n") + CmdL.FileList[i + 1] + "\n"; | |
1502 | std::transform(needle.begin(), needle.end(), needle.begin(), ::tolower); | |
1503 | if (haystack.find(needle) != std::string::npos) | |
1504 | continue; | |
1505 | found = false; | |
1506 | break; | |
1507 | } | |
1508 | if (found == false) | |
1509 | continue; | |
1510 | } | |
1511 | } | |
1512 | ||
1513 | if (Format.empty()) | |
1514 | cout << stanza.str(); | |
1515 | else | |
1516 | { | |
3fd89e62 DK |
1517 | std::string out = SubstVar(Format, "$(FILENAME)", filename); |
1518 | out = T->Format(out); | |
8881b11e DK |
1519 | for (std::map<std::string,std::string>::const_iterator O = AddOptions.begin(); O != AddOptions.end(); ++O) |
1520 | out = SubstVar(out, std::string("$(") + O->first + ")", O->second); | |
1521 | cout << out << std::endl; | |
1522 | } | |
1523 | } | |
1524 | } | |
1525 | ||
1526 | return true; | |
1527 | } | |
1528 | /*}}}*/ | |
6079b276 | 1529 | bool ShowHelp(CommandLine &, aptDispatchWithHelp const * Cmds) /*{{{*/ |
0a8e3465 | 1530 | { |
249aec3b JB |
1531 | ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); |
1532 | ||
04aa15a8 | 1533 | if (_config->FindB("version") == true) |
b2e465d6 | 1534 | { |
db0db9fe | 1535 | cout << _("Supported modules:") << endl; |
249aec3b | 1536 | |
b2e465d6 AL |
1537 | for (unsigned I = 0; I != pkgVersioningSystem::GlobalListLen; I++) |
1538 | { | |
1539 | pkgVersioningSystem *VS = pkgVersioningSystem::GlobalList[I]; | |
1540 | if (_system != 0 && _system->VS == VS) | |
1541 | cout << '*'; | |
1542 | else | |
1543 | cout << ' '; | |
1544 | cout << "Ver: " << VS->Label << endl; | |
249aec3b | 1545 | |
b2e465d6 AL |
1546 | /* Print out all the packaging systems that will work with |
1547 | this VS */ | |
1548 | for (unsigned J = 0; J != pkgSystem::GlobalListLen; J++) | |
1549 | { | |
1550 | pkgSystem *Sys = pkgSystem::GlobalList[J]; | |
1551 | if (_system == Sys) | |
1552 | cout << '*'; | |
1553 | else | |
1554 | cout << ' '; | |
1555 | if (Sys->VS->TestCompatibility(*VS) == true) | |
1556 | cout << "Pkg: " << Sys->Label << " (Priority " << Sys->Score(*_config) << ")" << endl; | |
1557 | } | |
1558 | } | |
1559 | ||
1560 | for (unsigned I = 0; I != pkgSourceList::Type::GlobalListLen; I++) | |
1561 | { | |
1562 | pkgSourceList::Type *Type = pkgSourceList::Type::GlobalList[I]; | |
1563 | cout << " S.L: '" << Type->Name << "' " << Type->Label << endl; | |
1564 | } | |
1565 | ||
1566 | for (unsigned I = 0; I != pkgIndexFile::Type::GlobalListLen; I++) | |
1567 | { | |
1568 | pkgIndexFile::Type *Type = pkgIndexFile::Type::GlobalList[I]; | |
1569 | cout << " Idx: " << Type->Label << endl; | |
1570 | } | |
1571 | ||
1572 | return true; | |
1573 | } | |
cbbee23e DK |
1574 | |
1575 | std::cout << | |
b2e465d6 AL |
1576 | _("Usage: apt-get [options] command\n" |
1577 | " apt-get [options] install|remove pkg1 [pkg2 ...]\n" | |
1578 | " apt-get [options] source pkg1 [pkg2 ...]\n" | |
1579 | "\n" | |
1580 | "apt-get is a simple command line interface for downloading and\n" | |
1581 | "installing packages. The most frequently used commands are update\n" | |
cbbee23e DK |
1582 | "and install.\n") |
1583 | << std::endl | |
1584 | << _("Commands:") << std::endl; | |
1585 | for (; Cmds->Handler != nullptr; ++Cmds) | |
1586 | { | |
1587 | if (Cmds->Help == nullptr) | |
1588 | continue; | |
1589 | std::cout << " " << Cmds->Match << " - " << Cmds->Help << std::endl; | |
1590 | } | |
1591 | ||
1592 | std::cout << std::endl << | |
1593 | _("Options:\n" | |
b2e465d6 AL |
1594 | " -h This help text.\n" |
1595 | " -q Loggable output - no progress indicator\n" | |
1596 | " -qq No output except for errors\n" | |
1597 | " -d Download only - do NOT install or unpack archives\n" | |
1598 | " -s No-act. Perform ordering simulation\n" | |
1599 | " -y Assume Yes to all queries and do not prompt\n" | |
0748d509 | 1600 | " -f Attempt to correct a system with broken dependencies in place\n" |
b2e465d6 AL |
1601 | " -m Attempt to continue if archives are unlocatable\n" |
1602 | " -u Show a list of upgraded packages as well\n" | |
1603 | " -b Build the source package after fetching it\n" | |
ac625538 | 1604 | " -V Show verbose version numbers\n" |
b2e465d6 | 1605 | " -c=? Read this configuration file\n" |
a2884e32 | 1606 | " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n" |
b2e465d6 AL |
1607 | "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n" |
1608 | "pages for more information and options.\n" | |
1609 | " This APT has Super Cow Powers.\n"); | |
1610 | return true; | |
d7827aca AL |
1611 | } |
1612 | /*}}}*/ | |
6079b276 | 1613 | std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/ |
0a8e3465 | 1614 | { |
011188e3 | 1615 | return { |
cbbee23e DK |
1616 | {"update", &DoUpdate, _("Retrieve new lists of packages")}, |
1617 | {"upgrade", &DoUpgrade, _("Perform an upgrade")}, | |
1618 | {"install", &DoInstall, _("Install new packages (pkg is libc6 not libc6.deb)")}, | |
1619 | {"remove", &DoInstall, _("Remove packages")}, | |
1620 | {"purge", &DoInstall, _("Remove packages and config files")}, | |
1621 | {"autoremove", &DoInstall, _("Remove automatically all unused packages")}, | |
1622 | {"auto-remove", &DoInstall, nullptr}, | |
1623 | {"markauto", &DoMarkAuto, nullptr}, | |
1624 | {"unmarkauto", &DoMarkAuto, nullptr}, | |
1625 | {"dist-upgrade", &DoDistUpgrade, _("Distribution upgrade, see apt-get(8)")}, | |
1626 | {"full-upgrade", &DoDistUpgrade, nullptr}, | |
1627 | {"dselect-upgrade", &DoDSelectUpgrade, _("Follow dselect selections")}, | |
1628 | {"build-dep", &DoBuildDep, _("Configure build-dependencies for source packages")}, | |
1629 | {"clean", &DoClean, _("Erase downloaded archive files")}, | |
1630 | {"autoclean", &DoAutoClean, _("Erase old downloaded archive files")}, | |
1631 | {"auto-clean", &DoAutoClean, nullptr}, | |
1632 | {"check", &DoCheck, _("Verify that there are no broken dependencies")}, | |
1633 | {"source", &DoSource, _("Download source archives")}, | |
1634 | {"download", &DoDownload, _("Download the binary package into the current directory")}, | |
1635 | {"changelog", &DoChangelog, _("Download and display the changelog for the given package")}, | |
1636 | {"indextargets", &DoIndexTargets, nullptr}, | |
1637 | {"moo", &DoMoo, nullptr}, | |
1638 | {nullptr, nullptr, nullptr} | |
1639 | }; | |
011188e3 DK |
1640 | } |
1641 | /*}}}*/ | |
1642 | int main(int argc,const char *argv[]) /*{{{*/ | |
1643 | { | |
1644 | InitLocale(); | |
67111687 | 1645 | |
0a8e3465 | 1646 | // Parse the command line and initialize the package library |
ad7e0941 | 1647 | CommandLine CmdL; |
011188e3 | 1648 | auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_GET, &_config, &_system, argc, argv); |
55a5a46c | 1649 | |
3163087b | 1650 | InitSignals(); |
b9179170 | 1651 | InitOutput(); |
d7827aca | 1652 | |
e7e10e47 | 1653 | CheckIfSimulateMode(CmdL); |
0a8e3465 | 1654 | |
e7e10e47 | 1655 | return DispatchCommandLine(CmdL, Cmds); |
0a8e3465 | 1656 | } |
92fcbfc1 | 1657 | /*}}}*/ |