]>
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 | |
18 | dist-upgrade - Powerfull upgrader designed to handle the issues with | |
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 | ||
086bb6d7 | 30 | #include <apt-pkg/aptconfiguration.h> |
0a8e3465 AL |
31 | #include <apt-pkg/error.h> |
32 | #include <apt-pkg/cmndline.h> | |
33 | #include <apt-pkg/init.h> | |
34 | #include <apt-pkg/depcache.h> | |
35 | #include <apt-pkg/sourcelist.h> | |
0a8e3465 | 36 | #include <apt-pkg/algorithms.h> |
0919e3f9 | 37 | #include <apt-pkg/acquire-item.h> |
cdcc6d34 | 38 | #include <apt-pkg/strutl.h> |
472ff00e | 39 | #include <apt-pkg/fileutl.h> |
1bc849af | 40 | #include <apt-pkg/clean.h> |
36375005 AL |
41 | #include <apt-pkg/srcrecords.h> |
42 | #include <apt-pkg/version.h> | |
2d11135a | 43 | #include <apt-pkg/cachefile.h> |
8fde7239 | 44 | #include <apt-pkg/cacheset.h> |
b2e465d6 | 45 | #include <apt-pkg/sptr.h> |
092ae175 | 46 | #include <apt-pkg/md5.h> |
b2e465d6 | 47 | #include <apt-pkg/versionmatch.h> |
472ff00e DK |
48 | #include <apt-pkg/progress.h> |
49 | #include <apt-pkg/pkgsystem.h> | |
50 | #include <apt-pkg/pkgrecords.h> | |
51 | #include <apt-pkg/indexfile.h> | |
ffee1c2b | 52 | |
b9179170 MV |
53 | |
54 | #include <apt-private/private-install.h> | |
55 | #include <apt-private/private-upgrade.h> | |
56 | #include <apt-private/private-output.h> | |
57 | #include <apt-private/private-cacheset.h> | |
58 | #include <apt-private/private-update.h> | |
59 | #include <apt-private/private-cmndline.h> | |
60 | #include <apt-private/private-moo.h> | |
61 | ||
62 | #include <apt-private/acqprogress.h> | |
0919e3f9 | 63 | |
092ae175 | 64 | #include <set> |
233c2b66 | 65 | #include <locale.h> |
c8ca0ce1 | 66 | #include <langinfo.h> |
90f057fd | 67 | #include <fstream> |
d7827aca AL |
68 | #include <termios.h> |
69 | #include <sys/ioctl.h> | |
1bc849af | 70 | #include <sys/stat.h> |
885d204b | 71 | #include <sys/statfs.h> |
101030ab | 72 | #include <sys/statvfs.h> |
b9179170 MV |
73 | #include <signal.h> |
74 | #include <unistd.h> | |
75 | #include <stdio.h> | |
76 | #include <errno.h> | |
77 | #include <regex.h> | |
78 | #include <sys/wait.h> | |
79 | #include <sstream> | |
a3eaf954 | 80 | |
b9179170 MV |
81 | #include <apt-private/private-output.h> |
82 | #include <apt-private/private-main.h> | |
5ec427c2 | 83 | |
b9179170 MV |
84 | #include <apti18n.h> |
85 | /*}}}*/ | |
afb1e2e3 | 86 | |
642ebc1a | 87 | |
b9179170 | 88 | using namespace std; |
642ebc1a | 89 | |
642ebc1a | 90 | |
642ebc1a | 91 | |
b8ad5512 | 92 | // TryToInstallBuildDep - Try to install a single package /*{{{*/ |
c373c37a AL |
93 | // --------------------------------------------------------------------- |
94 | /* This used to be inlined in DoInstall, but with the advent of regex package | |
95 | name matching it was split out.. */ | |
21d4c9f1 | 96 | bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache, |
c373c37a | 97 | pkgProblemResolver &Fix,bool Remove,bool BrokenFix, |
70e706ad | 98 | bool AllowFail = true) |
c373c37a | 99 | { |
21d4c9f1 | 100 | if (Cache[Pkg].CandidateVer == 0 && Pkg->ProvidesList != 0) |
c373c37a | 101 | { |
21d4c9f1 | 102 | CacheSetHelperAPTGet helper(c1out); |
4caf8231 | 103 | helper.showErrors(false); |
21d4c9f1 DK |
104 | pkgCache::VerIterator Ver = helper.canNotFindNewestVer(Cache, Pkg); |
105 | if (Ver.end() == false) | |
106 | Pkg = Ver.ParentPkg(); | |
107 | else if (helper.showVirtualPackageErrors(Cache) == false) | |
108 | return AllowFail; | |
c373c37a | 109 | } |
61d6a8de | 110 | |
ac321486 DK |
111 | if (_config->FindB("Debug::BuildDeps",false) == true) |
112 | { | |
113 | if (Remove == true) | |
114 | cout << " Trying to remove " << Pkg << endl; | |
115 | else | |
116 | cout << " Trying to install " << Pkg << endl; | |
117 | } | |
118 | ||
c373c37a AL |
119 | if (Remove == true) |
120 | { | |
71d73928 | 121 | TryToRemove RemoveAction(Cache, &Fix); |
21d4c9f1 DK |
122 | RemoveAction(Pkg.VersionList()); |
123 | } else if (Cache[Pkg].CandidateVer != 0) { | |
71d73928 | 124 | TryToInstall InstallAction(Cache, &Fix, BrokenFix); |
21d4c9f1 | 125 | InstallAction(Cache[Pkg].CandidateVerIter(Cache)); |
6806db8a | 126 | InstallAction.doAutoInstall(); |
21d4c9f1 DK |
127 | } else |
128 | return AllowFail; | |
60681f93 | 129 | |
b2e465d6 AL |
130 | return true; |
131 | } | |
132 | /*}}}*/ | |
133 | // FindSrc - Find a source record /*{{{*/ | |
134 | // --------------------------------------------------------------------- | |
135 | /* */ | |
136 | pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs, | |
137 | pkgSrcRecords &SrcRecs,string &Src, | |
138 | pkgDepCache &Cache) | |
139 | { | |
b2e465d6 | 140 | string VerTag; |
fb3dc579 | 141 | string DefRel = _config->Find("APT::Default-Release"); |
b2e465d6 | 142 | string TmpSrc = Name; |
aca056a9 | 143 | |
fb3dc579 MV |
144 | // extract the version/release from the pkgname |
145 | const size_t found = TmpSrc.find_last_of("/="); | |
146 | if (found != string::npos) { | |
147 | if (TmpSrc[found] == '/') | |
148 | DefRel = TmpSrc.substr(found+1); | |
149 | else | |
150 | VerTag = TmpSrc.substr(found+1); | |
ebf6c42d DK |
151 | TmpSrc = TmpSrc.substr(0,found); |
152 | } | |
aca056a9 | 153 | |
fb3dc579 MV |
154 | /* Lookup the version of the package we would install if we were to |
155 | install a version and determine the source package name, then look | |
156 | in the archive for a source package of the same name. */ | |
157 | bool MatchSrcOnly = _config->FindB("APT::Get::Only-Source"); | |
158 | const pkgCache::PkgIterator Pkg = Cache.FindPkg(TmpSrc); | |
159 | if (MatchSrcOnly == false && Pkg.end() == false) | |
aca056a9 | 160 | { |
fb3dc579 | 161 | if(VerTag.empty() == false || DefRel.empty() == false) |
aca056a9 | 162 | { |
e84adb76 | 163 | bool fuzzy = false; |
fb3dc579 MV |
164 | // we have a default release, try to locate the pkg. we do it like |
165 | // this because GetCandidateVer() will not "downgrade", that means | |
166 | // "apt-get source -t stable apt" won't work on a unstable system | |
f7f0d6c7 | 167 | for (pkgCache::VerIterator Ver = Pkg.VersionList();; ++Ver) |
aca056a9 | 168 | { |
e84adb76 DK |
169 | // try first only exact matches, later fuzzy matches |
170 | if (Ver.end() == true) | |
171 | { | |
172 | if (fuzzy == true) | |
173 | break; | |
174 | fuzzy = true; | |
175 | Ver = Pkg.VersionList(); | |
259f688a MV |
176 | // exit right away from the Pkg.VersionList() loop if we |
177 | // don't have any versions | |
178 | if (Ver.end() == true) | |
179 | break; | |
e84adb76 DK |
180 | } |
181 | // We match against a concrete version (or a part of this version) | |
182 | if (VerTag.empty() == false && | |
183 | (fuzzy == true || Cache.VS().CmpVersion(VerTag, Ver.VerStr()) != 0) && // exact match | |
184 | (fuzzy == false || strncmp(VerTag.c_str(), Ver.VerStr(), VerTag.size()) != 0)) // fuzzy match | |
185 | continue; | |
186 | ||
fb3dc579 | 187 | for (pkgCache::VerFileIterator VF = Ver.FileList(); |
f7f0d6c7 | 188 | VF.end() == false; ++VF) |
aca056a9 | 189 | { |
fb3dc579 MV |
190 | /* If this is the status file, and the current version is not the |
191 | version in the status file (ie it is not installed, or somesuch) | |
192 | then it is not a candidate for installation, ever. This weeds | |
193 | out bogus entries that may be due to config-file states, or | |
194 | other. */ | |
195 | if ((VF.File()->Flags & pkgCache::Flag::NotSource) == | |
196 | pkgCache::Flag::NotSource && Pkg.CurrentVer() != Ver) | |
197 | continue; | |
198 | ||
fb3dc579 MV |
199 | // or we match against a release |
200 | if(VerTag.empty() == false || | |
201 | (VF.File().Archive() != 0 && VF.File().Archive() == DefRel) || | |
202 | (VF.File().Codename() != 0 && VF.File().Codename() == DefRel)) | |
203 | { | |
204 | pkgRecords::Parser &Parse = Recs.Lookup(VF); | |
205 | Src = Parse.SourcePkg(); | |
61690a7e MV |
206 | // no SourcePkg name, so it is the "binary" name |
207 | if (Src.empty() == true) | |
208 | Src = TmpSrc; | |
e84adb76 DK |
209 | // the Version we have is possibly fuzzy or includes binUploads, |
210 | // so we use the Version of the SourcePkg (empty if same as package) | |
211 | VerTag = Parse.SourceVer(); | |
61690a7e MV |
212 | if (VerTag.empty() == true) |
213 | VerTag = Ver.VerStr(); | |
fb3dc579 MV |
214 | break; |
215 | } | |
aca056a9 | 216 | } |
61690a7e MV |
217 | if (Src.empty() == false) |
218 | break; | |
aca056a9 | 219 | } |
fb3dc579 MV |
220 | if (Src.empty() == true) |
221 | { | |
61690a7e | 222 | // Sources files have no codename information |
ddff663f MV |
223 | if (VerTag.empty() == true && DefRel.empty() == false) |
224 | { | |
225 | _error->Error(_("Ignore unavailable target release '%s' of package '%s'"), DefRel.c_str(), TmpSrc.c_str()); | |
226 | return 0; | |
227 | } | |
fb3dc579 | 228 | } |
026f60e2 | 229 | } |
61690a7e | 230 | if (Src.empty() == true) |
b2e465d6 | 231 | { |
61690a7e MV |
232 | // if we don't have found a fitting package yet so we will |
233 | // choose a good candidate and proceed with that. | |
234 | // Maybe we will find a source later on with the right VerTag | |
ce6162be | 235 | pkgCache::VerIterator Ver = Cache.GetCandidateVer(Pkg); |
fb3dc579 | 236 | if (Ver.end() == false) |
b2e465d6 AL |
237 | { |
238 | pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList()); | |
239 | Src = Parse.SourcePkg(); | |
61690a7e MV |
240 | if (VerTag.empty() == true) |
241 | VerTag = Parse.SourceVer(); | |
b2e465d6 | 242 | } |
fb3dc579 MV |
243 | } |
244 | } | |
245 | ||
246 | if (Src.empty() == true) | |
247 | Src = TmpSrc; | |
248 | else | |
249 | { | |
250 | /* if we have a source pkg name, make sure to only search | |
251 | for srcpkg names, otherwise apt gets confused if there | |
252 | is a binary package "pkg1" and a source package "pkg1" | |
253 | with the same name but that comes from different packages */ | |
254 | MatchSrcOnly = true; | |
255 | if (Src != TmpSrc) | |
256 | { | |
257 | ioprintf(c1out, _("Picking '%s' as source package instead of '%s'\n"), Src.c_str(), TmpSrc.c_str()); | |
258 | } | |
b2e465d6 | 259 | } |
89ad8e7c | 260 | |
b2e465d6 AL |
261 | // The best hit |
262 | pkgSrcRecords::Parser *Last = 0; | |
263 | unsigned long Offset = 0; | |
264 | string Version; | |
89ad8e7c | 265 | |
b2e465d6 AL |
266 | /* Iterate over all of the hits, which includes the resulting |
267 | binary packages in the search */ | |
268 | pkgSrcRecords::Parser *Parse; | |
fb3dc579 | 269 | while (true) |
b2e465d6 | 270 | { |
fb3dc579 MV |
271 | SrcRecs.Restart(); |
272 | while ((Parse = SrcRecs.Find(Src.c_str(), MatchSrcOnly)) != 0) | |
b2e465d6 | 273 | { |
fb3dc579 MV |
274 | const string Ver = Parse->Version(); |
275 | ||
276 | // Ignore all versions which doesn't fit | |
e84adb76 DK |
277 | if (VerTag.empty() == false && |
278 | Cache.VS().CmpVersion(VerTag, Ver) != 0) // exact match | |
b2e465d6 | 279 | continue; |
fb3dc579 MV |
280 | |
281 | // Newer version or an exact match? Save the hit | |
282 | if (Last == 0 || Cache.VS().CmpVersion(Version,Ver) < 0) { | |
283 | Last = Parse; | |
284 | Offset = Parse->Offset(); | |
285 | Version = Ver; | |
286 | } | |
287 | ||
288 | // was the version check above an exact match? If so, we don't need to look further | |
289 | if (VerTag.empty() == false && VerTag.size() == Ver.size()) | |
290 | break; | |
b2e465d6 | 291 | } |
fb3dc579 MV |
292 | if (Last != 0 || VerTag.empty() == true) |
293 | break; | |
294 | //if (VerTag.empty() == false && Last == 0) | |
ddff663f MV |
295 | _error->Error(_("Ignore unavailable version '%s' of package '%s'"), VerTag.c_str(), TmpSrc.c_str()); |
296 | return 0; | |
b2e465d6 | 297 | } |
fb3dc579 | 298 | |
ce6162be | 299 | if (Last == 0 || Last->Jump(Offset) == false) |
b2e465d6 | 300 | return 0; |
fb3dc579 | 301 | |
b2e465d6 AL |
302 | return Last; |
303 | } | |
304 | /*}}}*/ | |
182a6a55 | 305 | /* mark packages as automatically/manually installed. {{{*/ |
d63a1458 JAK |
306 | bool DoMarkAuto(CommandLine &CmdL) |
307 | { | |
308 | bool Action = true; | |
309 | int AutoMarkChanged = 0; | |
310 | OpTextProgress progress; | |
311 | CacheFile Cache; | |
312 | if (Cache.Open() == false) | |
313 | return false; | |
314 | ||
315 | if (strcasecmp(CmdL.FileList[0],"markauto") == 0) | |
316 | Action = true; | |
317 | else if (strcasecmp(CmdL.FileList[0],"unmarkauto") == 0) | |
318 | Action = false; | |
319 | ||
320 | for (const char **I = CmdL.FileList + 1; *I != 0; I++) | |
321 | { | |
322 | const char *S = *I; | |
323 | // Locate the package | |
324 | pkgCache::PkgIterator Pkg = Cache->FindPkg(S); | |
325 | if (Pkg.end() == true) { | |
326 | return _error->Error(_("Couldn't find package %s"),S); | |
327 | } | |
328 | else | |
329 | { | |
330 | if (!Action) | |
331 | ioprintf(c1out,_("%s set to manually installed.\n"), Pkg.Name()); | |
332 | else | |
333 | ioprintf(c1out,_("%s set to automatically installed.\n"), | |
334 | Pkg.Name()); | |
335 | ||
336 | Cache->MarkAuto(Pkg,Action); | |
337 | AutoMarkChanged++; | |
338 | } | |
339 | } | |
182a6a55 DK |
340 | |
341 | _error->Notice(_("This command is deprecated. Please use 'apt-mark auto' and 'apt-mark manual' instead.")); | |
342 | ||
d63a1458 JAK |
343 | if (AutoMarkChanged && ! _config->FindB("APT::Get::Simulate",false)) |
344 | return Cache->writeStateFile(NULL); | |
345 | return false; | |
346 | } | |
0a8e3465 AL |
347 | /*}}}*/ |
348 | // DoDistUpgrade - Automatic smart upgrader /*{{{*/ | |
349 | // --------------------------------------------------------------------- | |
350 | /* Intelligent upgrader that will install and remove packages at will */ | |
351 | bool DoDistUpgrade(CommandLine &CmdL) | |
352 | { | |
b9674b75 MV |
353 | if (CmdL.FileSize() != 1) |
354 | return _error->Error(_("The dist-upgrade command takes no arguments")); | |
355 | ||
0a8e3465 | 356 | CacheFile Cache; |
c37b9502 | 357 | if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false) |
0a8e3465 AL |
358 | return false; |
359 | ||
db0db9fe | 360 | c0out << _("Calculating upgrade... ") << flush; |
0a8e3465 AL |
361 | if (pkgDistUpgrade(*Cache) == false) |
362 | { | |
b2e465d6 | 363 | c0out << _("Failed") << endl; |
421c8d10 | 364 | ShowBroken(c1out,Cache,false); |
0a8e3465 AL |
365 | return false; |
366 | } | |
367 | ||
b2e465d6 | 368 | c0out << _("Done") << endl; |
0a8e3465 AL |
369 | |
370 | return InstallPackages(Cache,true); | |
371 | } | |
372 | /*}}}*/ | |
373 | // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/ | |
374 | // --------------------------------------------------------------------- | |
375 | /* Follows dselect's selections */ | |
376 | bool DoDSelectUpgrade(CommandLine &CmdL) | |
377 | { | |
378 | CacheFile Cache; | |
c37b9502 | 379 | if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false) |
0a8e3465 AL |
380 | return false; |
381 | ||
a4decc40 MV |
382 | pkgDepCache::ActionGroup group(Cache); |
383 | ||
0a8e3465 AL |
384 | // Install everything with the install flag set |
385 | pkgCache::PkgIterator I = Cache->PkgBegin(); | |
f7f0d6c7 | 386 | for (;I.end() != true; ++I) |
0a8e3465 AL |
387 | { |
388 | /* Install the package only if it is a new install, the autoupgrader | |
389 | will deal with the rest */ | |
390 | if (I->SelectedState == pkgCache::State::Install) | |
391 | Cache->MarkInstall(I,false); | |
392 | } | |
393 | ||
394 | /* Now install their deps too, if we do this above then order of | |
395 | the status file is significant for | groups */ | |
f7f0d6c7 | 396 | for (I = Cache->PkgBegin();I.end() != true; ++I) |
0a8e3465 AL |
397 | { |
398 | /* Install the package only if it is a new install, the autoupgrader | |
399 | will deal with the rest */ | |
400 | if (I->SelectedState == pkgCache::State::Install) | |
2f45c76a | 401 | Cache->MarkInstall(I,true); |
0a8e3465 AL |
402 | } |
403 | ||
404 | // Apply erasures now, they override everything else. | |
f7f0d6c7 | 405 | for (I = Cache->PkgBegin();I.end() != true; ++I) |
0a8e3465 AL |
406 | { |
407 | // Remove packages | |
408 | if (I->SelectedState == pkgCache::State::DeInstall || | |
409 | I->SelectedState == pkgCache::State::Purge) | |
d556d1a1 | 410 | Cache->MarkDelete(I,I->SelectedState == pkgCache::State::Purge); |
0a8e3465 AL |
411 | } |
412 | ||
2f45c76a AL |
413 | /* Resolve any problems that dselect created, allupgrade cannot handle |
414 | such things. We do so quite agressively too.. */ | |
415 | if (Cache->BrokenCount() != 0) | |
416 | { | |
417 | pkgProblemResolver Fix(Cache); | |
418 | ||
419 | // Hold back held packages. | |
b2e465d6 | 420 | if (_config->FindB("APT::Ignore-Hold",false) == false) |
2f45c76a | 421 | { |
f7f0d6c7 | 422 | for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() == false; ++I) |
2f45c76a AL |
423 | { |
424 | if (I->SelectedState == pkgCache::State::Hold) | |
425 | { | |
426 | Fix.Protect(I); | |
427 | Cache->MarkKeep(I); | |
428 | } | |
429 | } | |
430 | } | |
431 | ||
432 | if (Fix.Resolve() == false) | |
433 | { | |
421c8d10 | 434 | ShowBroken(c1out,Cache,false); |
2a7e07c7 | 435 | return _error->Error(_("Internal error, problem resolver broke stuff")); |
2f45c76a AL |
436 | } |
437 | } | |
438 | ||
439 | // Now upgrade everything | |
0a8e3465 AL |
440 | if (pkgAllUpgrade(Cache) == false) |
441 | { | |
421c8d10 | 442 | ShowBroken(c1out,Cache,false); |
2a7e07c7 | 443 | return _error->Error(_("Internal error, problem resolver broke stuff")); |
0a8e3465 AL |
444 | } |
445 | ||
446 | return InstallPackages(Cache,false); | |
447 | } | |
448 | /*}}}*/ | |
449 | // DoClean - Remove download archives /*{{{*/ | |
450 | // --------------------------------------------------------------------- | |
451 | /* */ | |
452 | bool DoClean(CommandLine &CmdL) | |
453 | { | |
657ecd4a DK |
454 | std::string const archivedir = _config->FindDir("Dir::Cache::archives"); |
455 | std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache"); | |
456 | std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache"); | |
457 | ||
8b067c22 AL |
458 | if (_config->FindB("APT::Get::Simulate") == true) |
459 | { | |
657ecd4a DK |
460 | cout << "Del " << archivedir << "* " << archivedir << "partial/*"<< endl |
461 | << "Del " << pkgcache << " " << srcpkgcache << endl; | |
8b067c22 AL |
462 | return true; |
463 | } | |
464 | ||
1b6d659c AL |
465 | // Lock the archive directory |
466 | FileFd Lock; | |
467 | if (_config->FindB("Debug::NoLocking",false) == false) | |
468 | { | |
de24f8ce MV |
469 | int lock_fd = GetLock(archivedir + "lock"); |
470 | if (lock_fd < 0) | |
b2e465d6 | 471 | return _error->Error(_("Unable to lock the download directory")); |
de24f8ce | 472 | Lock.Fd(lock_fd); |
1b6d659c AL |
473 | } |
474 | ||
7a1b1f8b | 475 | pkgAcquire Fetcher; |
657ecd4a DK |
476 | Fetcher.Clean(archivedir); |
477 | Fetcher.Clean(archivedir + "partial/"); | |
478 | ||
8de79b68 | 479 | pkgCacheFile::RemoveCaches(); |
657ecd4a | 480 | |
0a8e3465 AL |
481 | return true; |
482 | } | |
483 | /*}}}*/ | |
1bc849af AL |
484 | // DoAutoClean - Smartly remove downloaded archives /*{{{*/ |
485 | // --------------------------------------------------------------------- | |
486 | /* This is similar to clean but it only purges things that cannot be | |
487 | downloaded, that is old versions of cached packages. */ | |
65a1e968 AL |
488 | class LogCleaner : public pkgArchiveCleaner |
489 | { | |
490 | protected: | |
491 | virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St) | |
492 | { | |
4cc8bab0 | 493 | c1out << "Del " << Pkg << " " << Ver << " [" << SizeToStr(St.st_size) << "B]" << endl; |
c1e78ee5 AL |
494 | |
495 | if (_config->FindB("APT::Get::Simulate") == false) | |
496 | unlink(File); | |
65a1e968 AL |
497 | }; |
498 | }; | |
499 | ||
1bc849af AL |
500 | bool DoAutoClean(CommandLine &CmdL) |
501 | { | |
1b6d659c AL |
502 | // Lock the archive directory |
503 | FileFd Lock; | |
504 | if (_config->FindB("Debug::NoLocking",false) == false) | |
505 | { | |
de24f8ce MV |
506 | int lock_fd = GetLock(_config->FindDir("Dir::Cache::Archives") + "lock"); |
507 | if (lock_fd < 0) | |
b2e465d6 | 508 | return _error->Error(_("Unable to lock the download directory")); |
de24f8ce | 509 | Lock.Fd(lock_fd); |
1b6d659c AL |
510 | } |
511 | ||
1bc849af | 512 | CacheFile Cache; |
2d11135a | 513 | if (Cache.Open() == false) |
1bc849af AL |
514 | return false; |
515 | ||
65a1e968 | 516 | LogCleaner Cleaner; |
1bc849af AL |
517 | |
518 | return Cleaner.Go(_config->FindDir("Dir::Cache::archives"),*Cache) && | |
519 | Cleaner.Go(_config->FindDir("Dir::Cache::archives") + "partial/",*Cache); | |
520 | } | |
521 | /*}}}*/ | |
0e3e112e MV |
522 | // DoDownload - download a binary /*{{{*/ |
523 | // --------------------------------------------------------------------- | |
524 | bool DoDownload(CommandLine &CmdL) | |
525 | { | |
526 | CacheFile Cache; | |
527 | if (Cache.ReadOnlyOpen() == false) | |
528 | return false; | |
529 | ||
530 | APT::CacheSetHelper helper(c0out); | |
c4cca791 DK |
531 | APT::VersionList verset = APT::VersionList::FromCommandLine(Cache, |
532 | CmdL.FileList + 1, APT::VersionList::CANDIDATE, helper); | |
0e3e112e MV |
533 | |
534 | if (verset.empty() == true) | |
535 | return false; | |
536 | ||
42d41ddb DK |
537 | pkgAcquire Fetcher; |
538 | AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0)); | |
fd8b88d6 | 539 | if (_config->FindB("APT::Get::Print-URIs") == false) |
42d41ddb DK |
540 | Fetcher.Setup(&Stat); |
541 | ||
0e3e112e MV |
542 | pkgRecords Recs(Cache); |
543 | pkgSourceList *SrcList = Cache.GetSourceList(); | |
567785b9 DK |
544 | bool gotAll = true; |
545 | ||
c4cca791 | 546 | for (APT::VersionList::const_iterator Ver = verset.begin(); |
0e3e112e MV |
547 | Ver != verset.end(); |
548 | ++Ver) | |
549 | { | |
550 | string descr; | |
551 | // get the right version | |
552 | pkgCache::PkgIterator Pkg = Ver.ParentPkg(); | |
553 | pkgRecords::Parser &rec=Recs.Lookup(Ver.FileList()); | |
554 | pkgCache::VerFileIterator Vf = Ver.FileList(); | |
555 | if (Vf.end() == true) | |
567785b9 DK |
556 | { |
557 | _error->Error("Can not find VerFile for %s in version %s", Pkg.FullName().c_str(), Ver.VerStr()); | |
558 | gotAll = false; | |
559 | continue; | |
560 | } | |
0e3e112e MV |
561 | pkgCache::PkgFileIterator F = Vf.File(); |
562 | pkgIndexFile *index; | |
563 | if(SrcList->FindIndex(F, index) == false) | |
567785b9 DK |
564 | { |
565 | _error->Error(_("Can't find a source to download version '%s' of '%s'"), Ver.VerStr(), Pkg.FullName().c_str()); | |
566 | gotAll = false; | |
567 | continue; | |
568 | } | |
0e3e112e MV |
569 | string uri = index->ArchiveURI(rec.FileName()); |
570 | strprintf(descr, _("Downloading %s %s"), Pkg.Name(), Ver.VerStr()); | |
571 | // get the most appropriate hash | |
572 | HashString hash; | |
d9b9e9e2 MV |
573 | if (rec.SHA512Hash() != "") |
574 | hash = HashString("sha512", rec.SHA512Hash()); | |
ee5f5d25 | 575 | else if (rec.SHA256Hash() != "") |
0e3e112e MV |
576 | hash = HashString("sha256", rec.SHA256Hash()); |
577 | else if (rec.SHA1Hash() != "") | |
578 | hash = HashString("sha1", rec.SHA1Hash()); | |
579 | else if (rec.MD5Hash() != "") | |
580 | hash = HashString("md5", rec.MD5Hash()); | |
581 | // get the file | |
582 | new pkgAcqFile(&Fetcher, uri, hash.toStr(), (*Ver)->Size, descr, Pkg.Name(), "."); | |
0e3e112e | 583 | } |
567785b9 DK |
584 | if (gotAll == false) |
585 | return false; | |
0e3e112e | 586 | |
42d41ddb DK |
587 | // Just print out the uris and exit if the --print-uris flag was used |
588 | if (_config->FindB("APT::Get::Print-URIs") == true) | |
589 | { | |
590 | pkgAcquire::UriIterator I = Fetcher.UriBegin(); | |
f7f0d6c7 | 591 | for (; I != Fetcher.UriEnd(); ++I) |
42d41ddb DK |
592 | cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << |
593 | I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl; | |
594 | return true; | |
595 | } | |
596 | ||
597 | return (Fetcher.Run() == pkgAcquire::Continue); | |
0e3e112e MV |
598 | } |
599 | /*}}}*/ | |
0a8e3465 AL |
600 | // DoCheck - Perform the check operation /*{{{*/ |
601 | // --------------------------------------------------------------------- | |
602 | /* Opening automatically checks the system, this command is mostly used | |
603 | for debugging */ | |
604 | bool DoCheck(CommandLine &CmdL) | |
605 | { | |
606 | CacheFile Cache; | |
607 | Cache.Open(); | |
2d11135a | 608 | Cache.CheckDeps(); |
0a8e3465 AL |
609 | |
610 | return true; | |
611 | } | |
612 | /*}}}*/ | |
36375005 AL |
613 | // DoSource - Fetch a source archive /*{{{*/ |
614 | // --------------------------------------------------------------------- | |
2d11135a | 615 | /* Fetch souce packages */ |
fb0ee66e AL |
616 | struct DscFile |
617 | { | |
618 | string Package; | |
619 | string Version; | |
620 | string Dsc; | |
621 | }; | |
622 | ||
36375005 AL |
623 | bool DoSource(CommandLine &CmdL) |
624 | { | |
625 | CacheFile Cache; | |
2d11135a | 626 | if (Cache.Open(false) == false) |
36375005 AL |
627 | return false; |
628 | ||
2d11135a | 629 | if (CmdL.FileSize() <= 1) |
b2e465d6 | 630 | return _error->Error(_("Must specify at least one package to fetch source for")); |
2d11135a | 631 | |
36375005 | 632 | // Read the source list |
1bb8cd67 DK |
633 | if (Cache.BuildSourceList() == false) |
634 | return false; | |
635 | pkgSourceList *List = Cache.GetSourceList(); | |
36375005 AL |
636 | |
637 | // Create the text record parsers | |
638 | pkgRecords Recs(Cache); | |
1bb8cd67 | 639 | pkgSrcRecords SrcRecs(*List); |
36375005 AL |
640 | if (_error->PendingError() == true) |
641 | return false; | |
642 | ||
643 | // Create the download object | |
644 | AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); | |
1cd1c398 | 645 | pkgAcquire Fetcher; |
4a53151a | 646 | Fetcher.SetLog(&Stat); |
fb0ee66e AL |
647 | |
648 | DscFile *Dsc = new DscFile[CmdL.FileSize()]; | |
36375005 | 649 | |
092ae175 MV |
650 | // insert all downloaded uris into this set to avoid downloading them |
651 | // twice | |
652 | set<string> queued; | |
8545b536 DK |
653 | |
654 | // Diff only mode only fetches .diff files | |
655 | bool const diffOnly = _config->FindB("APT::Get::Diff-Only", false); | |
656 | // Tar only mode only fetches .tar files | |
657 | bool const tarOnly = _config->FindB("APT::Get::Tar-Only", false); | |
658 | // Dsc only mode only fetches .dsc files | |
659 | bool const dscOnly = _config->FindB("APT::Get::Dsc-Only", false); | |
660 | ||
36375005 | 661 | // Load the requestd sources into the fetcher |
fb0ee66e AL |
662 | unsigned J = 0; |
663 | for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++) | |
36375005 AL |
664 | { |
665 | string Src; | |
b2e465d6 | 666 | pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,*Cache); |
36375005 | 667 | |
6070a346 DK |
668 | if (Last == 0) { |
669 | delete[] Dsc; | |
b2e465d6 | 670 | return _error->Error(_("Unable to find a source package for %s"),Src.c_str()); |
6070a346 | 671 | } |
36375005 | 672 | |
3238423f MV |
673 | string srec = Last->AsStr(); |
674 | string::size_type pos = srec.find("\nVcs-"); | |
774a6687 | 675 | while (pos != string::npos) |
3238423f MV |
676 | { |
677 | pos += strlen("\nVcs-"); | |
678 | string vcs = srec.substr(pos,srec.find(":",pos)-pos); | |
774a6687 MV |
679 | if(vcs == "Browser") |
680 | { | |
681 | pos = srec.find("\nVcs-", pos); | |
682 | continue; | |
683 | } | |
3238423f MV |
684 | pos += vcs.length()+2; |
685 | string::size_type epos = srec.find("\n", pos); | |
686 | string uri = srec.substr(pos,epos-pos).c_str(); | |
b799e134 | 687 | ioprintf(c1out, _("NOTICE: '%s' packaging is maintained in " |
3238423f | 688 | "the '%s' version control system at:\n" |
8756297c | 689 | "%s\n"), |
3238423f MV |
690 | Src.c_str(), vcs.c_str(), uri.c_str()); |
691 | if(vcs == "Bzr") | |
927677f0 | 692 | ioprintf(c1out,_("Please use:\n" |
f3e3a2d4 | 693 | "bzr branch %s\n" |
3d513bbd | 694 | "to retrieve the latest (possibly unreleased) " |
b799e134 | 695 | "updates to the package.\n"), |
3238423f | 696 | uri.c_str()); |
b799e134 | 697 | break; |
3238423f MV |
698 | } |
699 | ||
36375005 AL |
700 | // Back track |
701 | vector<pkgSrcRecords::File> Lst; | |
6070a346 DK |
702 | if (Last->Files(Lst) == false) { |
703 | delete[] Dsc; | |
36375005 | 704 | return false; |
6070a346 | 705 | } |
36375005 AL |
706 | |
707 | // Load them into the fetcher | |
708 | for (vector<pkgSrcRecords::File>::const_iterator I = Lst.begin(); | |
f7f0d6c7 | 709 | I != Lst.end(); ++I) |
36375005 AL |
710 | { |
711 | // Try to guess what sort of file it is we are getting. | |
b2e465d6 | 712 | if (I->Type == "dsc") |
fb0ee66e | 713 | { |
fb0ee66e AL |
714 | Dsc[J].Package = Last->Package(); |
715 | Dsc[J].Version = Last->Version(); | |
716 | Dsc[J].Dsc = flNotDir(I->Path); | |
717 | } | |
092ae175 | 718 | |
8545b536 DK |
719 | // Handle the only options so that multiple can be used at once |
720 | if (diffOnly == true || tarOnly == true || dscOnly == true) | |
721 | { | |
722 | if ((diffOnly == true && I->Type == "diff") || | |
723 | (tarOnly == true && I->Type == "tar") || | |
724 | (dscOnly == true && I->Type == "dsc")) | |
725 | ; // Fine, we want this file downloaded | |
726 | else | |
727 | continue; | |
728 | } | |
1979e742 | 729 | |
092ae175 MV |
730 | // don't download the same uri twice (should this be moved to |
731 | // the fetcher interface itself?) | |
732 | if(queued.find(Last->Index().ArchiveURI(I->Path)) != queued.end()) | |
733 | continue; | |
734 | queued.insert(Last->Index().ArchiveURI(I->Path)); | |
b9179170 | 735 | |
092ae175 MV |
736 | // check if we have a file with that md5 sum already localy |
737 | if(!I->MD5Hash.empty() && FileExists(flNotDir(I->Path))) | |
738 | { | |
739 | FileFd Fd(flNotDir(I->Path), FileFd::ReadOnly); | |
740 | MD5Summation sum; | |
741 | sum.AddFD(Fd.Fd(), Fd.Size()); | |
742 | Fd.Close(); | |
743 | if((string)sum.Result() == I->MD5Hash) | |
744 | { | |
443cb67c | 745 | ioprintf(c1out,_("Skipping already downloaded file '%s'\n"), |
092ae175 MV |
746 | flNotDir(I->Path).c_str()); |
747 | continue; | |
748 | } | |
749 | } | |
750 | ||
b2e465d6 AL |
751 | new pkgAcqFile(&Fetcher,Last->Index().ArchiveURI(I->Path), |
752 | I->MD5Hash,I->Size, | |
753 | Last->Index().SourceInfo(*Last,*I),Src); | |
36375005 AL |
754 | } |
755 | } | |
756 | ||
757 | // Display statistics | |
3a882565 DK |
758 | unsigned long long FetchBytes = Fetcher.FetchNeeded(); |
759 | unsigned long long FetchPBytes = Fetcher.PartialPresent(); | |
760 | unsigned long long DebBytes = Fetcher.TotalNeeded(); | |
36375005 AL |
761 | |
762 | // Check for enough free space | |
f332b62b | 763 | struct statvfs Buf; |
36375005 | 764 | string OutputDir = "."; |
c1ce032a | 765 | if (statvfs(OutputDir.c_str(),&Buf) != 0) { |
6070a346 | 766 | delete[] Dsc; |
c1ce032a DK |
767 | if (errno == EOVERFLOW) |
768 | return _error->WarningE("statvfs",_("Couldn't determine free space in %s"), | |
769 | OutputDir.c_str()); | |
770 | else | |
771 | return _error->Errno("statvfs",_("Couldn't determine free space in %s"), | |
772 | OutputDir.c_str()); | |
773 | } else if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize) | |
885d204b OS |
774 | { |
775 | struct statfs Stat; | |
f64196e8 DK |
776 | if (statfs(OutputDir.c_str(),&Stat) != 0 |
777 | #if HAVE_STRUCT_STATFS_F_TYPE | |
778 | || unsigned(Stat.f_type) != RAMFS_MAGIC | |
779 | #endif | |
6070a346 DK |
780 | ) { |
781 | delete[] Dsc; | |
885d204b OS |
782 | return _error->Error(_("You don't have enough free space in %s"), |
783 | OutputDir.c_str()); | |
6070a346 DK |
784 | } |
785 | } | |
36375005 AL |
786 | |
787 | // Number of bytes | |
36375005 | 788 | if (DebBytes != FetchBytes) |
4d8d8112 DK |
789 | //TRANSLATOR: The required space between number and unit is already included |
790 | // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB | |
b2e465d6 AL |
791 | ioprintf(c1out,_("Need to get %sB/%sB of source archives.\n"), |
792 | SizeToStr(FetchBytes).c_str(),SizeToStr(DebBytes).c_str()); | |
36375005 | 793 | else |
4d8d8112 DK |
794 | //TRANSLATOR: The required space between number and unit is already included |
795 | // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB | |
b2e465d6 AL |
796 | ioprintf(c1out,_("Need to get %sB of source archives.\n"), |
797 | SizeToStr(DebBytes).c_str()); | |
798 | ||
2c0c53b3 AL |
799 | if (_config->FindB("APT::Get::Simulate",false) == true) |
800 | { | |
801 | for (unsigned I = 0; I != J; I++) | |
db0db9fe | 802 | ioprintf(cout,_("Fetch source %s\n"),Dsc[I].Package.c_str()); |
3a4477a4 | 803 | delete[] Dsc; |
2c0c53b3 AL |
804 | return true; |
805 | } | |
806 | ||
36375005 AL |
807 | // Just print out the uris an exit if the --print-uris flag was used |
808 | if (_config->FindB("APT::Get::Print-URIs") == true) | |
809 | { | |
810 | pkgAcquire::UriIterator I = Fetcher.UriBegin(); | |
f7f0d6c7 | 811 | for (; I != Fetcher.UriEnd(); ++I) |
36375005 | 812 | cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << |
495e5cb2 | 813 | I->Owner->FileSize << ' ' << I->Owner->HashSum() << endl; |
3a4477a4 | 814 | delete[] Dsc; |
36375005 AL |
815 | return true; |
816 | } | |
817 | ||
818 | // Run it | |
024d1123 | 819 | if (Fetcher.Run() == pkgAcquire::Failed) |
6070a346 DK |
820 | { |
821 | delete[] Dsc; | |
36375005 | 822 | return false; |
6070a346 | 823 | } |
36375005 AL |
824 | |
825 | // Print error messages | |
fb0ee66e | 826 | bool Failed = false; |
f7f0d6c7 | 827 | for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I) |
36375005 AL |
828 | { |
829 | if ((*I)->Status == pkgAcquire::Item::StatDone && | |
830 | (*I)->Complete == true) | |
831 | continue; | |
832 | ||
b2e465d6 AL |
833 | fprintf(stderr,_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(), |
834 | (*I)->ErrorText.c_str()); | |
fb0ee66e | 835 | Failed = true; |
36375005 | 836 | } |
fb0ee66e | 837 | if (Failed == true) |
6070a346 DK |
838 | { |
839 | delete[] Dsc; | |
b2e465d6 | 840 | return _error->Error(_("Failed to fetch some archives.")); |
6070a346 DK |
841 | } |
842 | ||
fb0ee66e | 843 | if (_config->FindB("APT::Get::Download-only",false) == true) |
b2e465d6 AL |
844 | { |
845 | c1out << _("Download complete and in download only mode") << endl; | |
3a4477a4 | 846 | delete[] Dsc; |
fb0ee66e | 847 | return true; |
b2e465d6 AL |
848 | } |
849 | ||
fb0ee66e | 850 | // Unpack the sources |
54676e1a AL |
851 | pid_t Process = ExecFork(); |
852 | ||
853 | if (Process == 0) | |
fb0ee66e | 854 | { |
827d04d3 | 855 | bool const fixBroken = _config->FindB("APT::Get::Fix-Broken", false); |
f7f0d6c7 | 856 | for (unsigned I = 0; I != J; ++I) |
fb0ee66e | 857 | { |
b2e465d6 | 858 | string Dir = Dsc[I].Package + '-' + Cache->VS().UpstreamVersion(Dsc[I].Version.c_str()); |
fb0ee66e | 859 | |
17c0e8e1 AL |
860 | // Diff only mode only fetches .diff files |
861 | if (_config->FindB("APT::Get::Diff-Only",false) == true || | |
a3eaf954 AL |
862 | _config->FindB("APT::Get::Tar-Only",false) == true || |
863 | Dsc[I].Dsc.empty() == true) | |
17c0e8e1 | 864 | continue; |
a3eaf954 | 865 | |
54676e1a AL |
866 | // See if the package is already unpacked |
867 | struct stat Stat; | |
827d04d3 | 868 | if (fixBroken == false && stat(Dir.c_str(),&Stat) == 0 && |
54676e1a AL |
869 | S_ISDIR(Stat.st_mode) != 0) |
870 | { | |
b2e465d6 AL |
871 | ioprintf(c0out ,_("Skipping unpack of already unpacked source in %s\n"), |
872 | Dir.c_str()); | |
54676e1a AL |
873 | } |
874 | else | |
875 | { | |
876 | // Call dpkg-source | |
877 | char S[500]; | |
878 | snprintf(S,sizeof(S),"%s -x %s", | |
879 | _config->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(), | |
880 | Dsc[I].Dsc.c_str()); | |
881 | if (system(S) != 0) | |
882 | { | |
b2e465d6 | 883 | fprintf(stderr,_("Unpack command '%s' failed.\n"),S); |
14cd494a | 884 | fprintf(stderr,_("Check if the 'dpkg-dev' package is installed.\n")); |
54676e1a AL |
885 | _exit(1); |
886 | } | |
887 | } | |
888 | ||
889 | // Try to compile it with dpkg-buildpackage | |
890 | if (_config->FindB("APT::Get::Compile",false) == true) | |
891 | { | |
234675b7 DK |
892 | string buildopts = _config->Find("APT::Get::Host-Architecture"); |
893 | if (buildopts.empty() == false) | |
c5102538 | 894 | buildopts = "-a" + buildopts + " "; |
234675b7 DK |
895 | buildopts.append(_config->Find("DPkg::Build-Options","-b -uc")); |
896 | ||
54676e1a AL |
897 | // Call dpkg-buildpackage |
898 | char S[500]; | |
899 | snprintf(S,sizeof(S),"cd %s && %s %s", | |
900 | Dir.c_str(), | |
901 | _config->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(), | |
234675b7 | 902 | buildopts.c_str()); |
54676e1a AL |
903 | |
904 | if (system(S) != 0) | |
905 | { | |
b2e465d6 | 906 | fprintf(stderr,_("Build command '%s' failed.\n"),S); |
54676e1a AL |
907 | _exit(1); |
908 | } | |
909 | } | |
910 | } | |
911 | ||
912 | _exit(0); | |
913 | } | |
3a4477a4 DK |
914 | delete[] Dsc; |
915 | ||
54676e1a AL |
916 | // Wait for the subprocess |
917 | int Status = 0; | |
918 | while (waitpid(Process,&Status,0) != Process) | |
919 | { | |
920 | if (errno == EINTR) | |
921 | continue; | |
922 | return _error->Errno("waitpid","Couldn't wait for subprocess"); | |
923 | } | |
924 | ||
925 | if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0) | |
b2e465d6 AL |
926 | return _error->Error(_("Child process failed")); |
927 | ||
928 | return true; | |
929 | } | |
930 | /*}}}*/ | |
931 | // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/ | |
932 | // --------------------------------------------------------------------- | |
933 | /* This function will look at the build depends list of the given source | |
934 | package and install the necessary packages to make it true, or fail. */ | |
935 | bool DoBuildDep(CommandLine &CmdL) | |
936 | { | |
937 | CacheFile Cache; | |
35180212 JAK |
938 | |
939 | _config->Set("APT::Install-Recommends", false); | |
940 | ||
b2e465d6 AL |
941 | if (Cache.Open(true) == false) |
942 | return false; | |
943 | ||
944 | if (CmdL.FileSize() <= 1) | |
945 | return _error->Error(_("Must specify at least one package to check builddeps for")); | |
946 | ||
947 | // Read the source list | |
1bb8cd67 DK |
948 | if (Cache.BuildSourceList() == false) |
949 | return false; | |
950 | pkgSourceList *List = Cache.GetSourceList(); | |
54676e1a | 951 | |
b2e465d6 AL |
952 | // Create the text record parsers |
953 | pkgRecords Recs(Cache); | |
1bb8cd67 | 954 | pkgSrcRecords SrcRecs(*List); |
b2e465d6 AL |
955 | if (_error->PendingError() == true) |
956 | return false; | |
957 | ||
958 | // Create the download object | |
959 | AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0)); | |
1cd1c398 DK |
960 | pkgAcquire Fetcher; |
961 | if (Fetcher.Setup(&Stat) == false) | |
962 | return false; | |
b2e465d6 | 963 | |
234675b7 DK |
964 | bool StripMultiArch; |
965 | string hostArch = _config->Find("APT::Get::Host-Architecture"); | |
966 | if (hostArch.empty() == false) | |
967 | { | |
968 | std::vector<std::string> archs = APT::Configuration::getArchitectures(); | |
969 | if (std::find(archs.begin(), archs.end(), hostArch) == archs.end()) | |
970 | return _error->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch.c_str()); | |
971 | StripMultiArch = false; | |
972 | } | |
973 | else | |
974 | StripMultiArch = true; | |
975 | ||
b2e465d6 AL |
976 | unsigned J = 0; |
977 | for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++) | |
978 | { | |
979 | string Src; | |
980 | pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,*Cache); | |
981 | if (Last == 0) | |
982 | return _error->Error(_("Unable to find a source package for %s"),Src.c_str()); | |
983 | ||
984 | // Process the build-dependencies | |
985 | vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps; | |
65f99834 DK |
986 | // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary |
987 | if (hostArch.empty() == false) | |
988 | { | |
989 | std::string nativeArch = _config->Find("APT::Architecture"); | |
990 | _config->Set("APT::Architecture", hostArch); | |
991 | bool Success = Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch); | |
992 | _config->Set("APT::Architecture", nativeArch); | |
993 | if (Success == false) | |
994 | return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str()); | |
995 | } | |
996 | else if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false) | |
997 | return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str()); | |
b2e465d6 | 998 | |
7d6f9f8f AL |
999 | // Also ensure that build-essential packages are present |
1000 | Configuration::Item const *Opts = _config->Tree("APT::Build-Essential"); | |
1001 | if (Opts) | |
1002 | Opts = Opts->Child; | |
1003 | for (; Opts; Opts = Opts->Next) | |
1004 | { | |
1005 | if (Opts->Value.empty() == true) | |
1006 | continue; | |
1007 | ||
1008 | pkgSrcRecords::Parser::BuildDepRec rec; | |
1009 | rec.Package = Opts->Value; | |
1010 | rec.Type = pkgSrcRecords::Parser::BuildDependIndep; | |
1011 | rec.Op = 0; | |
58d76831 | 1012 | BuildDeps.push_back(rec); |
7d6f9f8f AL |
1013 | } |
1014 | ||
f7f0d6c7 | 1015 | if (BuildDeps.empty() == true) |
b2e465d6 AL |
1016 | { |
1017 | ioprintf(c1out,_("%s has no build depends.\n"),Src.c_str()); | |
1018 | continue; | |
1019 | } | |
234675b7 | 1020 | |
b2e465d6 | 1021 | // Install the requested packages |
b2e465d6 AL |
1022 | vector <pkgSrcRecords::Parser::BuildDepRec>::iterator D; |
1023 | pkgProblemResolver Fix(Cache); | |
58d76831 | 1024 | bool skipAlternatives = false; // skip remaining alternatives in an or group |
f7f0d6c7 | 1025 | for (D = BuildDeps.begin(); D != BuildDeps.end(); ++D) |
b2e465d6 | 1026 | { |
58d76831 AL |
1027 | bool hasAlternatives = (((*D).Op & pkgCache::Dep::Or) == pkgCache::Dep::Or); |
1028 | ||
1029 | if (skipAlternatives == true) | |
1030 | { | |
3fdb6f83 DK |
1031 | /* |
1032 | * if there are alternatives, we've already picked one, so skip | |
1033 | * the rest | |
1034 | * | |
1035 | * TODO: this means that if there's a build-dep on A|B and B is | |
1036 | * installed, we'll still try to install A; more importantly, | |
1037 | * if A is currently broken, we cannot go back and try B. To fix | |
1038 | * this would require we do a Resolve cycle for each package we | |
1039 | * add to the install list. Ugh | |
1040 | */ | |
58d76831 AL |
1041 | if (!hasAlternatives) |
1042 | skipAlternatives = false; // end of or group | |
1043 | continue; | |
1044 | } | |
1045 | ||
aa2d22be AL |
1046 | if ((*D).Type == pkgSrcRecords::Parser::BuildConflict || |
1047 | (*D).Type == pkgSrcRecords::Parser::BuildConflictIndep) | |
d3fc0061 | 1048 | { |
e3a86238 | 1049 | pkgCache::GrpIterator Grp = Cache->FindGrp((*D).Package); |
aa2d22be | 1050 | // Build-conflicts on unknown packages are silently ignored |
e3a86238 | 1051 | if (Grp.end() == true) |
aa2d22be AL |
1052 | continue; |
1053 | ||
e3a86238 DK |
1054 | for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg)) |
1055 | { | |
1056 | pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache); | |
1057 | /* | |
1058 | * Remove if we have an installed version that satisfies the | |
1059 | * version criteria | |
1060 | */ | |
1061 | if (IV.end() == false && | |
1062 | Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true) | |
1063 | TryToInstallBuildDep(Pkg,Cache,Fix,true,false); | |
1064 | } | |
d3fc0061 | 1065 | } |
aa2d22be AL |
1066 | else // BuildDep || BuildDepIndep |
1067 | { | |
58d76831 AL |
1068 | if (_config->FindB("Debug::BuildDeps",false) == true) |
1069 | cout << "Looking for " << (*D).Package << "...\n"; | |
1070 | ||
234675b7 DK |
1071 | pkgCache::PkgIterator Pkg; |
1072 | ||
1073 | // Cross-Building? | |
c307a4f0 | 1074 | if (StripMultiArch == false && D->Type != pkgSrcRecords::Parser::BuildDependIndep) |
234675b7 DK |
1075 | { |
1076 | size_t const colon = D->Package.find(":"); | |
666faa35 DK |
1077 | if (colon != string::npos) |
1078 | { | |
1079 | if (strcmp(D->Package.c_str() + colon, ":any") == 0 || strcmp(D->Package.c_str() + colon, ":native") == 0) | |
1080 | Pkg = Cache->FindPkg(D->Package.substr(0,colon)); | |
1081 | else | |
1082 | Pkg = Cache->FindPkg(D->Package); | |
1083 | } | |
234675b7 | 1084 | else |
666faa35 | 1085 | Pkg = Cache->FindPkg(D->Package, hostArch); |
234675b7 | 1086 | |
234675b7 | 1087 | // a bad version either is invalid or doesn't satify dependency |
d5dea0be DK |
1088 | #define BADVER(Ver) (Ver.end() == true || \ |
1089 | (D->Version.empty() == false && \ | |
1090 | Cache->VS().CheckDep(Ver.VerStr(),D->Op,D->Version.c_str()) == false)) | |
234675b7 | 1091 | |
d5dea0be | 1092 | APT::VersionList verlist; |
234675b7 DK |
1093 | if (Pkg.end() == false) |
1094 | { | |
d5dea0be DK |
1095 | pkgCache::VerIterator Ver = (*Cache)[Pkg].InstVerIter(*Cache); |
1096 | if (BADVER(Ver) == false) | |
1097 | verlist.insert(Ver); | |
1098 | Ver = (*Cache)[Pkg].CandidateVerIter(*Cache); | |
1099 | if (BADVER(Ver) == false) | |
1100 | verlist.insert(Ver); | |
234675b7 | 1101 | } |
d5dea0be | 1102 | if (verlist.empty() == true) |
234675b7 | 1103 | { |
666faa35 DK |
1104 | pkgCache::PkgIterator BuildPkg = Cache->FindPkg(D->Package, "native"); |
1105 | if (BuildPkg.end() == false && Pkg != BuildPkg) | |
234675b7 | 1106 | { |
666faa35 | 1107 | pkgCache::VerIterator Ver = (*Cache)[BuildPkg].InstVerIter(*Cache); |
d5dea0be DK |
1108 | if (BADVER(Ver) == false) |
1109 | verlist.insert(Ver); | |
666faa35 | 1110 | Ver = (*Cache)[BuildPkg].CandidateVerIter(*Cache); |
d5dea0be DK |
1111 | if (BADVER(Ver) == false) |
1112 | verlist.insert(Ver); | |
234675b7 DK |
1113 | } |
1114 | } | |
d5dea0be DK |
1115 | #undef BADVER |
1116 | ||
1117 | string forbidden; | |
1118 | // We need to decide if host or build arch, so find a version we can look at | |
1119 | APT::VersionList::const_iterator Ver = verlist.begin(); | |
1120 | for (; Ver != verlist.end(); ++Ver) | |
234675b7 | 1121 | { |
d5dea0be | 1122 | forbidden.clear(); |
737c7a7b SL |
1123 | if (Ver->MultiArch == pkgCache::Version::None || Ver->MultiArch == pkgCache::Version::All) |
1124 | { | |
1125 | if (colon == string::npos) | |
737c7a7b | 1126 | Pkg = Ver.ParentPkg().Group().FindPkg(hostArch); |
a9a370d9 TG |
1127 | else if (strcmp(D->Package.c_str() + colon, ":any") == 0) |
1128 | forbidden = "Multi-Arch: none"; | |
666faa35 DK |
1129 | else if (strcmp(D->Package.c_str() + colon, ":native") == 0) |
1130 | Pkg = Ver.ParentPkg().Group().FindPkg("native"); | |
737c7a7b | 1131 | } |
234675b7 DK |
1132 | else if (Ver->MultiArch == pkgCache::Version::Same) |
1133 | { | |
737c7a7b | 1134 | if (colon == string::npos) |
234675b7 DK |
1135 | Pkg = Ver.ParentPkg().Group().FindPkg(hostArch); |
1136 | else if (strcmp(D->Package.c_str() + colon, ":any") == 0) | |
1137 | forbidden = "Multi-Arch: same"; | |
666faa35 DK |
1138 | else if (strcmp(D->Package.c_str() + colon, ":native") == 0) |
1139 | Pkg = Ver.ParentPkg().Group().FindPkg("native"); | |
234675b7 | 1140 | } |
2a2a7ef4 | 1141 | else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign) |
234675b7 | 1142 | { |
666faa35 DK |
1143 | if (colon == string::npos) |
1144 | Pkg = Ver.ParentPkg().Group().FindPkg("native"); | |
1145 | else if (strcmp(D->Package.c_str() + colon, ":any") == 0 || | |
1146 | strcmp(D->Package.c_str() + colon, ":native") == 0) | |
234675b7 DK |
1147 | forbidden = "Multi-Arch: foreign"; |
1148 | } | |
2a2a7ef4 | 1149 | else if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed) |
234675b7 DK |
1150 | { |
1151 | if (colon == string::npos) | |
1152 | Pkg = Ver.ParentPkg().Group().FindPkg(hostArch); | |
1153 | else if (strcmp(D->Package.c_str() + colon, ":any") == 0) | |
1154 | { | |
1155 | // prefer any installed over preferred non-installed architectures | |
1156 | pkgCache::GrpIterator Grp = Ver.ParentPkg().Group(); | |
1157 | // we don't check for version here as we are better of with upgrading than remove and install | |
1158 | for (Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg)) | |
1159 | if (Pkg.CurrentVer().end() == false) | |
1160 | break; | |
1161 | if (Pkg.end() == true) | |
1162 | Pkg = Grp.FindPreferredPkg(true); | |
1163 | } | |
666faa35 DK |
1164 | else if (strcmp(D->Package.c_str() + colon, ":native") == 0) |
1165 | Pkg = Ver.ParentPkg().Group().FindPkg("native"); | |
234675b7 | 1166 | } |
d5dea0be | 1167 | |
234675b7 DK |
1168 | if (forbidden.empty() == false) |
1169 | { | |
1170 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
d5dea0be DK |
1171 | cout << D->Package.substr(colon, string::npos) << " is not allowed from " << forbidden << " package " << (*D).Package << " (" << Ver.VerStr() << ")" << endl; |
1172 | continue; | |
1173 | } | |
1174 | ||
1175 | //we found a good version | |
1176 | break; | |
1177 | } | |
1178 | if (Ver == verlist.end()) | |
1179 | { | |
1180 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
1181 | cout << " No multiarch info as we have no satisfying installed nor candidate for " << D->Package << " on build or host arch" << endl; | |
1182 | ||
1183 | if (forbidden.empty() == false) | |
1184 | { | |
234675b7 DK |
1185 | if (hasAlternatives) |
1186 | continue; | |
1187 | return _error->Error(_("%s dependency for %s can't be satisfied " | |
1188 | "because %s is not allowed on '%s' packages"), | |
1189 | Last->BuildDepType(D->Type), Src.c_str(), | |
a9a370d9 | 1190 | D->Package.c_str(), forbidden.c_str()); |
234675b7 DK |
1191 | } |
1192 | } | |
234675b7 DK |
1193 | } |
1194 | else | |
1195 | Pkg = Cache->FindPkg(D->Package); | |
1196 | ||
727d8712 | 1197 | if (Pkg.end() == true || (Pkg->VersionList == 0 && Pkg->ProvidesList == 0)) |
aa2d22be | 1198 | { |
58d76831 AL |
1199 | if (_config->FindB("Debug::BuildDeps",false) == true) |
1200 | cout << " (not found)" << (*D).Package << endl; | |
1201 | ||
1202 | if (hasAlternatives) | |
1203 | continue; | |
1204 | ||
1205 | return _error->Error(_("%s dependency for %s cannot be satisfied " | |
1206 | "because the package %s cannot be found"), | |
1207 | Last->BuildDepType((*D).Type),Src.c_str(), | |
1208 | (*D).Package.c_str()); | |
aa2d22be AL |
1209 | } |
1210 | ||
e5002e30 | 1211 | pkgCache::VerIterator IV = (*Cache)[Pkg].InstVerIter(*Cache); |
91bee655 DK |
1212 | if (IV.end() == false) |
1213 | { | |
1214 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
1215 | cout << " Is installed\n"; | |
e5002e30 | 1216 | |
91bee655 DK |
1217 | if (D->Version.empty() == true || |
1218 | Cache->VS().CheckDep(IV.VerStr(),(*D).Op,(*D).Version.c_str()) == true) | |
1219 | { | |
1220 | skipAlternatives = hasAlternatives; | |
1221 | continue; | |
1222 | } | |
cfa5659c | 1223 | |
91bee655 DK |
1224 | if (_config->FindB("Debug::BuildDeps",false) == true) |
1225 | cout << " ...but the installed version doesn't meet the version requirement\n"; | |
58d76831 | 1226 | |
91bee655 DK |
1227 | if (((*D).Op & pkgCache::Dep::LessEq) == pkgCache::Dep::LessEq) |
1228 | return _error->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"), | |
1229 | Last->BuildDepType((*D).Type), Src.c_str(), Pkg.FullName(true).c_str()); | |
1230 | } | |
58d76831 | 1231 | |
fe027879 DK |
1232 | // Only consider virtual packages if there is no versioned dependency |
1233 | if ((*D).Version.empty() == true) | |
1234 | { | |
1235 | /* | |
1236 | * If this is a virtual package, we need to check the list of | |
1237 | * packages that provide it and see if any of those are | |
1238 | * installed | |
1239 | */ | |
1240 | pkgCache::PrvIterator Prv = Pkg.ProvidesList(); | |
f7f0d6c7 | 1241 | for (; Prv.end() != true; ++Prv) |
fe027879 DK |
1242 | { |
1243 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
1244 | cout << " Checking provider " << Prv.OwnerPkg().FullName() << endl; | |
58d76831 | 1245 | |
fe027879 DK |
1246 | if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false) |
1247 | break; | |
1248 | } | |
58d76831 | 1249 | |
fe027879 DK |
1250 | if (Prv.end() == false) |
1251 | { | |
1252 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
1253 | cout << " Is provided by installed package " << Prv.OwnerPkg().FullName() << endl; | |
1254 | skipAlternatives = hasAlternatives; | |
1255 | continue; | |
1256 | } | |
1257 | } | |
2baf02ca DK |
1258 | else // versioned dependency |
1259 | { | |
1260 | pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache); | |
1261 | if (CV.end() == true || | |
1262 | Cache->VS().CheckDep(CV.VerStr(),(*D).Op,(*D).Version.c_str()) == false) | |
1263 | { | |
1264 | if (hasAlternatives) | |
1265 | continue; | |
1266 | else if (CV.end() == false) | |
1267 | return _error->Error(_("%s dependency for %s cannot be satisfied " | |
1268 | "because candidate version of package %s " | |
1269 | "can't satisfy version requirements"), | |
1270 | Last->BuildDepType(D->Type), Src.c_str(), | |
1271 | D->Package.c_str()); | |
1272 | else | |
1273 | return _error->Error(_("%s dependency for %s cannot be satisfied " | |
1274 | "because package %s has no candidate version"), | |
1275 | Last->BuildDepType(D->Type), Src.c_str(), | |
1276 | D->Package.c_str()); | |
1277 | } | |
1278 | } | |
58d76831 | 1279 | |
f1f874bd | 1280 | if (TryToInstallBuildDep(Pkg,Cache,Fix,false,false,false) == true) |
58d76831 AL |
1281 | { |
1282 | // We successfully installed something; skip remaining alternatives | |
1283 | skipAlternatives = hasAlternatives; | |
d59228b0 | 1284 | if(_config->FindB("APT::Get::Build-Dep-Automatic", false) == true) |
496a05c6 | 1285 | Cache->MarkAuto(Pkg, true); |
58d76831 AL |
1286 | continue; |
1287 | } | |
1288 | else if (hasAlternatives) | |
1289 | { | |
1290 | if (_config->FindB("Debug::BuildDeps",false) == true) | |
1291 | cout << " Unsatisfiable, trying alternatives\n"; | |
1292 | continue; | |
1293 | } | |
1294 | else | |
1295 | { | |
1296 | return _error->Error(_("Failed to satisfy %s dependency for %s: %s"), | |
1297 | Last->BuildDepType((*D).Type), | |
1298 | Src.c_str(), | |
1299 | (*D).Package.c_str()); | |
1300 | } | |
b2e465d6 AL |
1301 | } |
1302 | } | |
f3c736f9 | 1303 | |
b2e465d6 AL |
1304 | if (Fix.Resolve(true) == false) |
1305 | _error->Discard(); | |
1306 | ||
1307 | // Now we check the state of the packages, | |
1308 | if (Cache->BrokenCount() != 0) | |
0dae8ac5 DK |
1309 | { |
1310 | ShowBroken(cout, Cache, false); | |
1311 | return _error->Error(_("Build-dependencies for %s could not be satisfied."),*I); | |
1312 | } | |
b2e465d6 AL |
1313 | } |
1314 | ||
1315 | if (InstallPackages(Cache, false, true) == false) | |
1316 | return _error->Error(_("Failed to process build dependencies")); | |
36375005 AL |
1317 | return true; |
1318 | } | |
1319 | /*}}}*/ | |
a53b07bb MV |
1320 | // GetChangelogPath - return a path pointing to a changelog file or dir /*{{{*/ |
1321 | // --------------------------------------------------------------------- | |
1322 | /* This returns a "path" string for the changelog url construction. | |
1323 | * Please note that its not complete, it either needs a "/changelog" | |
1324 | * appended (for the packages.debian.org/changelogs site) or a | |
1325 | * ".changelog" (for third party sites that store the changelog in the | |
1326 | * pool/ next to the deb itself) | |
1327 | * Example return: "pool/main/a/apt/apt_0.8.8ubuntu3" | |
1328 | */ | |
1329 | string GetChangelogPath(CacheFile &Cache, | |
1330 | pkgCache::PkgIterator Pkg, | |
1331 | pkgCache::VerIterator Ver) | |
1332 | { | |
1333 | string path; | |
1334 | ||
1335 | pkgRecords Recs(Cache); | |
1336 | pkgRecords::Parser &rec=Recs.Lookup(Ver.FileList()); | |
1337 | string srcpkg = rec.SourcePkg().empty() ? Pkg.Name() : rec.SourcePkg(); | |
c5d6a22c MV |
1338 | string ver = Ver.VerStr(); |
1339 | // if there is a source version it always wins | |
1340 | if (rec.SourceVer() != "") | |
1341 | ver = rec.SourceVer(); | |
a53b07bb | 1342 | path = flNotFile(rec.FileName()); |
c5d6a22c | 1343 | path += srcpkg + "_" + StripEpoch(ver); |
a53b07bb MV |
1344 | return path; |
1345 | } | |
1346 | /*}}}*/ | |
cdb9307c MV |
1347 | // GuessThirdPartyChangelogUri - return url /*{{{*/ |
1348 | // --------------------------------------------------------------------- | |
a53b07bb MV |
1349 | /* Contruct a changelog file path for third party sites that do not use |
1350 | * packages.debian.org/changelogs | |
1351 | * This simply uses the ArchiveURI() of the source pkg and looks for | |
1352 | * a .changelog file there, Example for "mediabuntu": | |
1353 | * apt-get changelog mplayer-doc: | |
1354 | * http://packages.medibuntu.org/pool/non-free/m/mplayer/mplayer_1.0~rc4~try1.dsfg1-1ubuntu1+medibuntu1.changelog | |
1355 | */ | |
cdb9307c MV |
1356 | bool GuessThirdPartyChangelogUri(CacheFile &Cache, |
1357 | pkgCache::PkgIterator Pkg, | |
1358 | pkgCache::VerIterator Ver, | |
1359 | string &out_uri) | |
1360 | { | |
cdb9307c | 1361 | // get the binary deb server path |
cdb9307c MV |
1362 | pkgCache::VerFileIterator Vf = Ver.FileList(); |
1363 | if (Vf.end() == true) | |
1364 | return false; | |
1365 | pkgCache::PkgFileIterator F = Vf.File(); | |
1366 | pkgIndexFile *index; | |
a53b07bb | 1367 | pkgSourceList *SrcList = Cache.GetSourceList(); |
cdb9307c MV |
1368 | if(SrcList->FindIndex(F, index) == false) |
1369 | return false; | |
a53b07bb | 1370 | |
cdb9307c | 1371 | // get archive uri for the binary deb |
a53b07bb MV |
1372 | string path_without_dot_changelog = GetChangelogPath(Cache, Pkg, Ver); |
1373 | out_uri = index->ArchiveURI(path_without_dot_changelog + ".changelog"); | |
cdb9307c MV |
1374 | |
1375 | // now strip away the filename and add srcpkg_srcver.changelog | |
cdb9307c MV |
1376 | return true; |
1377 | } | |
fcb144b9 | 1378 | /*}}}*/ |
a4c40430 MV |
1379 | // DownloadChangelog - Download the changelog /*{{{*/ |
1380 | // --------------------------------------------------------------------- | |
a53b07bb MV |
1381 | bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher, |
1382 | pkgCache::VerIterator Ver, string targetfile) | |
1383 | /* Download a changelog file for the given package version to | |
1384 | * targetfile. This will first try the server from Apt::Changelogs::Server | |
1385 | * (http://packages.debian.org/changelogs by default) and if that gives | |
1386 | * a 404 tries to get it from the archive directly (see | |
1387 | * GuessThirdPartyChangelogUri for details how) | |
1388 | */ | |
a4c40430 | 1389 | { |
a53b07bb | 1390 | string path; |
a4c40430 | 1391 | string descr; |
c2991635 | 1392 | string server; |
a53b07bb | 1393 | string changelog_uri; |
a4c40430 MV |
1394 | |
1395 | // data structures we need | |
a53b07bb | 1396 | pkgCache::PkgIterator Pkg = Ver.ParentPkg(); |
a4c40430 | 1397 | |
a53b07bb | 1398 | // make the server root configurable |
c2991635 | 1399 | server = _config->Find("Apt::Changelogs::Server", |
a53b07bb MV |
1400 | "http://packages.debian.org/changelogs"); |
1401 | path = GetChangelogPath(CacheFile, Pkg, Ver); | |
1402 | strprintf(changelog_uri, "%s/%s/changelog", server.c_str(), path.c_str()); | |
fcb144b9 DK |
1403 | if (_config->FindB("APT::Get::Print-URIs", false) == true) |
1404 | { | |
1405 | std::cout << '\'' << changelog_uri << '\'' << std::endl; | |
1406 | return true; | |
1407 | } | |
1408 | ||
88573174 | 1409 | strprintf(descr, _("Changelog for %s (%s)"), Pkg.Name(), changelog_uri.c_str()); |
a53b07bb | 1410 | // queue it |
88573174 | 1411 | new pkgAcqFile(&Fetcher, changelog_uri, "", 0, descr, Pkg.Name(), "ignored", targetfile); |
d786352d | 1412 | |
fcb144b9 DK |
1413 | // try downloading it, if that fails, try third-party-changelogs location |
1414 | // FIXME: Fetcher.Run() is "Continue" even if I get a 404?!? | |
1415 | Fetcher.Run(); | |
cdb9307c MV |
1416 | if (!FileExists(targetfile)) |
1417 | { | |
1418 | string third_party_uri; | |
a53b07bb | 1419 | if (GuessThirdPartyChangelogUri(CacheFile, Pkg, Ver, third_party_uri)) |
cdb9307c | 1420 | { |
88573174 MV |
1421 | strprintf(descr, _("Changelog for %s (%s)"), Pkg.Name(), third_party_uri.c_str()); |
1422 | new pkgAcqFile(&Fetcher, third_party_uri, "", 0, descr, Pkg.Name(), "ignored", targetfile); | |
fcb144b9 | 1423 | Fetcher.Run(); |
cdb9307c MV |
1424 | } |
1425 | } | |
4a6fe09c | 1426 | |
a4c40430 | 1427 | if (FileExists(targetfile)) |
18ae8b29 | 1428 | return true; |
a4c40430 MV |
1429 | |
1430 | // error | |
18ae8b29 | 1431 | return _error->Error("changelog download failed"); |
a4c40430 MV |
1432 | } |
1433 | /*}}}*/ | |
1434 | // DisplayFileInPager - Display File with pager /*{{{*/ | |
1435 | void DisplayFileInPager(string filename) | |
1436 | { | |
1437 | pid_t Process = ExecFork(); | |
1438 | if (Process == 0) | |
1439 | { | |
1440 | const char *Args[3]; | |
1441 | Args[0] = "/usr/bin/sensible-pager"; | |
1442 | Args[1] = filename.c_str(); | |
1443 | Args[2] = 0; | |
1444 | execvp(Args[0],(char **)Args); | |
1445 | exit(100); | |
1446 | } | |
1447 | ||
1448 | // Wait for the subprocess | |
1449 | ExecWait(Process, "sensible-pager", false); | |
1450 | } | |
1451 | /*}}}*/ | |
1452 | // DoChangelog - Get changelog from the command line /*{{{*/ | |
1453 | // --------------------------------------------------------------------- | |
1454 | bool DoChangelog(CommandLine &CmdL) | |
1455 | { | |
1456 | CacheFile Cache; | |
1457 | if (Cache.ReadOnlyOpen() == false) | |
1458 | return false; | |
1459 | ||
1460 | APT::CacheSetHelper helper(c0out); | |
c4cca791 DK |
1461 | APT::VersionList verset = APT::VersionList::FromCommandLine(Cache, |
1462 | CmdL.FileList + 1, APT::VersionList::CANDIDATE, helper); | |
72dd5bec DK |
1463 | if (verset.empty() == true) |
1464 | return false; | |
a4c40430 | 1465 | pkgAcquire Fetcher; |
fcb144b9 DK |
1466 | |
1467 | if (_config->FindB("APT::Get::Print-URIs", false) == true) | |
a98b6615 DH |
1468 | { |
1469 | bool Success = true; | |
c4cca791 | 1470 | for (APT::VersionList::const_iterator Ver = verset.begin(); |
fcb144b9 | 1471 | Ver != verset.end(); ++Ver) |
a98b6615 DH |
1472 | Success &= DownloadChangelog(Cache, Fetcher, Ver, ""); |
1473 | return Success; | |
1474 | } | |
fcb144b9 | 1475 | |
8cc74fb1 MV |
1476 | AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0)); |
1477 | Fetcher.Setup(&Stat); | |
a4c40430 | 1478 | |
72dd5bec DK |
1479 | bool const downOnly = _config->FindB("APT::Get::Download-Only", false); |
1480 | ||
1481 | char tmpname[100]; | |
1482 | char* tmpdir = NULL; | |
1483 | if (downOnly == false) | |
1484 | { | |
1485 | const char* const tmpDir = getenv("TMPDIR"); | |
1486 | if (tmpDir != NULL && *tmpDir != '\0') | |
1487 | snprintf(tmpname, sizeof(tmpname), "%s/apt-changelog-XXXXXX", tmpDir); | |
1488 | else | |
1489 | strncpy(tmpname, "/tmp/apt-changelog-XXXXXX", sizeof(tmpname)); | |
1490 | tmpdir = mkdtemp(tmpname); | |
1491 | if (tmpdir == NULL) | |
1492 | return _error->Errno("mkdtemp", "mkdtemp failed"); | |
18ae8b29 | 1493 | } |
72dd5bec | 1494 | |
c4cca791 | 1495 | for (APT::VersionList::const_iterator Ver = verset.begin(); |
a4c40430 MV |
1496 | Ver != verset.end(); |
1497 | ++Ver) | |
1498 | { | |
72dd5bec DK |
1499 | string changelogfile; |
1500 | if (downOnly == false) | |
1501 | changelogfile.append(tmpname).append("changelog"); | |
1502 | else | |
1503 | changelogfile.append(Ver.ParentPkg().Name()).append(".changelog"); | |
1504 | if (DownloadChangelog(Cache, Fetcher, Ver, changelogfile) && downOnly == false) | |
1505 | { | |
a4c40430 | 1506 | DisplayFileInPager(changelogfile); |
72dd5bec DK |
1507 | // cleanup temp file |
1508 | unlink(changelogfile.c_str()); | |
1509 | } | |
a4c40430 | 1510 | } |
18ae8b29 | 1511 | // clenaup tmp dir |
72dd5bec DK |
1512 | if (tmpdir != NULL) |
1513 | rmdir(tmpdir); | |
4a6fe09c | 1514 | return true; |
a4c40430 MV |
1515 | } |
1516 | /*}}}*/ | |
0a8e3465 AL |
1517 | // ShowHelp - Show a help screen /*{{{*/ |
1518 | // --------------------------------------------------------------------- | |
1519 | /* */ | |
212ad54a | 1520 | bool ShowHelp(CommandLine &CmdL) |
0a8e3465 | 1521 | { |
9179f697 | 1522 | ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION, |
5b28c804 | 1523 | COMMON_ARCH,__DATE__,__TIME__); |
b2e465d6 | 1524 | |
04aa15a8 | 1525 | if (_config->FindB("version") == true) |
b2e465d6 | 1526 | { |
db0db9fe | 1527 | cout << _("Supported modules:") << endl; |
b2e465d6 AL |
1528 | |
1529 | for (unsigned I = 0; I != pkgVersioningSystem::GlobalListLen; I++) | |
1530 | { | |
1531 | pkgVersioningSystem *VS = pkgVersioningSystem::GlobalList[I]; | |
1532 | if (_system != 0 && _system->VS == VS) | |
1533 | cout << '*'; | |
1534 | else | |
1535 | cout << ' '; | |
1536 | cout << "Ver: " << VS->Label << endl; | |
1537 | ||
1538 | /* Print out all the packaging systems that will work with | |
1539 | this VS */ | |
1540 | for (unsigned J = 0; J != pkgSystem::GlobalListLen; J++) | |
1541 | { | |
1542 | pkgSystem *Sys = pkgSystem::GlobalList[J]; | |
1543 | if (_system == Sys) | |
1544 | cout << '*'; | |
1545 | else | |
1546 | cout << ' '; | |
1547 | if (Sys->VS->TestCompatibility(*VS) == true) | |
1548 | cout << "Pkg: " << Sys->Label << " (Priority " << Sys->Score(*_config) << ")" << endl; | |
1549 | } | |
1550 | } | |
1551 | ||
1552 | for (unsigned I = 0; I != pkgSourceList::Type::GlobalListLen; I++) | |
1553 | { | |
1554 | pkgSourceList::Type *Type = pkgSourceList::Type::GlobalList[I]; | |
1555 | cout << " S.L: '" << Type->Name << "' " << Type->Label << endl; | |
1556 | } | |
1557 | ||
1558 | for (unsigned I = 0; I != pkgIndexFile::Type::GlobalListLen; I++) | |
1559 | { | |
1560 | pkgIndexFile::Type *Type = pkgIndexFile::Type::GlobalList[I]; | |
1561 | cout << " Idx: " << Type->Label << endl; | |
1562 | } | |
1563 | ||
1564 | return true; | |
1565 | } | |
1566 | ||
1567 | cout << | |
1568 | _("Usage: apt-get [options] command\n" | |
1569 | " apt-get [options] install|remove pkg1 [pkg2 ...]\n" | |
1570 | " apt-get [options] source pkg1 [pkg2 ...]\n" | |
1571 | "\n" | |
1572 | "apt-get is a simple command line interface for downloading and\n" | |
1573 | "installing packages. The most frequently used commands are update\n" | |
1574 | "and install.\n" | |
1575 | "\n" | |
1576 | "Commands:\n" | |
1577 | " update - Retrieve new lists of packages\n" | |
1578 | " upgrade - Perform an upgrade\n" | |
1579 | " install - Install new packages (pkg is libc6 not libc6.deb)\n" | |
1580 | " remove - Remove packages\n" | |
12bffed7 | 1581 | " autoremove - Remove automatically all unused packages\n" |
73fc19d0 | 1582 | " purge - Remove packages and config files\n" |
b2e465d6 AL |
1583 | " source - Download source archives\n" |
1584 | " build-dep - Configure build-dependencies for source packages\n" | |
1585 | " dist-upgrade - Distribution upgrade, see apt-get(8)\n" | |
1586 | " dselect-upgrade - Follow dselect selections\n" | |
1587 | " clean - Erase downloaded archive files\n" | |
1588 | " autoclean - Erase old downloaded archive files\n" | |
1589 | " check - Verify that there are no broken dependencies\n" | |
5f967f2d MV |
1590 | " changelog - Download and display the changelog for the given package\n" |
1591 | " download - Download the binary package into the current directory\n" | |
b2e465d6 AL |
1592 | "\n" |
1593 | "Options:\n" | |
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; | |
0a8e3465 AL |
1611 | } |
1612 | /*}}}*/ | |
d7827aca AL |
1613 | // SigWinch - Window size change signal handler /*{{{*/ |
1614 | // --------------------------------------------------------------------- | |
1615 | /* */ | |
1616 | void SigWinch(int) | |
1617 | { | |
1618 | // Riped from GNU ls | |
1619 | #ifdef TIOCGWINSZ | |
1620 | struct winsize ws; | |
1621 | ||
1622 | if (ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col >= 5) | |
1623 | ScreenWidth = ws.ws_col - 1; | |
1624 | #endif | |
1625 | } | |
1626 | /*}}}*/ | |
b9179170 MV |
1627 | |
1628 | bool DoUpgrade(CommandLine &CmdL) | |
1629 | { | |
c678a044 | 1630 | if (_config->FindB("APT::Get::Upgrade-Allow-New", false) == true) |
b9179170 MV |
1631 | return DoUpgradeWithAllowNewPackages(CmdL); |
1632 | else | |
1633 | return DoUpgradeNoNewPackages(CmdL); | |
1634 | } | |
1635 | ||
92fcbfc1 | 1636 | int main(int argc,const char *argv[]) /*{{{*/ |
0a8e3465 | 1637 | { |
83d89a9f AL |
1638 | CommandLine::Dispatch Cmds[] = {{"update",&DoUpdate}, |
1639 | {"upgrade",&DoUpgrade}, | |
1640 | {"install",&DoInstall}, | |
1641 | {"remove",&DoInstall}, | |
24401c09 | 1642 | {"purge",&DoInstall}, |
74a05226 | 1643 | {"autoremove",&DoInstall}, |
d63a1458 JAK |
1644 | {"markauto",&DoMarkAuto}, |
1645 | {"unmarkauto",&DoMarkAuto}, | |
83d89a9f AL |
1646 | {"dist-upgrade",&DoDistUpgrade}, |
1647 | {"dselect-upgrade",&DoDSelectUpgrade}, | |
b2e465d6 | 1648 | {"build-dep",&DoBuildDep}, |
83d89a9f | 1649 | {"clean",&DoClean}, |
1bc849af | 1650 | {"autoclean",&DoAutoClean}, |
83d89a9f | 1651 | {"check",&DoCheck}, |
67111687 | 1652 | {"source",&DoSource}, |
459b5f5d | 1653 | {"download",&DoDownload}, |
a4c40430 | 1654 | {"changelog",&DoChangelog}, |
b2e465d6 | 1655 | {"moo",&DoMoo}, |
67111687 | 1656 | {"help",&ShowHelp}, |
83d89a9f | 1657 | {0,0}}; |
67111687 | 1658 | |
b9179170 MV |
1659 | std::vector<CommandLine::Args> Args = getCommandArgs("apt-get", CommandLine::GetCommand(Cmds, argc, argv)); |
1660 | ||
67111687 AL |
1661 | // Set up gettext support |
1662 | setlocale(LC_ALL,""); | |
1663 | textdomain(PACKAGE); | |
1664 | ||
0a8e3465 | 1665 | // Parse the command line and initialize the package library |
b9179170 | 1666 | CommandLine CmdL(Args.data(),_config); |
b2e465d6 AL |
1667 | if (pkgInitConfig(*_config) == false || |
1668 | CmdL.Parse(argc,argv) == false || | |
1669 | pkgInitSystem(*_config,_system) == false) | |
0a8e3465 | 1670 | { |
b2e465d6 AL |
1671 | if (_config->FindB("version") == true) |
1672 | ShowHelp(CmdL); | |
1673 | ||
0a8e3465 AL |
1674 | _error->DumpErrors(); |
1675 | return 100; | |
1676 | } | |
1677 | ||
1678 | // See if the help should be shown | |
1679 | if (_config->FindB("help") == true || | |
04aa15a8 | 1680 | _config->FindB("version") == true || |
0a8e3465 | 1681 | CmdL.FileSize() == 0) |
b2e465d6 AL |
1682 | { |
1683 | ShowHelp(CmdL); | |
1684 | return 0; | |
1685 | } | |
55a5a46c | 1686 | |
b9179170 MV |
1687 | // see if we are in simulate mode |
1688 | CheckSimulateMode(CmdL); | |
55a5a46c | 1689 | |
a9a5908d | 1690 | // Deal with stdout not being a tty |
c340d185 | 1691 | if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) |
a9a5908d | 1692 | _config->Set("quiet","1"); |
01b64152 | 1693 | |
0a8e3465 | 1694 | // Setup the output streams |
b9179170 | 1695 | InitOutput(); |
d7827aca AL |
1696 | |
1697 | // Setup the signals | |
1698 | signal(SIGPIPE,SIG_IGN); | |
1699 | signal(SIGWINCH,SigWinch); | |
1700 | SigWinch(0); | |
b2e465d6 | 1701 | |
0a8e3465 | 1702 | // Match the operation |
83d89a9f | 1703 | CmdL.DispatchArg(Cmds); |
0a8e3465 AL |
1704 | |
1705 | // Print any errors or warnings found during parsing | |
65beb572 DK |
1706 | bool const Errors = _error->PendingError(); |
1707 | if (_config->FindI("quiet",0) > 0) | |
0a8e3465 | 1708 | _error->DumpErrors(); |
65beb572 DK |
1709 | else |
1710 | _error->DumpErrors(GlobalError::DEBUG); | |
1711 | return Errors == true ? 100 : 0; | |
0a8e3465 | 1712 | } |
92fcbfc1 | 1713 | /*}}}*/ |