1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.156 2004/08/28 01:05:16 mdz Exp $
4 /* ######################################################################
6 apt-get - Cover for dpkg
8 This is an allout cover for dpkg implementing a safer front end. It is
9 based largely on libapt-pkg.
11 The syntax is different,
12 apt-get [opt] command [things]
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 - Powerful upgrader designed to handle the issues with
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
25 ##################################################################### */
27 // Include Files /*{{{*/
30 #include <apt-pkg/acquire-item.h>
31 #include <apt-pkg/algorithms.h>
32 #include <apt-pkg/aptconfiguration.h>
33 #include <apt-pkg/cachefile.h>
34 #include <apt-pkg/cacheset.h>
35 #include <apt-pkg/clean.h>
36 #include <apt-pkg/cmndline.h>
37 #include <apt-pkg/debmetaindex.h>
38 #include <apt-pkg/depcache.h>
39 #include <apt-pkg/error.h>
40 #include <apt-pkg/fileutl.h>
41 #include <apt-pkg/indexfile.h>
42 #include <apt-pkg/indexrecords.h>
43 #include <apt-pkg/init.h>
44 #include <apt-pkg/md5.h>
45 #include <apt-pkg/metaindex.h>
46 #include <apt-pkg/pkgrecords.h>
47 #include <apt-pkg/pkgsystem.h>
48 #include <apt-pkg/progress.h>
49 #include <apt-pkg/sourcelist.h>
50 #include <apt-pkg/srcrecords.h>
51 #include <apt-pkg/strutl.h>
52 #include <apt-pkg/version.h>
53 #include <apt-pkg/acquire.h>
54 #include <apt-pkg/configuration.h>
55 #include <apt-pkg/macros.h>
56 #include <apt-pkg/pkgcache.h>
57 #include <apt-pkg/cacheiterators.h>
58 #include <apt-pkg/upgrade.h>
59 #include <apt-pkg/sptr.h>
61 #include <apt-private/acqprogress.h>
62 #include <apt-private/private-cacheset.h>
63 #include <apt-private/private-cachefile.h>
64 #include <apt-private/private-cmndline.h>
65 #include <apt-private/private-download.h>
66 #include <apt-private/private-install.h>
67 #include <apt-private/private-main.h>
68 #include <apt-private/private-moo.h>
69 #include <apt-private/private-output.h>
70 #include <apt-private/private-update.h>
71 #include <apt-private/private-upgrade.h>
72 #include <apt-private/private-utils.h>
80 #include <sys/ioctl.h>
100 // TryToInstallBuildDep - Try to install a single package /*{{{*/
101 // ---------------------------------------------------------------------
102 /* This used to be inlined in DoInstall, but with the advent of regex package
103 name matching it was split out.. */
104 static bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg
,pkgCacheFile
&Cache
,
105 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
106 bool AllowFail
= true)
108 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0)
110 CacheSetHelperAPTGet
helper(c1out
);
111 helper
.showErrors(false);
112 pkgCache::VerIterator Ver
= helper
.canNotFindNewestVer(Cache
, Pkg
);
113 if (Ver
.end() == false)
114 Pkg
= Ver
.ParentPkg();
115 else if (helper
.showVirtualPackageErrors(Cache
) == false)
119 if (_config
->FindB("Debug::BuildDeps",false) == true)
122 cout
<< " Trying to remove " << Pkg
<< endl
;
124 cout
<< " Trying to install " << Pkg
<< endl
;
129 TryToRemove
RemoveAction(Cache
, &Fix
);
130 RemoveAction(Pkg
.VersionList());
131 } else if (Cache
[Pkg
].CandidateVer
!= 0) {
132 TryToInstall
InstallAction(Cache
, &Fix
, BrokenFix
);
133 InstallAction(Cache
[Pkg
].CandidateVerIter(Cache
));
134 InstallAction
.doAutoInstall();
141 // GetReleaseFileForSourceRecord - Return Suite for the given srcrecord /*{{{*/
142 static pkgCache::RlsFileIterator
GetReleaseFileForSourceRecord(CacheFile
&CacheFile
,
143 pkgSourceList
*SrcList
, pkgSrcRecords::Parser
*Parse
)
145 // try to find release
146 const pkgIndexFile
& CurrentIndexFile
= Parse
->Index();
148 for (pkgSourceList::const_iterator S
= SrcList
->begin();
149 S
!= SrcList
->end(); ++S
)
151 vector
<pkgIndexFile
*> *Indexes
= (*S
)->GetIndexFiles();
152 for (vector
<pkgIndexFile
*>::const_iterator IF
= Indexes
->begin();
153 IF
!= Indexes
->end(); ++IF
)
155 if (&CurrentIndexFile
== (*IF
))
156 return (*S
)->FindInCache(CacheFile
, false);
159 return pkgCache::RlsFileIterator(CacheFile
);
162 // FindSrc - Find a source record /*{{{*/
163 // ---------------------------------------------------------------------
165 #if APT_PKG_ABI >= 413
166 static pkgSrcRecords::Parser
*FindSrc(const char *Name
,
168 static pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
170 pkgSrcRecords
&SrcRecs
,string
&Src
,
171 CacheFile
&CacheFile
)
173 string VerTag
, UserRequestedVerTag
;
175 string RelTag
= _config
->Find("APT::Default-Release");
176 string TmpSrc
= Name
;
177 pkgDepCache
*Cache
= CacheFile
.GetDepCache();
180 size_t found
= TmpSrc
.find_last_of("/");
181 if (found
!= string::npos
)
183 RelTag
= TmpSrc
.substr(found
+1);
184 TmpSrc
= TmpSrc
.substr(0,found
);
186 // extract the version
187 found
= TmpSrc
.find_last_of("=");
188 if (found
!= string::npos
)
190 VerTag
= UserRequestedVerTag
= TmpSrc
.substr(found
+1);
191 TmpSrc
= TmpSrc
.substr(0,found
);
194 found
= TmpSrc
.find_last_of(":");
195 if (found
!= string::npos
)
197 ArchTag
= TmpSrc
.substr(found
+1);
198 TmpSrc
= TmpSrc
.substr(0,found
);
201 /* Lookup the version of the package we would install if we were to
202 install a version and determine the source package name, then look
203 in the archive for a source package of the same name. */
204 bool MatchSrcOnly
= _config
->FindB("APT::Get::Only-Source");
205 pkgCache::PkgIterator Pkg
;
207 Pkg
= Cache
->FindPkg(TmpSrc
, ArchTag
);
209 Pkg
= Cache
->FindPkg(TmpSrc
);
211 // if we can't find a package but the user qualified with a arch,
213 if (Pkg
.end() && ArchTag
!= "")
216 _error
->Error(_("Can not find a package for architecture '%s'"),
221 if (MatchSrcOnly
== false && Pkg
.end() == false)
223 if(VerTag
!= "" || RelTag
!= "" || ArchTag
!= "")
226 // we have a default release, try to locate the pkg. we do it like
227 // this because GetCandidateVer() will not "downgrade", that means
228 // "apt-get source -t stable apt" won't work on a unstable system
229 for (pkgCache::VerIterator Ver
= Pkg
.VersionList();; ++Ver
)
231 // try first only exact matches, later fuzzy matches
232 if (Ver
.end() == true)
237 Ver
= Pkg
.VersionList();
238 // exit right away from the Pkg.VersionList() loop if we
239 // don't have any versions
240 if (Ver
.end() == true)
244 // ignore arches that are not for us
245 if (ArchTag
!= "" && Ver
.Arch() != ArchTag
)
248 // pick highest version for the arch unless the user wants
250 if (ArchTag
!= "" && VerTag
== "" && RelTag
== "")
251 if(Cache
->VS().CmpVersion(VerTag
, Ver
.VerStr()) < 0)
252 VerTag
= Ver
.VerStr();
254 // We match against a concrete version (or a part of this version)
255 if (VerTag
.empty() == false &&
256 (fuzzy
== true || Cache
->VS().CmpVersion(VerTag
, Ver
.VerStr()) != 0) && // exact match
257 (fuzzy
== false || strncmp(VerTag
.c_str(), Ver
.VerStr(), VerTag
.size()) != 0)) // fuzzy match
260 for (pkgCache::VerFileIterator VF
= Ver
.FileList();
261 VF
.end() == false; ++VF
)
263 /* If this is the status file, and the current version is not the
264 version in the status file (ie it is not installed, or somesuch)
265 then it is not a candidate for installation, ever. This weeds
266 out bogus entries that may be due to config-file states, or
268 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) ==
269 pkgCache::Flag::NotSource
&& Pkg
.CurrentVer() != Ver
)
272 // or we match against a release
273 if(VerTag
.empty() == false ||
274 (VF
.File().Archive() != 0 && VF
.File().Archive() == RelTag
) ||
275 (VF
.File().Codename() != 0 && VF
.File().Codename() == RelTag
))
277 // the Version we have is possibly fuzzy or includes binUploads,
278 // so we use the Version of the SourcePkg (empty if same as package)
279 #if APT_PKG_ABI >= 413
280 Src
= Ver
.SourcePkgName();
281 VerTag
= Ver
.SourceVerStr();
283 pkgRecords::Parser
&Parse
= Recs
.Lookup(VF
);
284 Src
= Parse
.SourcePkg();
285 // no SourcePkg name, so it is the "binary" name
286 if (Src
.empty() == true)
288 VerTag
= Parse
.SourceVer();
289 if (VerTag
.empty() == true)
290 VerTag
= Ver
.VerStr();
295 if (Src
.empty() == false)
300 if (Src
== "" && ArchTag
!= "")
303 _error
->Error(_("Can not find a package '%s' with version '%s'"),
304 Pkg
.FullName().c_str(), VerTag
.c_str());
306 _error
->Error(_("Can not find a package '%s' with release '%s'"),
307 Pkg
.FullName().c_str(), RelTag
.c_str());
313 if (Src
.empty() == true)
315 // if we don't have found a fitting package yet so we will
316 // choose a good candidate and proceed with that.
317 // Maybe we will find a source later on with the right VerTag
319 pkgCache::VerIterator Ver
= Cache
->GetCandidateVer(Pkg
);
320 if (Ver
.end() == false)
322 #if APT_PKG_ABI >= 413
323 if (strcmp(Ver
.SourcePkgName(),Ver
.ParentPkg().Name()) != 0)
324 Src
= Ver
.SourcePkgName();
325 if (VerTag
.empty() == true && strcmp(Ver
.SourceVerStr(),Ver
.VerStr()) != 0)
326 VerTag
= Ver
.SourceVerStr();
328 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
329 Src
= Parse
.SourcePkg();
330 if (VerTag
.empty() == true)
331 VerTag
= Parse
.SourceVer();
337 if (Src
.empty() == true)
343 /* if we have a source pkg name, make sure to only search
344 for srcpkg names, otherwise apt gets confused if there
345 is a binary package "pkg1" and a source package "pkg1"
346 with the same name but that comes from different packages */
350 ioprintf(c1out
, _("Picking '%s' as source package instead of '%s'\n"), Src
.c_str(), TmpSrc
.c_str());
355 pkgSrcRecords::Parser
*Last
= 0;
356 unsigned long Offset
= 0;
358 pkgSourceList
*SrcList
= CacheFile
.GetSourceList();
360 /* Iterate over all of the hits, which includes the resulting
361 binary packages in the search */
362 pkgSrcRecords::Parser
*Parse
;
366 while ((Parse
= SrcRecs
.Find(Src
.c_str(), MatchSrcOnly
)) != 0)
368 const string Ver
= Parse
->Version();
370 // See if we need to look for a specific release tag
371 if (RelTag
!= "" && UserRequestedVerTag
== "")
373 pkgCache::RlsFileIterator
const Rls
= GetReleaseFileForSourceRecord(CacheFile
, SrcList
, Parse
);
374 if (Rls
.end() == false)
376 if ((Rls
->Archive
!= 0 && RelTag
== Rls
.Archive()) ||
377 (Rls
->Codename
!= 0 && RelTag
== Rls
.Codename()))
380 Offset
= Parse
->Offset();
386 // Ignore all versions which doesn't fit
387 if (VerTag
.empty() == false &&
388 Cache
->VS().CmpVersion(VerTag
, Ver
) != 0) // exact match
391 // Newer version or an exact match? Save the hit
392 if (Last
== 0 || Cache
->VS().CmpVersion(Version
,Ver
) < 0) {
394 Offset
= Parse
->Offset();
398 // was the version check above an exact match?
399 // If so, we don't need to look further
400 if (VerTag
.empty() == false && (VerTag
== Ver
))
403 if (UserRequestedVerTag
== "" && Version
!= "" && RelTag
!= "")
404 ioprintf(c1out
, "Selected version '%s' (%s) for %s\n",
405 Version
.c_str(), RelTag
.c_str(), Src
.c_str());
407 if (Last
!= 0 || VerTag
.empty() == true)
409 _error
->Error(_("Can not find version '%s' of package '%s'"), VerTag
.c_str(), TmpSrc
.c_str());
413 if (Last
== 0 || Last
->Jump(Offset
) == false)
419 /* mark packages as automatically/manually installed. {{{*/
420 static bool DoMarkAuto(CommandLine
&CmdL
)
423 int AutoMarkChanged
= 0;
424 OpTextProgress progress
;
426 if (Cache
.Open() == false)
429 if (strcasecmp(CmdL
.FileList
[0],"markauto") == 0)
431 else if (strcasecmp(CmdL
.FileList
[0],"unmarkauto") == 0)
434 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
437 // Locate the package
438 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
439 if (Pkg
.end() == true) {
440 return _error
->Error(_("Couldn't find package %s"),S
);
445 ioprintf(c1out
,_("%s set to manually installed.\n"), Pkg
.Name());
447 ioprintf(c1out
,_("%s set to automatically installed.\n"),
450 Cache
->MarkAuto(Pkg
,Action
);
455 _error
->Notice(_("This command is deprecated. Please use 'apt-mark auto' and 'apt-mark manual' instead."));
457 if (AutoMarkChanged
&& ! _config
->FindB("APT::Get::Simulate",false))
458 return Cache
->writeStateFile(NULL
);
462 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
463 // ---------------------------------------------------------------------
464 /* Follows dselect's selections */
465 static bool DoDSelectUpgrade(CommandLine
&)
468 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
471 pkgDepCache::ActionGroup
group(Cache
);
473 // Install everything with the install flag set
474 pkgCache::PkgIterator I
= Cache
->PkgBegin();
475 for (;I
.end() != true; ++I
)
477 /* Install the package only if it is a new install, the autoupgrader
478 will deal with the rest */
479 if (I
->SelectedState
== pkgCache::State::Install
)
480 Cache
->MarkInstall(I
,false);
483 /* Now install their deps too, if we do this above then order of
484 the status file is significant for | groups */
485 for (I
= Cache
->PkgBegin();I
.end() != true; ++I
)
487 /* Install the package only if it is a new install, the autoupgrader
488 will deal with the rest */
489 if (I
->SelectedState
== pkgCache::State::Install
)
490 Cache
->MarkInstall(I
,true);
493 // Apply erasures now, they override everything else.
494 for (I
= Cache
->PkgBegin();I
.end() != true; ++I
)
497 if (I
->SelectedState
== pkgCache::State::DeInstall
||
498 I
->SelectedState
== pkgCache::State::Purge
)
499 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
502 /* Resolve any problems that dselect created, allupgrade cannot handle
503 such things. We do so quite aggressively too.. */
504 if (Cache
->BrokenCount() != 0)
506 pkgProblemResolver
Fix(Cache
);
508 // Hold back held packages.
509 if (_config
->FindB("APT::Ignore-Hold",false) == false)
511 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; ++I
)
513 if (I
->SelectedState
== pkgCache::State::Hold
)
521 if (Fix
.Resolve() == false)
523 ShowBroken(c1out
,Cache
,false);
524 return _error
->Error(_("Internal error, problem resolver broke stuff"));
528 // Now upgrade everything
529 if (APT::Upgrade::Upgrade(Cache
, APT::Upgrade::FORBID_REMOVE_PACKAGES
| APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES
) == false)
531 ShowBroken(c1out
,Cache
,false);
532 return _error
->Error(_("Internal error, problem resolver broke stuff"));
535 return InstallPackages(Cache
,false);
538 // DoClean - Remove download archives /*{{{*/
539 // ---------------------------------------------------------------------
541 static bool DoClean(CommandLine
&)
543 std::string
const archivedir
= _config
->FindDir("Dir::Cache::archives");
544 std::string
const listsdir
= _config
->FindDir("Dir::state::lists");
546 if (_config
->FindB("APT::Get::Simulate") == true)
548 std::string
const pkgcache
= _config
->FindFile("Dir::cache::pkgcache");
549 std::string
const srcpkgcache
= _config
->FindFile("Dir::cache::srcpkgcache");
550 cout
<< "Del " << archivedir
<< "* " << archivedir
<< "partial/*"<< endl
551 << "Del " << listsdir
<< "partial/*" << endl
552 << "Del " << pkgcache
<< " " << srcpkgcache
<< endl
;
557 Fetcher
.GetLock(archivedir
);
558 Fetcher
.Clean(archivedir
);
559 Fetcher
.Clean(archivedir
+ "partial/");
561 Fetcher
.GetLock(listsdir
);
562 Fetcher
.Clean(listsdir
+ "partial/");
564 pkgCacheFile::RemoveCaches();
569 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
570 // ---------------------------------------------------------------------
571 /* This is similar to clean but it only purges things that cannot be
572 downloaded, that is old versions of cached packages. */
573 class LogCleaner
: public pkgArchiveCleaner
576 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
) APT_OVERRIDE
578 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
580 if (_config
->FindB("APT::Get::Simulate") == false)
585 static bool DoAutoClean(CommandLine
&)
587 // Lock the archive directory
589 if (_config
->FindB("Debug::NoLocking",false) == false)
591 int lock_fd
= GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock");
593 return _error
->Error(_("Unable to lock the download directory"));
598 if (Cache
.Open() == false)
603 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
604 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
607 // DoDownload - download a binary /*{{{*/
608 // ---------------------------------------------------------------------
609 static bool DoDownload(CommandLine
&CmdL
)
612 if (Cache
.ReadOnlyOpen() == false)
615 APT::CacheSetHelper helper
;
616 APT::VersionSet verset
= APT::VersionSet::FromCommandLine(Cache
,
617 CmdL
.FileList
+ 1, APT::CacheSetHelper::CANDIDATE
, helper
);
619 if (verset
.empty() == true)
622 AcqTextStatus
Stat(std::cout
, ScreenWidth
,_config
->FindI("quiet",0));
623 pkgAcquire
Fetcher(&Stat
);
625 pkgRecords
Recs(Cache
);
626 pkgSourceList
*SrcList
= Cache
.GetSourceList();
628 // reuse the usual acquire methods for deb files, but don't drop them into
629 // the usual directories - keep everything in the current directory
630 std::vector
<std::string
> storefile(verset
.size());
631 std::string
const cwd
= SafeGetCWD();
632 _config
->Set("Dir::Cache::Archives", cwd
);
634 for (APT::VersionSet::const_iterator Ver
= verset
.begin();
635 Ver
!= verset
.end(); ++Ver
, ++i
)
637 pkgAcquire::Item
*I
= new pkgAcqArchive(&Fetcher
, SrcList
, &Recs
, *Ver
, storefile
[i
]);
638 if (storefile
[i
].empty())
640 std::string
const filename
= cwd
+ flNotDir(storefile
[i
]);
641 storefile
[i
].assign(filename
);
642 I
->DestFile
.assign(filename
);
645 // Just print out the uris and exit if the --print-uris flag was used
646 if (_config
->FindB("APT::Get::Print-URIs") == true)
648 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
649 for (; I
!= Fetcher
.UriEnd(); ++I
)
650 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
651 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
655 // Disable drop-privs if "_apt" can not write to the target dir
656 CheckDropPrivsMustBeDisabled(Fetcher
);
658 if (_error
->PendingError() == true || CheckAuth(Fetcher
, false) == false)
662 if (AcquireRun(Fetcher
, 0, &Failed
, NULL
) == false)
665 // copy files in local sources to the current directory
666 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); ++I
)
668 std::string
const filename
= cwd
+ flNotDir((*I
)->DestFile
);
669 if ((*I
)->Local
== true &&
670 filename
!= (*I
)->DestFile
&&
671 (*I
)->Status
== pkgAcquire::Item::StatDone
)
673 std::ifstream
src((*I
)->DestFile
.c_str(), std::ios::binary
);
674 std::ofstream
dst(filename
.c_str(), std::ios::binary
);
678 return Failed
== false;
681 // DoCheck - Perform the check operation /*{{{*/
682 // ---------------------------------------------------------------------
683 /* Opening automatically checks the system, this command is mostly used
685 static bool DoCheck(CommandLine
&)
694 // DoSource - Fetch a source archive /*{{{*/
695 // ---------------------------------------------------------------------
696 /* Fetch souce packages */
704 static bool DoSource(CommandLine
&CmdL
)
707 if (Cache
.Open(false) == false)
710 if (CmdL
.FileSize() <= 1)
711 return _error
->Error(_("Must specify at least one package to fetch source for"));
713 // Read the source list
714 if (Cache
.BuildSourceList() == false)
716 pkgSourceList
*List
= Cache
.GetSourceList();
718 // Create the text record parsers
719 #if APT_PKG_ABI < 413
720 pkgRecords
Recs(Cache
);
722 pkgSrcRecords
SrcRecs(*List
);
723 if (_error
->PendingError() == true)
726 // Create the download object
727 AcqTextStatus
Stat(std::cout
, ScreenWidth
,_config
->FindI("quiet",0));
728 pkgAcquire
Fetcher(&Stat
);
730 SPtrArray
<DscFile
> Dsc
= new DscFile
[CmdL
.FileSize()];
732 // insert all downloaded uris into this set to avoid downloading them
736 // Diff only mode only fetches .diff files
737 bool const diffOnly
= _config
->FindB("APT::Get::Diff-Only", false);
738 // Tar only mode only fetches .tar files
739 bool const tarOnly
= _config
->FindB("APT::Get::Tar-Only", false);
740 // Dsc only mode only fetches .dsc files
741 bool const dscOnly
= _config
->FindB("APT::Get::Dsc-Only", false);
743 // Load the requestd sources into the fetcher
745 std::vector
<std::string
> UntrustedList
;
746 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
749 #if APT_PKG_ABI >= 413
750 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,SrcRecs
,Src
,Cache
);
752 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,Cache
);
755 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
758 if (Last
->Index().IsTrusted() == false)
759 UntrustedList
.push_back(Src
);
761 string srec
= Last
->AsStr();
762 string::size_type pos
= srec
.find("\nVcs-");
763 while (pos
!= string::npos
)
765 pos
+= strlen("\nVcs-");
766 string vcs
= srec
.substr(pos
,srec
.find(":",pos
)-pos
);
769 pos
= srec
.find("\nVcs-", pos
);
772 pos
+= vcs
.length()+2;
773 string::size_type epos
= srec
.find("\n", pos
);
774 string uri
= srec
.substr(pos
,epos
-pos
).c_str();
775 ioprintf(c1out
, _("NOTICE: '%s' packaging is maintained in "
776 "the '%s' version control system at:\n"
778 Src
.c_str(), vcs
.c_str(), uri
.c_str());
780 ioprintf(c1out
,_("Please use:\n"
782 "to retrieve the latest (possibly unreleased) "
783 "updates to the package.\n"),
789 vector
<pkgSrcRecords::File2
> Lst
;
790 if (Last
->Files2(Lst
) == false) {
794 // Load them into the fetcher
795 for (vector
<pkgSrcRecords::File2
>::const_iterator I
= Lst
.begin();
798 // Try to guess what sort of file it is we are getting.
799 if (I
->Type
== "dsc")
801 Dsc
[J
].Package
= Last
->Package();
802 Dsc
[J
].Version
= Last
->Version();
803 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
806 // Handle the only options so that multiple can be used at once
807 if (diffOnly
== true || tarOnly
== true || dscOnly
== true)
809 if ((diffOnly
== true && I
->Type
== "diff") ||
810 (tarOnly
== true && I
->Type
== "tar") ||
811 (dscOnly
== true && I
->Type
== "dsc"))
812 ; // Fine, we want this file downloaded
817 // don't download the same uri twice (should this be moved to
818 // the fetcher interface itself?)
819 if(queued
.find(Last
->Index().ArchiveURI(I
->Path
)) != queued
.end())
821 queued
.insert(Last
->Index().ArchiveURI(I
->Path
));
823 // check if we have a file with that md5 sum already localy
824 std::string localFile
= flNotDir(I
->Path
);
825 if (FileExists(localFile
) == true)
826 if(I
->Hashes
.VerifyFile(localFile
) == true)
828 ioprintf(c1out
,_("Skipping already downloaded file '%s'\n"),
833 // see if we have a hash (Acquire::ForceHash is the only way to have none)
834 if (I
->Hashes
.usable() == false && _config
->FindB("APT::Get::AllowUnauthenticated",false) == false)
836 ioprintf(c1out
, "Skipping download of file '%s' as requested hashsum is not available for authentication\n",
841 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
842 I
->Hashes
, I
->FileSize
, Last
->Index().SourceInfo(*Last
,*I
), Src
);
846 // Display statistics
847 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
848 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
849 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
851 if (CheckFreeSpaceBeforeDownload(".", (FetchBytes
- FetchPBytes
)) == false)
855 if (DebBytes
!= FetchBytes
)
856 //TRANSLATOR: The required space between number and unit is already included
857 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
858 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
859 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
861 //TRANSLATOR: The required space between number and unit is already included
862 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
863 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
864 SizeToStr(DebBytes
).c_str());
866 if (_config
->FindB("APT::Get::Simulate",false) == true)
868 for (unsigned I
= 0; I
!= J
; I
++)
869 ioprintf(cout
,_("Fetch source %s\n"),Dsc
[I
].Package
.c_str());
873 // Just print out the uris an exit if the --print-uris flag was used
874 if (_config
->FindB("APT::Get::Print-URIs") == true)
876 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
877 for (; I
!= Fetcher
.UriEnd(); ++I
)
878 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
879 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
883 // Disable drop-privs if "_apt" can not write to the target dir
884 CheckDropPrivsMustBeDisabled(Fetcher
);
886 // check authentication status of the source as well
887 if (UntrustedList
.empty() == false && AuthPrompt(UntrustedList
, false) == false)
892 if (AcquireRun(Fetcher
, 0, &Failed
, NULL
) == false || Failed
== true)
894 return _error
->Error(_("Failed to fetch some archives."));
897 if (_config
->FindB("APT::Get::Download-only",false) == true)
899 c1out
<< _("Download complete and in download only mode") << endl
;
903 // Unpack the sources
904 pid_t Process
= ExecFork();
908 bool const fixBroken
= _config
->FindB("APT::Get::Fix-Broken", false);
909 for (unsigned I
= 0; I
!= J
; ++I
)
911 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
913 // Diff only mode only fetches .diff files
914 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
915 _config
->FindB("APT::Get::Tar-Only",false) == true ||
916 Dsc
[I
].Dsc
.empty() == true)
919 // See if the package is already unpacked
921 if (fixBroken
== false && stat(Dir
.c_str(),&Stat
) == 0 &&
922 S_ISDIR(Stat
.st_mode
) != 0)
924 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
930 std::string
const sourceopts
= _config
->Find("DPkg::Source-Options", "-x");
932 strprintf(S
, "%s %s %s",
933 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
934 sourceopts
.c_str(), Dsc
[I
].Dsc
.c_str());
935 if (system(S
.c_str()) != 0)
937 fprintf(stderr
, _("Unpack command '%s' failed.\n"), S
.c_str());
938 fprintf(stderr
, _("Check if the 'dpkg-dev' package is installed.\n"));
943 // Try to compile it with dpkg-buildpackage
944 if (_config
->FindB("APT::Get::Compile",false) == true)
946 string buildopts
= _config
->Find("APT::Get::Host-Architecture");
947 if (buildopts
.empty() == false)
948 buildopts
= "-a" + buildopts
+ " ";
950 // get all active build profiles
951 std::string
const profiles
= APT::Configuration::getBuildProfilesString();
952 if (profiles
.empty() == false)
953 buildopts
.append(" -P").append(profiles
).append(" ");
955 buildopts
.append(_config
->Find("DPkg::Build-Options","-b -uc"));
957 // Call dpkg-buildpackage
959 strprintf(S
, "cd %s && %s %s",
961 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
964 if (system(S
.c_str()) != 0)
966 fprintf(stderr
, _("Build command '%s' failed.\n"), S
.c_str());
975 // Wait for the subprocess
977 while (waitpid(Process
,&Status
,0) != Process
)
981 return _error
->Errno("waitpid","Couldn't wait for subprocess");
984 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
985 return _error
->Error(_("Child process failed"));
990 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
991 // ---------------------------------------------------------------------
992 /* This function will look at the build depends list of the given source
993 package and install the necessary packages to make it true, or fail. */
994 static bool DoBuildDep(CommandLine
&CmdL
)
998 _config
->Set("APT::Install-Recommends", false);
1000 if (Cache
.Open(true) == false)
1003 if (CmdL
.FileSize() <= 1)
1004 return _error
->Error(_("Must specify at least one package to check builddeps for"));
1006 // Read the source list
1007 if (Cache
.BuildSourceList() == false)
1009 pkgSourceList
*List
= Cache
.GetSourceList();
1011 // Create the text record parsers
1012 pkgSrcRecords
SrcRecs(*List
);
1013 if (_error
->PendingError() == true)
1016 bool StripMultiArch
;
1017 string hostArch
= _config
->Find("APT::Get::Host-Architecture");
1018 if (hostArch
.empty() == false)
1020 std::vector
<std::string
> archs
= APT::Configuration::getArchitectures();
1021 if (std::find(archs
.begin(), archs
.end(), hostArch
) == archs
.end())
1022 return _error
->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch
.c_str());
1023 StripMultiArch
= false;
1026 StripMultiArch
= true;
1029 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1032 pkgSrcRecords::Parser
*Last
= 0;
1033 SPtr
<pkgSrcRecords::Parser
> LastOwner
;
1035 // an unpacked debian source tree
1036 using APT::String::Startswith
;
1037 if ((Startswith(*I
, "./") || Startswith(*I
, "/")) &&
1038 DirectoryExists(*I
))
1040 ioprintf(c1out
, _("Note, using directory '%s' to get the build dependencies\n"), *I
);
1041 // FIXME: how can we make this more elegant?
1042 std::string TypeName
= "Debian control file";
1043 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GetType(TypeName
.c_str());
1045 LastOwner
= Last
= Type
->CreateSrcPkgParser(*I
);
1047 // if its a local file (e.g. .dsc) use this
1048 else if (FileExists(*I
))
1050 ioprintf(c1out
, _("Note, using file '%s' to get the build dependencies\n"), *I
);
1052 // see if we can get a parser for this pkgIndexFile type
1053 string TypeName
= "Debian " + flExtension(*I
) + " file";
1054 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GetType(TypeName
.c_str());
1056 LastOwner
= Last
= Type
->CreateSrcPkgParser(*I
);
1058 // normal case, search the cache for the source file
1059 #if APT_PKG_ABI >= 413
1060 Last
= FindSrc(*I
,SrcRecs
,Src
,Cache
);
1062 Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,Cache
);
1067 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1069 // Process the build-dependencies
1070 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
1071 // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary
1072 if (hostArch
.empty() == false)
1074 std::string nativeArch
= _config
->Find("APT::Architecture");
1075 _config
->Set("APT::Architecture", hostArch
);
1076 bool Success
= Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only", false), StripMultiArch
);
1077 _config
->Set("APT::Architecture", nativeArch
);
1078 if (Success
== false)
1079 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
1081 else if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only", false), StripMultiArch
) == false)
1082 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
1084 // Also ensure that build-essential packages are present
1085 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
1088 for (; Opts
; Opts
= Opts
->Next
)
1090 if (Opts
->Value
.empty() == true)
1093 pkgSrcRecords::Parser::BuildDepRec rec
;
1094 rec
.Package
= Opts
->Value
;
1095 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
1097 BuildDeps
.push_back(rec
);
1100 if (BuildDeps
.empty() == true)
1102 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
1106 // Install the requested packages
1107 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
1108 pkgProblemResolver
Fix(Cache
);
1109 bool skipAlternatives
= false; // skip remaining alternatives in an or group
1110 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); ++D
)
1112 bool hasAlternatives
= (((*D
).Op
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
);
1114 if (skipAlternatives
== true)
1117 * if there are alternatives, we've already picked one, so skip
1120 * TODO: this means that if there's a build-dep on A|B and B is
1121 * installed, we'll still try to install A; more importantly,
1122 * if A is currently broken, we cannot go back and try B. To fix
1123 * this would require we do a Resolve cycle for each package we
1124 * add to the install list. Ugh
1126 if (!hasAlternatives
)
1127 skipAlternatives
= false; // end of or group
1131 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1132 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1134 pkgCache::GrpIterator Grp
= Cache
->FindGrp((*D
).Package
);
1135 // Build-conflicts on unknown packages are silently ignored
1136 if (Grp
.end() == true)
1139 for (pkgCache::PkgIterator Pkg
= Grp
.PackageList(); Pkg
.end() == false; Pkg
= Grp
.NextPkg(Pkg
))
1141 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1143 * Remove if we have an installed version that satisfies the
1146 if (IV
.end() == false &&
1147 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1148 TryToInstallBuildDep(Pkg
,Cache
,Fix
,true,false);
1151 else // BuildDep || BuildDepIndep
1153 if (_config
->FindB("Debug::BuildDeps",false) == true)
1154 cout
<< "Looking for " << (*D
).Package
<< "...\n";
1156 pkgCache::PkgIterator Pkg
;
1159 if (StripMultiArch
== false && D
->Type
!= pkgSrcRecords::Parser::BuildDependIndep
)
1161 size_t const colon
= D
->Package
.find(":");
1162 if (colon
!= string::npos
)
1164 if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0 || strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1165 Pkg
= Cache
->FindPkg(D
->Package
.substr(0,colon
));
1167 Pkg
= Cache
->FindPkg(D
->Package
);
1170 Pkg
= Cache
->FindPkg(D
->Package
, hostArch
);
1172 // a bad version either is invalid or doesn't satify dependency
1173 #define BADVER(Ver) (Ver.end() == true || \
1174 (D->Version.empty() == false && \
1175 Cache->VS().CheckDep(Ver.VerStr(),D->Op,D->Version.c_str()) == false))
1177 APT::VersionList verlist
;
1178 if (Pkg
.end() == false)
1180 pkgCache::VerIterator Ver
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1181 if (BADVER(Ver
) == false)
1182 verlist
.insert(Ver
);
1183 Ver
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1184 if (BADVER(Ver
) == false)
1185 verlist
.insert(Ver
);
1187 if (verlist
.empty() == true)
1189 pkgCache::PkgIterator BuildPkg
= Cache
->FindPkg(D
->Package
, "native");
1190 if (BuildPkg
.end() == false && Pkg
!= BuildPkg
)
1192 pkgCache::VerIterator Ver
= (*Cache
)[BuildPkg
].InstVerIter(*Cache
);
1193 if (BADVER(Ver
) == false)
1194 verlist
.insert(Ver
);
1195 Ver
= (*Cache
)[BuildPkg
].CandidateVerIter(*Cache
);
1196 if (BADVER(Ver
) == false)
1197 verlist
.insert(Ver
);
1203 // We need to decide if host or build arch, so find a version we can look at
1204 APT::VersionList::const_iterator Ver
= verlist
.begin();
1205 for (; Ver
!= verlist
.end(); ++Ver
)
1208 if (Ver
->MultiArch
== pkgCache::Version::None
|| Ver
->MultiArch
== pkgCache::Version::All
)
1210 if (colon
== string::npos
)
1211 Pkg
= Ver
.ParentPkg().Group().FindPkg(hostArch
);
1212 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0)
1213 forbidden
= "Multi-Arch: none";
1214 else if (strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1215 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1217 else if (Ver
->MultiArch
== pkgCache::Version::Same
)
1219 if (colon
== string::npos
)
1220 Pkg
= Ver
.ParentPkg().Group().FindPkg(hostArch
);
1221 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0)
1222 forbidden
= "Multi-Arch: same";
1223 else if (strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1224 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1226 else if ((Ver
->MultiArch
& pkgCache::Version::Foreign
) == pkgCache::Version::Foreign
)
1228 if (colon
== string::npos
)
1229 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1230 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0 ||
1231 strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1232 forbidden
= "Multi-Arch: foreign";
1234 else if ((Ver
->MultiArch
& pkgCache::Version::Allowed
) == pkgCache::Version::Allowed
)
1236 if (colon
== string::npos
)
1237 Pkg
= Ver
.ParentPkg().Group().FindPkg(hostArch
);
1238 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0)
1240 // prefer any installed over preferred non-installed architectures
1241 pkgCache::GrpIterator Grp
= Ver
.ParentPkg().Group();
1242 // we don't check for version here as we are better of with upgrading than remove and install
1243 for (Pkg
= Grp
.PackageList(); Pkg
.end() == false; Pkg
= Grp
.NextPkg(Pkg
))
1244 if (Pkg
.CurrentVer().end() == false)
1246 if (Pkg
.end() == true)
1247 Pkg
= Grp
.FindPreferredPkg(true);
1249 else if (strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1250 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1253 if (forbidden
.empty() == false)
1255 if (_config
->FindB("Debug::BuildDeps",false) == true)
1256 cout
<< D
->Package
.substr(colon
, string::npos
) << " is not allowed from " << forbidden
<< " package " << (*D
).Package
<< " (" << Ver
.VerStr() << ")" << endl
;
1260 //we found a good version
1263 if (Ver
== verlist
.end())
1265 if (_config
->FindB("Debug::BuildDeps",false) == true)
1266 cout
<< " No multiarch info as we have no satisfying installed nor candidate for " << D
->Package
<< " on build or host arch" << endl
;
1268 if (forbidden
.empty() == false)
1270 if (hasAlternatives
)
1272 return _error
->Error(_("%s dependency for %s can't be satisfied "
1273 "because %s is not allowed on '%s' packages"),
1274 Last
->BuildDepType(D
->Type
), Src
.c_str(),
1275 D
->Package
.c_str(), forbidden
.c_str());
1280 Pkg
= Cache
->FindPkg(D
->Package
);
1282 if (Pkg
.end() == true || (Pkg
->VersionList
== 0 && Pkg
->ProvidesList
== 0))
1284 if (_config
->FindB("Debug::BuildDeps",false) == true)
1285 cout
<< " (not found)" << (*D
).Package
<< endl
;
1287 if (hasAlternatives
)
1290 return _error
->Error(_("%s dependency for %s cannot be satisfied "
1291 "because the package %s cannot be found"),
1292 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
1293 (*D
).Package
.c_str());
1296 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1297 if (IV
.end() == false)
1299 if (_config
->FindB("Debug::BuildDeps",false) == true)
1300 cout
<< " Is installed\n";
1302 if (D
->Version
.empty() == true ||
1303 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1305 skipAlternatives
= hasAlternatives
;
1309 if (_config
->FindB("Debug::BuildDeps",false) == true)
1310 cout
<< " ...but the installed version doesn't meet the version requirement\n";
1312 if (((*D
).Op
& pkgCache::Dep::LessEq
) == pkgCache::Dep::LessEq
)
1313 return _error
->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
1314 Last
->BuildDepType((*D
).Type
), Src
.c_str(), Pkg
.FullName(true).c_str());
1317 // Only consider virtual packages if there is no versioned dependency
1318 if ((*D
).Version
.empty() == true)
1321 * If this is a virtual package, we need to check the list of
1322 * packages that provide it and see if any of those are
1325 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
1326 for (; Prv
.end() != true; ++Prv
)
1328 if (_config
->FindB("Debug::BuildDeps",false) == true)
1329 cout
<< " Checking provider " << Prv
.OwnerPkg().FullName() << endl
;
1331 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
1335 if (Prv
.end() == false)
1337 if (_config
->FindB("Debug::BuildDeps",false) == true)
1338 cout
<< " Is provided by installed package " << Prv
.OwnerPkg().FullName() << endl
;
1339 skipAlternatives
= hasAlternatives
;
1343 else // versioned dependency
1345 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1346 if (CV
.end() == true ||
1347 Cache
->VS().CheckDep(CV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == false)
1349 if (hasAlternatives
)
1351 else if (CV
.end() == false)
1352 return _error
->Error(_("%s dependency for %s cannot be satisfied "
1353 "because candidate version of package %s "
1354 "can't satisfy version requirements"),
1355 Last
->BuildDepType(D
->Type
), Src
.c_str(),
1356 D
->Package
.c_str());
1358 return _error
->Error(_("%s dependency for %s cannot be satisfied "
1359 "because package %s has no candidate version"),
1360 Last
->BuildDepType(D
->Type
), Src
.c_str(),
1361 D
->Package
.c_str());
1365 if (TryToInstallBuildDep(Pkg
,Cache
,Fix
,false,false,false) == true)
1367 // We successfully installed something; skip remaining alternatives
1368 skipAlternatives
= hasAlternatives
;
1369 if(_config
->FindB("APT::Get::Build-Dep-Automatic", false) == true)
1370 Cache
->MarkAuto(Pkg
, true);
1373 else if (hasAlternatives
)
1375 if (_config
->FindB("Debug::BuildDeps",false) == true)
1376 cout
<< " Unsatisfiable, trying alternatives\n";
1381 return _error
->Error(_("Failed to satisfy %s dependency for %s: %s"),
1382 Last
->BuildDepType((*D
).Type
),
1384 (*D
).Package
.c_str());
1389 if (Fix
.Resolve(true) == false)
1392 // Now we check the state of the packages,
1393 if (Cache
->BrokenCount() != 0)
1395 ShowBroken(cout
, Cache
, false);
1396 return _error
->Error(_("Build-dependencies for %s could not be satisfied."),*I
);
1400 if (InstallPackages(Cache
, false, true) == false)
1401 return _error
->Error(_("Failed to process build dependencies"));
1405 // DoChangelog - Get changelog from the command line /*{{{*/
1406 static bool DoChangelog(CommandLine
&CmdL
)
1409 if (Cache
.ReadOnlyOpen() == false)
1412 APT::CacheSetHelper helper
;
1413 APT::VersionList verset
= APT::VersionList::FromCommandLine(Cache
,
1414 CmdL
.FileList
+ 1, APT::CacheSetHelper::CANDIDATE
, helper
);
1415 if (verset
.empty() == true)
1418 AcqTextStatus
Stat(std::cout
, ScreenWidth
,_config
->FindI("quiet",0));
1419 Fetcher
.SetLog(&Stat
);
1421 bool const downOnly
= _config
->FindB("APT::Get::Download-Only", false);
1422 bool const printOnly
= _config
->FindB("APT::Get::Print-URIs", false);
1424 for (APT::VersionList::const_iterator Ver
= verset
.begin();
1425 Ver
!= verset
.end();
1429 new pkgAcqChangelog(&Fetcher
, Ver
, "/dev/null");
1431 new pkgAcqChangelog(&Fetcher
, Ver
, ".");
1433 new pkgAcqChangelog(&Fetcher
, Ver
);
1436 if (printOnly
== false)
1438 // Disable drop-privs if "_apt" can not write to the target dir
1439 CheckDropPrivsMustBeDisabled(Fetcher
);
1440 if (_error
->PendingError() == true)
1443 bool Failed
= false;
1444 if (AcquireRun(Fetcher
, 0, &Failed
, NULL
) == false || Failed
== true)
1448 if (downOnly
== false || printOnly
== true)
1450 bool Failed
= false;
1451 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); ++I
)
1455 if ((*I
)->ErrorText
.empty() == false)
1458 _error
->Error("%s", (*I
)->ErrorText
.c_str());
1461 cout
<< '\'' << (*I
)->DescURI() << "' " << flNotDir((*I
)->DestFile
) << std::endl
;
1464 DisplayFileInPager((*I
)->DestFile
);
1466 return Failed
== false;
1472 // DoIndexTargets - Lists all IndexTargets /*{{{*/
1473 static std::string
format_key(std::string key
)
1475 // deb822 is case-insensitive, but the human eye prefers candy
1476 std::transform(key
.begin(), key
.end(), key
.begin(), ::tolower
);
1477 key
[0] = ::toupper(key
[0]);
1478 size_t found
= key
.find("_uri");
1479 if (found
!= std::string::npos
)
1480 key
.replace(found
, 4, "-URI");
1481 while ((found
= key
.find('_')) != std::string::npos
)
1484 key
[found
+ 1] = ::toupper(key
[found
+ 1]);
1488 static bool DoIndexTargets(CommandLine
&CmdL
)
1490 pkgCacheFile CacheFile
;
1491 pkgSourceList
*SrcList
= CacheFile
.GetSourceList();
1493 if (SrcList
== NULL
)
1496 std::string
const Format
= _config
->Find("APT::Get::IndexTargets::Format");
1497 bool const ReleaseInfo
= _config
->FindB("APT::Get::IndexTargets::ReleaseInfo", true);
1498 bool Filtered
= CmdL
.FileSize() > 1;
1499 for (pkgSourceList::const_iterator S
= SrcList
->begin(); S
!= SrcList
->end(); ++S
)
1501 std::vector
<IndexTarget
> const targets
= (*S
)->GetIndexTargets();
1502 std::map
<std::string
, string
> AddOptions
;
1505 AddOptions
.insert(std::make_pair("TRUSTED", ((*S
)->IsTrusted() ? "yes" : "no")));
1506 pkgCache
&Cache
= *CacheFile
.GetPkgCache();
1507 pkgCache::RlsFileIterator
const RlsFile
= (*S
)->FindInCache(Cache
, false);
1510 #define APT_RELEASE(X,Y) if (RlsFile.Y() != NULL) AddOptions.insert(std::make_pair(X, RlsFile.Y()))
1511 APT_RELEASE("CODENAME", Codename
);
1512 APT_RELEASE("SUITE", Archive
);
1513 APT_RELEASE("VERSION", Version
);
1514 APT_RELEASE("ORIGIN", Origin
);
1515 APT_RELEASE("LABEL", Label
);
1519 for (std::vector
<IndexTarget
>::const_iterator T
= targets
.begin(); T
!= targets
.end(); ++T
)
1521 std::string filename
= T
->Option(ReleaseInfo
? IndexTarget::EXISTING_FILENAME
: IndexTarget::FILENAME
);
1522 if (filename
.empty())
1525 std::ostringstream stanza
;
1526 if (Filtered
|| Format
.empty())
1528 stanza
<< "MetaKey: " << T
->MetaKey
<< "\n"
1529 << "ShortDesc: " << T
->ShortDesc
<< "\n"
1530 << "Description: " << T
->Description
<< "\n"
1531 << "URI: " << T
->URI
<< "\n"
1532 << "Filename: " << filename
<< "\n"
1533 << "Optional: " << (T
->IsOptional
? "yes" : "no") << "\n";
1534 for (std::map
<std::string
,std::string
>::const_iterator O
= AddOptions
.begin(); O
!= AddOptions
.end(); ++O
)
1535 stanza
<< format_key(O
->first
) << ": " << O
->second
<< "\n";
1536 for (std::map
<std::string
,std::string
>::const_iterator O
= T
->Options
.begin(); O
!= T
->Options
.end(); ++O
)
1537 stanza
<< format_key(O
->first
) << ": " << O
->second
<< "\n";
1542 // that is a bit crude, but good enough for now
1544 std::string haystack
= std::string("\n") + stanza
.str() + "\n";
1545 std::transform(haystack
.begin(), haystack
.end(), haystack
.begin(), ::tolower
);
1546 size_t const filesize
= CmdL
.FileSize() - 1;
1547 for (size_t i
= 0; i
!= filesize
; ++i
)
1549 std::string needle
= std::string("\n") + CmdL
.FileList
[i
+ 1] + "\n";
1550 std::transform(needle
.begin(), needle
.end(), needle
.begin(), ::tolower
);
1551 if (haystack
.find(needle
) != std::string::npos
)
1562 cout
<< stanza
.str();
1565 std::string out
= SubstVar(Format
, "$(FILENAME)", filename
);
1566 out
= T
->Format(out
);
1567 for (std::map
<std::string
,std::string
>::const_iterator O
= AddOptions
.begin(); O
!= AddOptions
.end(); ++O
)
1568 out
= SubstVar(out
, std::string("$(") + O
->first
+ ")", O
->second
);
1569 cout
<< out
<< std::endl
;
1577 // ShowHelp - Show a help screen /*{{{*/
1578 // ---------------------------------------------------------------------
1580 static bool ShowHelp(CommandLine
&)
1582 ioprintf(cout
, "%s %s (%s)\n", PACKAGE
, PACKAGE_VERSION
, COMMON_ARCH
);
1584 if (_config
->FindB("version") == true)
1586 cout
<< _("Supported modules:") << endl
;
1588 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
1590 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
1591 if (_system
!= 0 && _system
->VS
== VS
)
1595 cout
<< "Ver: " << VS
->Label
<< endl
;
1597 /* Print out all the packaging systems that will work with
1599 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
1601 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
1606 if (Sys
->VS
->TestCompatibility(*VS
) == true)
1607 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
1611 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
1613 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
1614 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
1617 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
1619 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
1620 cout
<< " Idx: " << Type
->Label
<< endl
;
1627 _("Usage: apt-get [options] command\n"
1628 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
1629 " apt-get [options] source pkg1 [pkg2 ...]\n"
1631 "apt-get is a simple command line interface for downloading and\n"
1632 "installing packages. The most frequently used commands are update\n"
1636 " update - Retrieve new lists of packages\n"
1637 " upgrade - Perform an upgrade\n"
1638 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
1639 " remove - Remove packages\n"
1640 " autoremove - Remove automatically all unused packages\n"
1641 " purge - Remove packages and config files\n"
1642 " source - Download source archives\n"
1643 " build-dep - Configure build-dependencies for source packages\n"
1644 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
1645 " dselect-upgrade - Follow dselect selections\n"
1646 " clean - Erase downloaded archive files\n"
1647 " autoclean - Erase old downloaded archive files\n"
1648 " check - Verify that there are no broken dependencies\n"
1649 " changelog - Download and display the changelog for the given package\n"
1650 " download - Download the binary package into the current directory\n"
1653 " -h This help text.\n"
1654 " -q Loggable output - no progress indicator\n"
1655 " -qq No output except for errors\n"
1656 " -d Download only - do NOT install or unpack archives\n"
1657 " -s No-act. Perform ordering simulation\n"
1658 " -y Assume Yes to all queries and do not prompt\n"
1659 " -f Attempt to correct a system with broken dependencies in place\n"
1660 " -m Attempt to continue if archives are unlocatable\n"
1661 " -u Show a list of upgraded packages as well\n"
1662 " -b Build the source package after fetching it\n"
1663 " -V Show verbose version numbers\n"
1664 " -c=? Read this configuration file\n"
1665 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
1666 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
1667 "pages for more information and options.\n"
1668 " This APT has Super Cow Powers.\n");
1672 int main(int argc
,const char *argv
[]) /*{{{*/
1674 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
1675 {"upgrade",&DoUpgrade
},
1676 {"install",&DoInstall
},
1677 {"remove",&DoInstall
},
1678 {"purge",&DoInstall
},
1679 {"autoremove",&DoInstall
},
1680 {"markauto",&DoMarkAuto
},
1681 {"unmarkauto",&DoMarkAuto
},
1682 {"dist-upgrade",&DoDistUpgrade
},
1683 {"dselect-upgrade",&DoDSelectUpgrade
},
1684 {"build-dep",&DoBuildDep
},
1686 {"autoclean",&DoAutoClean
},
1688 {"source",&DoSource
},
1689 {"download",&DoDownload
},
1690 {"changelog",&DoChangelog
},
1691 {"indextargets",&DoIndexTargets
},
1696 std::vector
<CommandLine::Args
> Args
= getCommandArgs("apt-get", CommandLine::GetCommand(Cmds
, argc
, argv
));
1698 // Set up gettext support
1699 setlocale(LC_ALL
,"");
1700 textdomain(PACKAGE
);
1702 // Parse the command line and initialize the package library
1704 ParseCommandLine(CmdL
, Cmds
, Args
.data(), &_config
, &_system
, argc
, argv
, ShowHelp
);
1706 // see if we are in simulate mode
1707 CheckSimulateMode(CmdL
);
1712 // Setup the output streams
1715 // Match the operation
1716 CmdL
.DispatchArg(Cmds
);
1718 // Print any errors or warnings found during parsing
1719 bool const Errors
= _error
->PendingError();
1720 if (_config
->FindI("quiet",0) > 0)
1721 _error
->DumpErrors();
1723 _error
->DumpErrors(GlobalError::DEBUG
);
1724 return Errors
== true ? 100 : 0;