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 - Powerfull 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/aptconfiguration.h>
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>
36 #include <apt-pkg/algorithms.h>
37 #include <apt-pkg/acquire-item.h>
38 #include <apt-pkg/strutl.h>
39 #include <apt-pkg/fileutl.h>
40 #include <apt-pkg/clean.h>
41 #include <apt-pkg/srcrecords.h>
42 #include <apt-pkg/version.h>
43 #include <apt-pkg/cachefile.h>
44 #include <apt-pkg/cacheset.h>
45 #include <apt-pkg/sptr.h>
46 #include <apt-pkg/md5.h>
47 #include <apt-pkg/versionmatch.h>
48 #include <apt-pkg/progress.h>
49 #include <apt-pkg/pkgsystem.h>
50 #include <apt-pkg/pkgrecords.h>
51 #include <apt-pkg/indexfile.h>
52 #include <apt-pkg/upgrade.h>
53 #include <apt-pkg/metaindex.h>
54 #include <apt-pkg/indexrecords.h>
56 #include <apt-private/private-download.h>
57 #include <apt-private/private-install.h>
58 #include <apt-private/private-upgrade.h>
59 #include <apt-private/private-output.h>
60 #include <apt-private/private-cacheset.h>
61 #include <apt-private/private-update.h>
62 #include <apt-private/private-cmndline.h>
63 #include <apt-private/private-moo.h>
64 #include <apt-private/private-utils.h>
66 #include <apt-pkg/debmetaindex.h>
68 #include <apt-private/acqprogress.h>
77 #include <sys/ioctl.h>
79 #include <sys/statfs.h>
80 #include <sys/statvfs.h>
88 #include <apt-private/private-output.h>
89 #include <apt-private/private-main.h>
96 // TryToInstallBuildDep - Try to install a single package /*{{{*/
97 // ---------------------------------------------------------------------
98 /* This used to be inlined in DoInstall, but with the advent of regex package
99 name matching it was split out.. */
100 bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg
,pkgCacheFile
&Cache
,
101 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
102 bool AllowFail
= true)
104 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0)
106 CacheSetHelperAPTGet
helper(c1out
);
107 helper
.showErrors(false);
108 pkgCache::VerIterator Ver
= helper
.canNotFindNewestVer(Cache
, Pkg
);
109 if (Ver
.end() == false)
110 Pkg
= Ver
.ParentPkg();
111 else if (helper
.showVirtualPackageErrors(Cache
) == false)
115 if (_config
->FindB("Debug::BuildDeps",false) == true)
118 cout
<< " Trying to remove " << Pkg
<< endl
;
120 cout
<< " Trying to install " << Pkg
<< endl
;
125 TryToRemove
RemoveAction(Cache
, &Fix
);
126 RemoveAction(Pkg
.VersionList());
127 } else if (Cache
[Pkg
].CandidateVer
!= 0) {
128 TryToInstall
InstallAction(Cache
, &Fix
, BrokenFix
);
129 InstallAction(Cache
[Pkg
].CandidateVerIter(Cache
));
130 InstallAction
.doAutoInstall();
138 // FIXME: move into more generic code (metaindex ?)
139 std::string
MetaIndexFileName(metaIndex
*metaindex
)
141 // FIXME: this cast is the horror, the horror
142 debReleaseIndex
*r
= (debReleaseIndex
*)metaindex
;
144 // see if we have a InRelease file
145 std::string PathInRelease
= _config
->FindDir("Dir::State::lists") +
146 URItoFileName(r
->MetaIndexURI("InRelease"));
147 if (FileExists(PathInRelease
))
148 return PathInRelease
;
150 // and if not return the normal one
151 return _config
->FindDir("Dir::State::lists") +
152 URItoFileName(r
->MetaIndexURI("Release"));
155 std::string
GetReleaseForSourceRecord(pkgSourceList
*SrcList
,
156 pkgSrcRecords::Parser
*Parse
)
158 // try to find release
159 const pkgIndexFile
& SI
= Parse
->Index();
160 for (pkgSourceList::const_iterator S
= SrcList
->begin();
161 S
!= SrcList
->end(); ++S
)
163 vector
<pkgIndexFile
*> *Indexes
= (*S
)->GetIndexFiles();
164 for (vector
<pkgIndexFile
*>::const_iterator IF
= Indexes
->begin();
165 IF
!= Indexes
->end(); ++IF
)
169 std::string path
= MetaIndexFileName(*S
);
170 indexRecords records
;
172 return records
.GetSuite();
180 // FindSrc - Find a source record /*{{{*/
181 // ---------------------------------------------------------------------
183 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
184 pkgSrcRecords
&SrcRecs
,string
&Src
,
185 CacheFile
&CacheFile
)
188 string RelTag
= _config
->Find("APT::Default-Release");
189 string TmpSrc
= Name
;
190 pkgDepCache
*Cache
= CacheFile
.GetDepCache();
192 // extract the version/release from the pkgname
193 const size_t found
= TmpSrc
.find_last_of("/=");
194 if (found
!= string::npos
) {
195 if (TmpSrc
[found
] == '/')
196 RelTag
= TmpSrc
.substr(found
+1);
198 VerTag
= TmpSrc
.substr(found
+1);
199 TmpSrc
= TmpSrc
.substr(0,found
);
202 /* Lookup the version of the package we would install if we were to
203 install a version and determine the source package name, then look
204 in the archive for a source package of the same name. */
205 bool MatchSrcOnly
= _config
->FindB("APT::Get::Only-Source");
206 const pkgCache::PkgIterator Pkg
= Cache
->FindPkg(TmpSrc
);
207 if (MatchSrcOnly
== false && Pkg
.end() == false)
209 if(VerTag
.empty() == false || RelTag
.empty() == false)
212 // we have a default release, try to locate the pkg. we do it like
213 // this because GetCandidateVer() will not "downgrade", that means
214 // "apt-get source -t stable apt" won't work on a unstable system
215 for (pkgCache::VerIterator Ver
= Pkg
.VersionList();; ++Ver
)
217 // try first only exact matches, later fuzzy matches
218 if (Ver
.end() == true)
223 Ver
= Pkg
.VersionList();
224 // exit right away from the Pkg.VersionList() loop if we
225 // don't have any versions
226 if (Ver
.end() == true)
229 // We match against a concrete version (or a part of this version)
230 if (VerTag
.empty() == false &&
231 (fuzzy
== true || Cache
->VS().CmpVersion(VerTag
, Ver
.VerStr()) != 0) && // exact match
232 (fuzzy
== false || strncmp(VerTag
.c_str(), Ver
.VerStr(), VerTag
.size()) != 0)) // fuzzy match
235 for (pkgCache::VerFileIterator VF
= Ver
.FileList();
236 VF
.end() == false; ++VF
)
238 /* If this is the status file, and the current version is not the
239 version in the status file (ie it is not installed, or somesuch)
240 then it is not a candidate for installation, ever. This weeds
241 out bogus entries that may be due to config-file states, or
243 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) ==
244 pkgCache::Flag::NotSource
&& Pkg
.CurrentVer() != Ver
)
247 // or we match against a release
248 if(VerTag
.empty() == false ||
249 (VF
.File().Archive() != 0 && VF
.File().Archive() == RelTag
) ||
250 (VF
.File().Codename() != 0 && VF
.File().Codename() == RelTag
))
252 pkgRecords::Parser
&Parse
= Recs
.Lookup(VF
);
253 Src
= Parse
.SourcePkg();
254 // no SourcePkg name, so it is the "binary" name
255 if (Src
.empty() == true)
257 // the Version we have is possibly fuzzy or includes binUploads,
258 // so we use the Version of the SourcePkg (empty if same as package)
259 VerTag
= Parse
.SourceVer();
260 if (VerTag
.empty() == true)
261 VerTag
= Ver
.VerStr();
265 if (Src
.empty() == false)
269 if (Src
.empty() == true)
271 // if we don't have found a fitting package yet so we will
272 // choose a good candidate and proceed with that.
273 // Maybe we will find a source later on with the right VerTag
275 pkgCache::VerIterator Ver
= Cache
->GetCandidateVer(Pkg
);
276 if (Ver
.end() == false)
278 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
279 Src
= Parse
.SourcePkg();
280 if (VerTag
.empty() == true)
281 VerTag
= Parse
.SourceVer();
286 if (Src
.empty() == true)
292 /* if we have a source pkg name, make sure to only search
293 for srcpkg names, otherwise apt gets confused if there
294 is a binary package "pkg1" and a source package "pkg1"
295 with the same name but that comes from different packages */
299 ioprintf(c1out
, _("Picking '%s' as source package instead of '%s'\n"), Src
.c_str(), TmpSrc
.c_str());
304 pkgSrcRecords::Parser
*Last
= 0;
305 unsigned long Offset
= 0;
308 pkgSourceList
*SrcList
= CacheFile
.GetSourceList();
310 /* Iterate over all of the hits, which includes the resulting
311 binary packages in the search */
312 pkgSrcRecords::Parser
*Parse
;
316 while ((Parse
= SrcRecs
.Find(Src
.c_str(), MatchSrcOnly
)) != 0)
318 const string Ver
= Parse
->Version();
319 const string Rel
= GetReleaseForSourceRecord(SrcList
, Parse
);
321 if (RelTag
!= "" && Rel
== RelTag
)
323 ioprintf(c1out
, "Selectied version '%s' (%s) for %s\n",
324 Ver
.c_str(), RelTag
.c_str(), Src
.c_str());
326 Offset
= Parse
->Offset();
332 if (RelTag
.empty() == false && (RelTag
== FoundRel
))
335 // Ignore all versions which doesn't fit
336 if (VerTag
.empty() == false &&
337 Cache
->VS().CmpVersion(VerTag
, Ver
) != 0) // exact match
340 // Newer version or an exact match? Save the hit
341 if (Last
== 0 || Cache
->VS().CmpVersion(Version
,Ver
) < 0) {
343 Offset
= Parse
->Offset();
347 // was the version check above an exact match? If so, we don't need to look further
348 if (VerTag
.empty() == false && (VerTag
== Ver
))
353 if (Last
!= 0 || VerTag
.empty() == true)
358 if (Last
== 0 || Last
->Jump(Offset
) == false)
364 /* mark packages as automatically/manually installed. {{{*/
365 bool DoMarkAuto(CommandLine
&CmdL
)
368 int AutoMarkChanged
= 0;
369 OpTextProgress progress
;
371 if (Cache
.Open() == false)
374 if (strcasecmp(CmdL
.FileList
[0],"markauto") == 0)
376 else if (strcasecmp(CmdL
.FileList
[0],"unmarkauto") == 0)
379 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
382 // Locate the package
383 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
384 if (Pkg
.end() == true) {
385 return _error
->Error(_("Couldn't find package %s"),S
);
390 ioprintf(c1out
,_("%s set to manually installed.\n"), Pkg
.Name());
392 ioprintf(c1out
,_("%s set to automatically installed.\n"),
395 Cache
->MarkAuto(Pkg
,Action
);
400 _error
->Notice(_("This command is deprecated. Please use 'apt-mark auto' and 'apt-mark manual' instead."));
402 if (AutoMarkChanged
&& ! _config
->FindB("APT::Get::Simulate",false))
403 return Cache
->writeStateFile(NULL
);
407 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
408 // ---------------------------------------------------------------------
409 /* Follows dselect's selections */
410 bool DoDSelectUpgrade(CommandLine
&CmdL
)
413 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
416 pkgDepCache::ActionGroup
group(Cache
);
418 // Install everything with the install flag set
419 pkgCache::PkgIterator I
= Cache
->PkgBegin();
420 for (;I
.end() != true; ++I
)
422 /* Install the package only if it is a new install, the autoupgrader
423 will deal with the rest */
424 if (I
->SelectedState
== pkgCache::State::Install
)
425 Cache
->MarkInstall(I
,false);
428 /* Now install their deps too, if we do this above then order of
429 the status file is significant for | groups */
430 for (I
= Cache
->PkgBegin();I
.end() != true; ++I
)
432 /* Install the package only if it is a new install, the autoupgrader
433 will deal with the rest */
434 if (I
->SelectedState
== pkgCache::State::Install
)
435 Cache
->MarkInstall(I
,true);
438 // Apply erasures now, they override everything else.
439 for (I
= Cache
->PkgBegin();I
.end() != true; ++I
)
442 if (I
->SelectedState
== pkgCache::State::DeInstall
||
443 I
->SelectedState
== pkgCache::State::Purge
)
444 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
447 /* Resolve any problems that dselect created, allupgrade cannot handle
448 such things. We do so quite agressively too.. */
449 if (Cache
->BrokenCount() != 0)
451 pkgProblemResolver
Fix(Cache
);
453 // Hold back held packages.
454 if (_config
->FindB("APT::Ignore-Hold",false) == false)
456 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; ++I
)
458 if (I
->SelectedState
== pkgCache::State::Hold
)
466 if (Fix
.Resolve() == false)
468 ShowBroken(c1out
,Cache
,false);
469 return _error
->Error(_("Internal error, problem resolver broke stuff"));
473 // Now upgrade everything
474 if (pkgAllUpgrade(Cache
) == false)
476 ShowBroken(c1out
,Cache
,false);
477 return _error
->Error(_("Internal error, problem resolver broke stuff"));
480 return InstallPackages(Cache
,false);
483 // DoClean - Remove download archives /*{{{*/
484 // ---------------------------------------------------------------------
486 bool DoClean(CommandLine
&CmdL
)
488 std::string
const archivedir
= _config
->FindDir("Dir::Cache::archives");
489 std::string
const pkgcache
= _config
->FindFile("Dir::cache::pkgcache");
490 std::string
const srcpkgcache
= _config
->FindFile("Dir::cache::srcpkgcache");
492 if (_config
->FindB("APT::Get::Simulate") == true)
494 cout
<< "Del " << archivedir
<< "* " << archivedir
<< "partial/*"<< endl
495 << "Del " << pkgcache
<< " " << srcpkgcache
<< endl
;
499 // Lock the archive directory
501 if (_config
->FindB("Debug::NoLocking",false) == false)
503 int lock_fd
= GetLock(archivedir
+ "lock");
505 return _error
->Error(_("Unable to lock the download directory"));
510 Fetcher
.Clean(archivedir
);
511 Fetcher
.Clean(archivedir
+ "partial/");
513 pkgCacheFile::RemoveCaches();
518 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
519 // ---------------------------------------------------------------------
520 /* This is similar to clean but it only purges things that cannot be
521 downloaded, that is old versions of cached packages. */
522 class LogCleaner
: public pkgArchiveCleaner
525 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
527 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
529 if (_config
->FindB("APT::Get::Simulate") == false)
534 bool DoAutoClean(CommandLine
&CmdL
)
536 // Lock the archive directory
538 if (_config
->FindB("Debug::NoLocking",false) == false)
540 int lock_fd
= GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock");
542 return _error
->Error(_("Unable to lock the download directory"));
547 if (Cache
.Open() == false)
552 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
553 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
556 // DoDownload - download a binary /*{{{*/
557 // ---------------------------------------------------------------------
558 bool DoDownload(CommandLine
&CmdL
)
561 if (Cache
.ReadOnlyOpen() == false)
564 APT::CacheSetHelper
helper(c0out
);
565 APT::VersionList verset
= APT::VersionList::FromCommandLine(Cache
,
566 CmdL
.FileList
+ 1, APT::VersionList::CANDIDATE
, helper
);
568 if (verset
.empty() == true)
571 AcqTextStatus
Stat(ScreenWidth
, _config
->FindI("quiet", 0));
573 if (Fetcher
.Setup(&Stat
) == false)
576 pkgRecords
Recs(Cache
);
577 pkgSourceList
*SrcList
= Cache
.GetSourceList();
579 // reuse the usual acquire methods for deb files, but don't drop them into
580 // the usual directories - keep everything in the current directory
581 std::vector
<std::string
> storefile(verset
.size());
582 std::string
const cwd
= SafeGetCWD();
583 _config
->Set("Dir::Cache::Archives", cwd
);
585 for (APT::VersionList::const_iterator Ver
= verset
.begin();
586 Ver
!= verset
.end(); ++Ver
, ++i
)
588 pkgAcquire::Item
*I
= new pkgAcqArchive(&Fetcher
, SrcList
, &Recs
, *Ver
, storefile
[i
]);
589 std::string
const filename
= cwd
+ flNotDir(storefile
[i
]);
590 storefile
[i
].assign(filename
);
591 I
->DestFile
.assign(filename
);
594 // Just print out the uris and exit if the --print-uris flag was used
595 if (_config
->FindB("APT::Get::Print-URIs") == true)
597 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
598 for (; I
!= Fetcher
.UriEnd(); ++I
)
599 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
600 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
604 if (_error
->PendingError() == true || CheckAuth(Fetcher
, false) == false)
608 if (AcquireRun(Fetcher
, 0, &Failed
, NULL
) == false)
611 // copy files in local sources to the current directory
612 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); ++I
)
613 if ((*I
)->Local
== true && (*I
)->Status
== pkgAcquire::Item::StatDone
)
615 std::string
const filename
= cwd
+ flNotDir((*I
)->DestFile
);
616 std::ifstream
src((*I
)->DestFile
.c_str(), std::ios::binary
);
617 std::ofstream
dst(filename
.c_str(), std::ios::binary
);
621 return Failed
== false;
624 // DoCheck - Perform the check operation /*{{{*/
625 // ---------------------------------------------------------------------
626 /* Opening automatically checks the system, this command is mostly used
628 bool DoCheck(CommandLine
&CmdL
)
637 // DoSource - Fetch a source archive /*{{{*/
638 // ---------------------------------------------------------------------
639 /* Fetch souce packages */
647 bool DoSource(CommandLine
&CmdL
)
650 if (Cache
.Open(false) == false)
653 if (CmdL
.FileSize() <= 1)
654 return _error
->Error(_("Must specify at least one package to fetch source for"));
656 // Read the source list
657 if (Cache
.BuildSourceList() == false)
659 pkgSourceList
*List
= Cache
.GetSourceList();
661 // Create the text record parsers
662 pkgRecords
Recs(Cache
);
663 pkgSrcRecords
SrcRecs(*List
);
664 if (_error
->PendingError() == true)
667 // Create the download object
668 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
670 Fetcher
.SetLog(&Stat
);
672 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
674 // insert all downloaded uris into this set to avoid downloading them
678 // Diff only mode only fetches .diff files
679 bool const diffOnly
= _config
->FindB("APT::Get::Diff-Only", false);
680 // Tar only mode only fetches .tar files
681 bool const tarOnly
= _config
->FindB("APT::Get::Tar-Only", false);
682 // Dsc only mode only fetches .dsc files
683 bool const dscOnly
= _config
->FindB("APT::Get::Dsc-Only", false);
685 // Load the requestd sources into the fetcher
687 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
690 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,Cache
);
694 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
697 string srec
= Last
->AsStr();
698 string::size_type pos
= srec
.find("\nVcs-");
699 while (pos
!= string::npos
)
701 pos
+= strlen("\nVcs-");
702 string vcs
= srec
.substr(pos
,srec
.find(":",pos
)-pos
);
705 pos
= srec
.find("\nVcs-", pos
);
708 pos
+= vcs
.length()+2;
709 string::size_type epos
= srec
.find("\n", pos
);
710 string uri
= srec
.substr(pos
,epos
-pos
).c_str();
711 ioprintf(c1out
, _("NOTICE: '%s' packaging is maintained in "
712 "the '%s' version control system at:\n"
714 Src
.c_str(), vcs
.c_str(), uri
.c_str());
716 ioprintf(c1out
,_("Please use:\n"
718 "to retrieve the latest (possibly unreleased) "
719 "updates to the package.\n"),
725 vector
<pkgSrcRecords::File
> Lst
;
726 if (Last
->Files(Lst
) == false) {
731 // Load them into the fetcher
732 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
735 // Try to guess what sort of file it is we are getting.
736 if (I
->Type
== "dsc")
738 Dsc
[J
].Package
= Last
->Package();
739 Dsc
[J
].Version
= Last
->Version();
740 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
743 // Handle the only options so that multiple can be used at once
744 if (diffOnly
== true || tarOnly
== true || dscOnly
== true)
746 if ((diffOnly
== true && I
->Type
== "diff") ||
747 (tarOnly
== true && I
->Type
== "tar") ||
748 (dscOnly
== true && I
->Type
== "dsc"))
749 ; // Fine, we want this file downloaded
754 // don't download the same uri twice (should this be moved to
755 // the fetcher interface itself?)
756 if(queued
.find(Last
->Index().ArchiveURI(I
->Path
)) != queued
.end())
758 queued
.insert(Last
->Index().ArchiveURI(I
->Path
));
760 // check if we have a file with that md5 sum already localy
761 if(!I
->MD5Hash
.empty() && FileExists(flNotDir(I
->Path
)))
763 FileFd
Fd(flNotDir(I
->Path
), FileFd::ReadOnly
);
765 sum
.AddFD(Fd
.Fd(), Fd
.Size());
767 if((string
)sum
.Result() == I
->MD5Hash
)
769 ioprintf(c1out
,_("Skipping already downloaded file '%s'\n"),
770 flNotDir(I
->Path
).c_str());
775 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
777 Last
->Index().SourceInfo(*Last
,*I
),Src
);
781 // Display statistics
782 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
783 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
784 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
786 // Check for enough free space
788 string OutputDir
= ".";
789 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
791 if (errno
== EOVERFLOW
)
792 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
795 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
797 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
800 if (statfs(OutputDir
.c_str(),&Stat
) != 0
801 #if HAVE_STRUCT_STATFS_F_TYPE
802 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
806 return _error
->Error(_("You don't have enough free space in %s"),
812 if (DebBytes
!= FetchBytes
)
813 //TRANSLATOR: The required space between number and unit is already included
814 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
815 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
816 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
818 //TRANSLATOR: The required space between number and unit is already included
819 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
820 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
821 SizeToStr(DebBytes
).c_str());
823 if (_config
->FindB("APT::Get::Simulate",false) == true)
825 for (unsigned I
= 0; I
!= J
; I
++)
826 ioprintf(cout
,_("Fetch source %s\n"),Dsc
[I
].Package
.c_str());
831 // Just print out the uris an exit if the --print-uris flag was used
832 if (_config
->FindB("APT::Get::Print-URIs") == true)
834 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
835 for (; I
!= Fetcher
.UriEnd(); ++I
)
836 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
837 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
844 if (AcquireRun(Fetcher
, 0, &Failed
, NULL
) == false || Failed
== true)
847 return _error
->Error(_("Failed to fetch some archives."));
850 if (_config
->FindB("APT::Get::Download-only",false) == true)
852 c1out
<< _("Download complete and in download only mode") << endl
;
857 // Unpack the sources
858 pid_t Process
= ExecFork();
862 bool const fixBroken
= _config
->FindB("APT::Get::Fix-Broken", false);
863 for (unsigned I
= 0; I
!= J
; ++I
)
865 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
867 // Diff only mode only fetches .diff files
868 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
869 _config
->FindB("APT::Get::Tar-Only",false) == true ||
870 Dsc
[I
].Dsc
.empty() == true)
873 // See if the package is already unpacked
875 if (fixBroken
== false && stat(Dir
.c_str(),&Stat
) == 0 &&
876 S_ISDIR(Stat
.st_mode
) != 0)
878 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
885 snprintf(S
,sizeof(S
),"%s -x %s",
886 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
890 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
891 fprintf(stderr
,_("Check if the 'dpkg-dev' package is installed.\n"));
896 // Try to compile it with dpkg-buildpackage
897 if (_config
->FindB("APT::Get::Compile",false) == true)
899 string buildopts
= _config
->Find("APT::Get::Host-Architecture");
900 if (buildopts
.empty() == false)
901 buildopts
= "-a" + buildopts
+ " ";
902 buildopts
.append(_config
->Find("DPkg::Build-Options","-b -uc"));
904 // Call dpkg-buildpackage
906 snprintf(S
,sizeof(S
),"cd %s && %s %s",
908 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
913 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
923 // Wait for the subprocess
925 while (waitpid(Process
,&Status
,0) != Process
)
929 return _error
->Errno("waitpid","Couldn't wait for subprocess");
932 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
933 return _error
->Error(_("Child process failed"));
938 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
939 // ---------------------------------------------------------------------
940 /* This function will look at the build depends list of the given source
941 package and install the necessary packages to make it true, or fail. */
942 bool DoBuildDep(CommandLine
&CmdL
)
946 _config
->Set("APT::Install-Recommends", false);
948 if (Cache
.Open(true) == false)
951 if (CmdL
.FileSize() <= 1)
952 return _error
->Error(_("Must specify at least one package to check builddeps for"));
954 // Read the source list
955 if (Cache
.BuildSourceList() == false)
957 pkgSourceList
*List
= Cache
.GetSourceList();
959 // Create the text record parsers
960 pkgRecords
Recs(Cache
);
961 pkgSrcRecords
SrcRecs(*List
);
962 if (_error
->PendingError() == true)
965 // Create the download object
966 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
968 if (Fetcher
.Setup(&Stat
) == false)
972 string hostArch
= _config
->Find("APT::Get::Host-Architecture");
973 if (hostArch
.empty() == false)
975 std::vector
<std::string
> archs
= APT::Configuration::getArchitectures();
976 if (std::find(archs
.begin(), archs
.end(), hostArch
) == archs
.end())
977 return _error
->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch
.c_str());
978 StripMultiArch
= false;
981 StripMultiArch
= true;
984 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
987 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,Cache
);
989 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
991 // Process the build-dependencies
992 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
993 // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary
994 if (hostArch
.empty() == false)
996 std::string nativeArch
= _config
->Find("APT::Architecture");
997 _config
->Set("APT::Architecture", hostArch
);
998 bool Success
= Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only", false), StripMultiArch
);
999 _config
->Set("APT::Architecture", nativeArch
);
1000 if (Success
== false)
1001 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
1003 else if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only", false), StripMultiArch
) == false)
1004 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
1006 // Also ensure that build-essential packages are present
1007 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
1010 for (; Opts
; Opts
= Opts
->Next
)
1012 if (Opts
->Value
.empty() == true)
1015 pkgSrcRecords::Parser::BuildDepRec rec
;
1016 rec
.Package
= Opts
->Value
;
1017 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
1019 BuildDeps
.push_back(rec
);
1022 if (BuildDeps
.empty() == true)
1024 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
1028 // Install the requested packages
1029 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
1030 pkgProblemResolver
Fix(Cache
);
1031 bool skipAlternatives
= false; // skip remaining alternatives in an or group
1032 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); ++D
)
1034 bool hasAlternatives
= (((*D
).Op
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
);
1036 if (skipAlternatives
== true)
1039 * if there are alternatives, we've already picked one, so skip
1042 * TODO: this means that if there's a build-dep on A|B and B is
1043 * installed, we'll still try to install A; more importantly,
1044 * if A is currently broken, we cannot go back and try B. To fix
1045 * this would require we do a Resolve cycle for each package we
1046 * add to the install list. Ugh
1048 if (!hasAlternatives
)
1049 skipAlternatives
= false; // end of or group
1053 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1054 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1056 pkgCache::GrpIterator Grp
= Cache
->FindGrp((*D
).Package
);
1057 // Build-conflicts on unknown packages are silently ignored
1058 if (Grp
.end() == true)
1061 for (pkgCache::PkgIterator Pkg
= Grp
.PackageList(); Pkg
.end() == false; Pkg
= Grp
.NextPkg(Pkg
))
1063 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1065 * Remove if we have an installed version that satisfies the
1068 if (IV
.end() == false &&
1069 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1070 TryToInstallBuildDep(Pkg
,Cache
,Fix
,true,false);
1073 else // BuildDep || BuildDepIndep
1075 if (_config
->FindB("Debug::BuildDeps",false) == true)
1076 cout
<< "Looking for " << (*D
).Package
<< "...\n";
1078 pkgCache::PkgIterator Pkg
;
1081 if (StripMultiArch
== false && D
->Type
!= pkgSrcRecords::Parser::BuildDependIndep
)
1083 size_t const colon
= D
->Package
.find(":");
1084 if (colon
!= string::npos
)
1086 if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0 || strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1087 Pkg
= Cache
->FindPkg(D
->Package
.substr(0,colon
));
1089 Pkg
= Cache
->FindPkg(D
->Package
);
1092 Pkg
= Cache
->FindPkg(D
->Package
, hostArch
);
1094 // a bad version either is invalid or doesn't satify dependency
1095 #define BADVER(Ver) (Ver.end() == true || \
1096 (D->Version.empty() == false && \
1097 Cache->VS().CheckDep(Ver.VerStr(),D->Op,D->Version.c_str()) == false))
1099 APT::VersionList verlist
;
1100 if (Pkg
.end() == false)
1102 pkgCache::VerIterator Ver
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1103 if (BADVER(Ver
) == false)
1104 verlist
.insert(Ver
);
1105 Ver
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1106 if (BADVER(Ver
) == false)
1107 verlist
.insert(Ver
);
1109 if (verlist
.empty() == true)
1111 pkgCache::PkgIterator BuildPkg
= Cache
->FindPkg(D
->Package
, "native");
1112 if (BuildPkg
.end() == false && Pkg
!= BuildPkg
)
1114 pkgCache::VerIterator Ver
= (*Cache
)[BuildPkg
].InstVerIter(*Cache
);
1115 if (BADVER(Ver
) == false)
1116 verlist
.insert(Ver
);
1117 Ver
= (*Cache
)[BuildPkg
].CandidateVerIter(*Cache
);
1118 if (BADVER(Ver
) == false)
1119 verlist
.insert(Ver
);
1125 // We need to decide if host or build arch, so find a version we can look at
1126 APT::VersionList::const_iterator Ver
= verlist
.begin();
1127 for (; Ver
!= verlist
.end(); ++Ver
)
1130 if (Ver
->MultiArch
== pkgCache::Version::None
|| Ver
->MultiArch
== pkgCache::Version::All
)
1132 if (colon
== string::npos
)
1133 Pkg
= Ver
.ParentPkg().Group().FindPkg(hostArch
);
1134 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0)
1135 forbidden
= "Multi-Arch: none";
1136 else if (strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1137 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1139 else if (Ver
->MultiArch
== pkgCache::Version::Same
)
1141 if (colon
== string::npos
)
1142 Pkg
= Ver
.ParentPkg().Group().FindPkg(hostArch
);
1143 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0)
1144 forbidden
= "Multi-Arch: same";
1145 else if (strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1146 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1148 else if ((Ver
->MultiArch
& pkgCache::Version::Foreign
) == pkgCache::Version::Foreign
)
1150 if (colon
== string::npos
)
1151 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1152 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0 ||
1153 strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1154 forbidden
= "Multi-Arch: foreign";
1156 else if ((Ver
->MultiArch
& pkgCache::Version::Allowed
) == pkgCache::Version::Allowed
)
1158 if (colon
== string::npos
)
1159 Pkg
= Ver
.ParentPkg().Group().FindPkg(hostArch
);
1160 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0)
1162 // prefer any installed over preferred non-installed architectures
1163 pkgCache::GrpIterator Grp
= Ver
.ParentPkg().Group();
1164 // we don't check for version here as we are better of with upgrading than remove and install
1165 for (Pkg
= Grp
.PackageList(); Pkg
.end() == false; Pkg
= Grp
.NextPkg(Pkg
))
1166 if (Pkg
.CurrentVer().end() == false)
1168 if (Pkg
.end() == true)
1169 Pkg
= Grp
.FindPreferredPkg(true);
1171 else if (strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1172 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1175 if (forbidden
.empty() == false)
1177 if (_config
->FindB("Debug::BuildDeps",false) == true)
1178 cout
<< D
->Package
.substr(colon
, string::npos
) << " is not allowed from " << forbidden
<< " package " << (*D
).Package
<< " (" << Ver
.VerStr() << ")" << endl
;
1182 //we found a good version
1185 if (Ver
== verlist
.end())
1187 if (_config
->FindB("Debug::BuildDeps",false) == true)
1188 cout
<< " No multiarch info as we have no satisfying installed nor candidate for " << D
->Package
<< " on build or host arch" << endl
;
1190 if (forbidden
.empty() == false)
1192 if (hasAlternatives
)
1194 return _error
->Error(_("%s dependency for %s can't be satisfied "
1195 "because %s is not allowed on '%s' packages"),
1196 Last
->BuildDepType(D
->Type
), Src
.c_str(),
1197 D
->Package
.c_str(), forbidden
.c_str());
1202 Pkg
= Cache
->FindPkg(D
->Package
);
1204 if (Pkg
.end() == true || (Pkg
->VersionList
== 0 && Pkg
->ProvidesList
== 0))
1206 if (_config
->FindB("Debug::BuildDeps",false) == true)
1207 cout
<< " (not found)" << (*D
).Package
<< endl
;
1209 if (hasAlternatives
)
1212 return _error
->Error(_("%s dependency for %s cannot be satisfied "
1213 "because the package %s cannot be found"),
1214 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
1215 (*D
).Package
.c_str());
1218 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1219 if (IV
.end() == false)
1221 if (_config
->FindB("Debug::BuildDeps",false) == true)
1222 cout
<< " Is installed\n";
1224 if (D
->Version
.empty() == true ||
1225 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1227 skipAlternatives
= hasAlternatives
;
1231 if (_config
->FindB("Debug::BuildDeps",false) == true)
1232 cout
<< " ...but the installed version doesn't meet the version requirement\n";
1234 if (((*D
).Op
& pkgCache::Dep::LessEq
) == pkgCache::Dep::LessEq
)
1235 return _error
->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
1236 Last
->BuildDepType((*D
).Type
), Src
.c_str(), Pkg
.FullName(true).c_str());
1239 // Only consider virtual packages if there is no versioned dependency
1240 if ((*D
).Version
.empty() == true)
1243 * If this is a virtual package, we need to check the list of
1244 * packages that provide it and see if any of those are
1247 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
1248 for (; Prv
.end() != true; ++Prv
)
1250 if (_config
->FindB("Debug::BuildDeps",false) == true)
1251 cout
<< " Checking provider " << Prv
.OwnerPkg().FullName() << endl
;
1253 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
1257 if (Prv
.end() == false)
1259 if (_config
->FindB("Debug::BuildDeps",false) == true)
1260 cout
<< " Is provided by installed package " << Prv
.OwnerPkg().FullName() << endl
;
1261 skipAlternatives
= hasAlternatives
;
1265 else // versioned dependency
1267 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1268 if (CV
.end() == true ||
1269 Cache
->VS().CheckDep(CV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == false)
1271 if (hasAlternatives
)
1273 else if (CV
.end() == false)
1274 return _error
->Error(_("%s dependency for %s cannot be satisfied "
1275 "because candidate version of package %s "
1276 "can't satisfy version requirements"),
1277 Last
->BuildDepType(D
->Type
), Src
.c_str(),
1278 D
->Package
.c_str());
1280 return _error
->Error(_("%s dependency for %s cannot be satisfied "
1281 "because package %s has no candidate version"),
1282 Last
->BuildDepType(D
->Type
), Src
.c_str(),
1283 D
->Package
.c_str());
1287 if (TryToInstallBuildDep(Pkg
,Cache
,Fix
,false,false,false) == true)
1289 // We successfully installed something; skip remaining alternatives
1290 skipAlternatives
= hasAlternatives
;
1291 if(_config
->FindB("APT::Get::Build-Dep-Automatic", false) == true)
1292 Cache
->MarkAuto(Pkg
, true);
1295 else if (hasAlternatives
)
1297 if (_config
->FindB("Debug::BuildDeps",false) == true)
1298 cout
<< " Unsatisfiable, trying alternatives\n";
1303 return _error
->Error(_("Failed to satisfy %s dependency for %s: %s"),
1304 Last
->BuildDepType((*D
).Type
),
1306 (*D
).Package
.c_str());
1311 if (Fix
.Resolve(true) == false)
1314 // Now we check the state of the packages,
1315 if (Cache
->BrokenCount() != 0)
1317 ShowBroken(cout
, Cache
, false);
1318 return _error
->Error(_("Build-dependencies for %s could not be satisfied."),*I
);
1322 if (InstallPackages(Cache
, false, true) == false)
1323 return _error
->Error(_("Failed to process build dependencies"));
1327 // GetChangelogPath - return a path pointing to a changelog file or dir /*{{{*/
1328 // ---------------------------------------------------------------------
1329 /* This returns a "path" string for the changelog url construction.
1330 * Please note that its not complete, it either needs a "/changelog"
1331 * appended (for the packages.debian.org/changelogs site) or a
1332 * ".changelog" (for third party sites that store the changelog in the
1333 * pool/ next to the deb itself)
1334 * Example return: "pool/main/a/apt/apt_0.8.8ubuntu3"
1336 string
GetChangelogPath(CacheFile
&Cache
,
1337 pkgCache::PkgIterator Pkg
,
1338 pkgCache::VerIterator Ver
)
1342 pkgRecords
Recs(Cache
);
1343 pkgRecords::Parser
&rec
=Recs
.Lookup(Ver
.FileList());
1344 string srcpkg
= rec
.SourcePkg().empty() ? Pkg
.Name() : rec
.SourcePkg();
1345 string ver
= Ver
.VerStr();
1346 // if there is a source version it always wins
1347 if (rec
.SourceVer() != "")
1348 ver
= rec
.SourceVer();
1349 path
= flNotFile(rec
.FileName());
1350 path
+= srcpkg
+ "_" + StripEpoch(ver
);
1354 // GuessThirdPartyChangelogUri - return url /*{{{*/
1355 // ---------------------------------------------------------------------
1356 /* Contruct a changelog file path for third party sites that do not use
1357 * packages.debian.org/changelogs
1358 * This simply uses the ArchiveURI() of the source pkg and looks for
1359 * a .changelog file there, Example for "mediabuntu":
1360 * apt-get changelog mplayer-doc:
1361 * http://packages.medibuntu.org/pool/non-free/m/mplayer/mplayer_1.0~rc4~try1.dsfg1-1ubuntu1+medibuntu1.changelog
1363 bool GuessThirdPartyChangelogUri(CacheFile
&Cache
,
1364 pkgCache::PkgIterator Pkg
,
1365 pkgCache::VerIterator Ver
,
1368 // get the binary deb server path
1369 pkgCache::VerFileIterator Vf
= Ver
.FileList();
1370 if (Vf
.end() == true)
1372 pkgCache::PkgFileIterator F
= Vf
.File();
1373 pkgIndexFile
*index
;
1374 pkgSourceList
*SrcList
= Cache
.GetSourceList();
1375 if(SrcList
->FindIndex(F
, index
) == false)
1378 // get archive uri for the binary deb
1379 string path_without_dot_changelog
= GetChangelogPath(Cache
, Pkg
, Ver
);
1380 out_uri
= index
->ArchiveURI(path_without_dot_changelog
+ ".changelog");
1382 // now strip away the filename and add srcpkg_srcver.changelog
1386 // DownloadChangelog - Download the changelog /*{{{*/
1387 // ---------------------------------------------------------------------
1388 bool DownloadChangelog(CacheFile
&CacheFile
, pkgAcquire
&Fetcher
,
1389 pkgCache::VerIterator Ver
, string targetfile
)
1390 /* Download a changelog file for the given package version to
1391 * targetfile. This will first try the server from Apt::Changelogs::Server
1392 * (http://packages.debian.org/changelogs by default) and if that gives
1393 * a 404 tries to get it from the archive directly (see
1394 * GuessThirdPartyChangelogUri for details how)
1400 string changelog_uri
;
1402 // data structures we need
1403 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
1405 // make the server root configurable
1406 server
= _config
->Find("Apt::Changelogs::Server",
1407 "http://packages.debian.org/changelogs");
1408 path
= GetChangelogPath(CacheFile
, Pkg
, Ver
);
1409 strprintf(changelog_uri
, "%s/%s/changelog", server
.c_str(), path
.c_str());
1410 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
1412 std::cout
<< '\'' << changelog_uri
<< '\'' << std::endl
;
1416 strprintf(descr
, _("Changelog for %s (%s)"), Pkg
.Name(), changelog_uri
.c_str());
1418 new pkgAcqFile(&Fetcher
, changelog_uri
, "", 0, descr
, Pkg
.Name(), "ignored", targetfile
);
1420 // try downloading it, if that fails, try third-party-changelogs location
1421 // FIXME: Fetcher.Run() is "Continue" even if I get a 404?!?
1423 if (!FileExists(targetfile
))
1425 string third_party_uri
;
1426 if (GuessThirdPartyChangelogUri(CacheFile
, Pkg
, Ver
, third_party_uri
))
1428 strprintf(descr
, _("Changelog for %s (%s)"), Pkg
.Name(), third_party_uri
.c_str());
1429 new pkgAcqFile(&Fetcher
, third_party_uri
, "", 0, descr
, Pkg
.Name(), "ignored", targetfile
);
1434 if (FileExists(targetfile
))
1438 return _error
->Error("changelog download failed");
1441 // DoChangelog - Get changelog from the command line /*{{{*/
1442 // ---------------------------------------------------------------------
1443 bool DoChangelog(CommandLine
&CmdL
)
1446 if (Cache
.ReadOnlyOpen() == false)
1449 APT::CacheSetHelper
helper(c0out
);
1450 APT::VersionList verset
= APT::VersionList::FromCommandLine(Cache
,
1451 CmdL
.FileList
+ 1, APT::VersionList::CANDIDATE
, helper
);
1452 if (verset
.empty() == true)
1456 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
1458 bool Success
= true;
1459 for (APT::VersionList::const_iterator Ver
= verset
.begin();
1460 Ver
!= verset
.end(); ++Ver
)
1461 Success
&= DownloadChangelog(Cache
, Fetcher
, Ver
, "");
1465 AcqTextStatus
Stat(ScreenWidth
, _config
->FindI("quiet",0));
1466 Fetcher
.Setup(&Stat
);
1468 bool const downOnly
= _config
->FindB("APT::Get::Download-Only", false);
1471 char* tmpdir
= NULL
;
1472 if (downOnly
== false)
1474 const char* const tmpDir
= getenv("TMPDIR");
1475 if (tmpDir
!= NULL
&& *tmpDir
!= '\0')
1476 snprintf(tmpname
, sizeof(tmpname
), "%s/apt-changelog-XXXXXX", tmpDir
);
1478 strncpy(tmpname
, "/tmp/apt-changelog-XXXXXX", sizeof(tmpname
));
1479 tmpdir
= mkdtemp(tmpname
);
1481 return _error
->Errno("mkdtemp", "mkdtemp failed");
1484 for (APT::VersionList::const_iterator Ver
= verset
.begin();
1485 Ver
!= verset
.end();
1488 string changelogfile
;
1489 if (downOnly
== false)
1490 changelogfile
.append(tmpname
).append("changelog");
1492 changelogfile
.append(Ver
.ParentPkg().Name()).append(".changelog");
1493 if (DownloadChangelog(Cache
, Fetcher
, Ver
, changelogfile
) && downOnly
== false)
1495 DisplayFileInPager(changelogfile
);
1496 // cleanup temp file
1497 unlink(changelogfile
.c_str());
1506 // ShowHelp - Show a help screen /*{{{*/
1507 // ---------------------------------------------------------------------
1509 bool ShowHelp(CommandLine
&CmdL
)
1511 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,PACKAGE_VERSION
,
1512 COMMON_ARCH
,__DATE__
,__TIME__
);
1514 if (_config
->FindB("version") == true)
1516 cout
<< _("Supported modules:") << endl
;
1518 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
1520 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
1521 if (_system
!= 0 && _system
->VS
== VS
)
1525 cout
<< "Ver: " << VS
->Label
<< endl
;
1527 /* Print out all the packaging systems that will work with
1529 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
1531 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
1536 if (Sys
->VS
->TestCompatibility(*VS
) == true)
1537 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
1541 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
1543 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
1544 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
1547 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
1549 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
1550 cout
<< " Idx: " << Type
->Label
<< endl
;
1557 _("Usage: apt-get [options] command\n"
1558 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
1559 " apt-get [options] source pkg1 [pkg2 ...]\n"
1561 "apt-get is a simple command line interface for downloading and\n"
1562 "installing packages. The most frequently used commands are update\n"
1566 " update - Retrieve new lists of packages\n"
1567 " upgrade - Perform an upgrade\n"
1568 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
1569 " remove - Remove packages\n"
1570 " autoremove - Remove automatically all unused packages\n"
1571 " purge - Remove packages and config files\n"
1572 " source - Download source archives\n"
1573 " build-dep - Configure build-dependencies for source packages\n"
1574 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
1575 " dselect-upgrade - Follow dselect selections\n"
1576 " clean - Erase downloaded archive files\n"
1577 " autoclean - Erase old downloaded archive files\n"
1578 " check - Verify that there are no broken dependencies\n"
1579 " changelog - Download and display the changelog for the given package\n"
1580 " download - Download the binary package into the current directory\n"
1583 " -h This help text.\n"
1584 " -q Loggable output - no progress indicator\n"
1585 " -qq No output except for errors\n"
1586 " -d Download only - do NOT install or unpack archives\n"
1587 " -s No-act. Perform ordering simulation\n"
1588 " -y Assume Yes to all queries and do not prompt\n"
1589 " -f Attempt to correct a system with broken dependencies in place\n"
1590 " -m Attempt to continue if archives are unlocatable\n"
1591 " -u Show a list of upgraded packages as well\n"
1592 " -b Build the source package after fetching it\n"
1593 " -V Show verbose version numbers\n"
1594 " -c=? Read this configuration file\n"
1595 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
1596 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
1597 "pages for more information and options.\n"
1598 " This APT has Super Cow Powers.\n");
1602 // SigWinch - Window size change signal handler /*{{{*/
1603 // ---------------------------------------------------------------------
1607 // Riped from GNU ls
1611 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
1612 ScreenWidth
= ws
.ws_col
- 1;
1616 bool DoUpgrade(CommandLine
&CmdL
) /*{{{*/
1618 if (_config
->FindB("APT::Get::Upgrade-Allow-New", false) == true)
1619 return DoUpgradeWithAllowNewPackages(CmdL
);
1621 return DoUpgradeNoNewPackages(CmdL
);
1624 int main(int argc
,const char *argv
[]) /*{{{*/
1626 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
1627 {"upgrade",&DoUpgrade
},
1628 {"install",&DoInstall
},
1629 {"remove",&DoInstall
},
1630 {"purge",&DoInstall
},
1631 {"autoremove",&DoInstall
},
1632 {"markauto",&DoMarkAuto
},
1633 {"unmarkauto",&DoMarkAuto
},
1634 {"dist-upgrade",&DoDistUpgrade
},
1635 {"dselect-upgrade",&DoDSelectUpgrade
},
1636 {"build-dep",&DoBuildDep
},
1638 {"autoclean",&DoAutoClean
},
1640 {"source",&DoSource
},
1641 {"download",&DoDownload
},
1642 {"changelog",&DoChangelog
},
1647 std::vector
<CommandLine::Args
> Args
= getCommandArgs("apt-get", CommandLine::GetCommand(Cmds
, argc
, argv
));
1649 // Set up gettext support
1650 setlocale(LC_ALL
,"");
1651 textdomain(PACKAGE
);
1653 // Parse the command line and initialize the package library
1654 CommandLine
CmdL(Args
.data(),_config
);
1655 if (pkgInitConfig(*_config
) == false ||
1656 CmdL
.Parse(argc
,argv
) == false ||
1657 pkgInitSystem(*_config
,_system
) == false)
1659 if (_config
->FindB("version") == true)
1662 _error
->DumpErrors();
1666 // See if the help should be shown
1667 if (_config
->FindB("help") == true ||
1668 _config
->FindB("version") == true ||
1669 CmdL
.FileSize() == 0)
1675 // see if we are in simulate mode
1676 CheckSimulateMode(CmdL
);
1678 // Deal with stdout not being a tty
1679 if (!isatty(STDOUT_FILENO
) && _config
->FindI("quiet", -1) == -1)
1680 _config
->Set("quiet","1");
1682 // Setup the output streams
1685 // Setup the signals
1686 signal(SIGPIPE
,SIG_IGN
);
1687 signal(SIGWINCH
,SigWinch
);
1690 // Match the operation
1691 CmdL
.DispatchArg(Cmds
);
1693 // Print any errors or warnings found during parsing
1694 bool const Errors
= _error
->PendingError();
1695 if (_config
->FindI("quiet",0) > 0)
1696 _error
->DumpErrors();
1698 _error
->DumpErrors(GlobalError::DEBUG
);
1699 return Errors
== true ? 100 : 0;