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
= r
->MetaIndexFile("InRelease");
146 if (FileExists(PathInRelease
))
147 return PathInRelease
;
149 // and if not return the normal one
150 return r
->MetaIndexFile("Release");
153 std::string
GetReleaseForSourceRecord(pkgSourceList
*SrcList
,
154 pkgSrcRecords::Parser
*Parse
)
156 // try to find release
157 const pkgIndexFile
& SI
= Parse
->Index();
158 for (pkgSourceList::const_iterator S
= SrcList
->begin();
159 S
!= SrcList
->end(); ++S
)
161 vector
<pkgIndexFile
*> *Indexes
= (*S
)->GetIndexFiles();
162 for (vector
<pkgIndexFile
*>::const_iterator IF
= Indexes
->begin();
163 IF
!= Indexes
->end(); ++IF
)
167 std::string path
= MetaIndexFileName(*S
);
168 indexRecords records
;
170 return records
.GetSuite();
178 // FindSrc - Find a source record /*{{{*/
179 // ---------------------------------------------------------------------
181 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
182 pkgSrcRecords
&SrcRecs
,string
&Src
,
183 CacheFile
&CacheFile
)
186 string RelTag
= _config
->Find("APT::Default-Release");
187 string TmpSrc
= Name
;
188 pkgDepCache
*Cache
= CacheFile
.GetDepCache();
190 // extract the version/release from the pkgname
191 const size_t found
= TmpSrc
.find_last_of("/=");
192 if (found
!= string::npos
) {
193 if (TmpSrc
[found
] == '/')
194 RelTag
= TmpSrc
.substr(found
+1);
196 VerTag
= TmpSrc
.substr(found
+1);
197 TmpSrc
= TmpSrc
.substr(0,found
);
200 /* Lookup the version of the package we would install if we were to
201 install a version and determine the source package name, then look
202 in the archive for a source package of the same name. */
203 bool MatchSrcOnly
= _config
->FindB("APT::Get::Only-Source");
204 const pkgCache::PkgIterator Pkg
= Cache
->FindPkg(TmpSrc
);
205 if (MatchSrcOnly
== false && Pkg
.end() == false)
207 if(VerTag
.empty() == false || RelTag
.empty() == false)
210 // we have a default release, try to locate the pkg. we do it like
211 // this because GetCandidateVer() will not "downgrade", that means
212 // "apt-get source -t stable apt" won't work on a unstable system
213 for (pkgCache::VerIterator Ver
= Pkg
.VersionList();; ++Ver
)
215 // try first only exact matches, later fuzzy matches
216 if (Ver
.end() == true)
221 Ver
= Pkg
.VersionList();
222 // exit right away from the Pkg.VersionList() loop if we
223 // don't have any versions
224 if (Ver
.end() == true)
227 // We match against a concrete version (or a part of this version)
228 if (VerTag
.empty() == false &&
229 (fuzzy
== true || Cache
->VS().CmpVersion(VerTag
, Ver
.VerStr()) != 0) && // exact match
230 (fuzzy
== false || strncmp(VerTag
.c_str(), Ver
.VerStr(), VerTag
.size()) != 0)) // fuzzy match
233 for (pkgCache::VerFileIterator VF
= Ver
.FileList();
234 VF
.end() == false; ++VF
)
236 /* If this is the status file, and the current version is not the
237 version in the status file (ie it is not installed, or somesuch)
238 then it is not a candidate for installation, ever. This weeds
239 out bogus entries that may be due to config-file states, or
241 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) ==
242 pkgCache::Flag::NotSource
&& Pkg
.CurrentVer() != Ver
)
245 // or we match against a release
246 if(VerTag
.empty() == false ||
247 (VF
.File().Archive() != 0 && VF
.File().Archive() == RelTag
) ||
248 (VF
.File().Codename() != 0 && VF
.File().Codename() == RelTag
))
250 pkgRecords::Parser
&Parse
= Recs
.Lookup(VF
);
251 Src
= Parse
.SourcePkg();
252 // no SourcePkg name, so it is the "binary" name
253 if (Src
.empty() == true)
255 // the Version we have is possibly fuzzy or includes binUploads,
256 // so we use the Version of the SourcePkg (empty if same as package)
257 VerTag
= Parse
.SourceVer();
258 if (VerTag
.empty() == true)
259 VerTag
= Ver
.VerStr();
263 if (Src
.empty() == false)
267 if (Src
.empty() == true)
269 // if we don't have found a fitting package yet so we will
270 // choose a good candidate and proceed with that.
271 // Maybe we will find a source later on with the right VerTag
273 pkgCache::VerIterator Ver
= Cache
->GetCandidateVer(Pkg
);
274 if (Ver
.end() == false)
276 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
277 Src
= Parse
.SourcePkg();
278 if (VerTag
.empty() == true)
279 VerTag
= Parse
.SourceVer();
284 if (Src
.empty() == true)
290 /* if we have a source pkg name, make sure to only search
291 for srcpkg names, otherwise apt gets confused if there
292 is a binary package "pkg1" and a source package "pkg1"
293 with the same name but that comes from different packages */
297 ioprintf(c1out
, _("Picking '%s' as source package instead of '%s'\n"), Src
.c_str(), TmpSrc
.c_str());
302 pkgSrcRecords::Parser
*Last
= 0;
303 unsigned long Offset
= 0;
305 pkgSourceList
*SrcList
= CacheFile
.GetSourceList();
307 /* Iterate over all of the hits, which includes the resulting
308 binary packages in the search */
309 pkgSrcRecords::Parser
*Parse
;
313 while ((Parse
= SrcRecs
.Find(Src
.c_str(), MatchSrcOnly
)) != 0)
315 const string Ver
= Parse
->Version();
317 // See if we need to look for a specific release tag
320 const string Rel
= GetReleaseForSourceRecord(SrcList
, Parse
);
324 ioprintf(c1out
, "Selectied version '%s' (%s) for %s\n",
325 Ver
.c_str(), RelTag
.c_str(), Src
.c_str());
327 Offset
= Parse
->Offset();
332 // Ignore all versions which doesn't fit
333 if (VerTag
.empty() == false &&
334 Cache
->VS().CmpVersion(VerTag
, Ver
) != 0) // exact match
337 // Newer version or an exact match? Save the hit
338 if (Last
== 0 || Cache
->VS().CmpVersion(Version
,Ver
) < 0) {
340 Offset
= Parse
->Offset();
344 // was the version check above an exact match?
345 // If so, we don't need to look further
346 if (VerTag
.empty() == false && (VerTag
== Ver
))
349 if (Last
!= 0 || VerTag
.empty() == true)
351 _error
->Error(_("Ignore unavailable version '%s' of package '%s'"), VerTag
.c_str(), TmpSrc
.c_str());
355 if (Last
== 0 || Last
->Jump(Offset
) == false)
361 /* mark packages as automatically/manually installed. {{{*/
362 bool DoMarkAuto(CommandLine
&CmdL
)
365 int AutoMarkChanged
= 0;
366 OpTextProgress progress
;
368 if (Cache
.Open() == false)
371 if (strcasecmp(CmdL
.FileList
[0],"markauto") == 0)
373 else if (strcasecmp(CmdL
.FileList
[0],"unmarkauto") == 0)
376 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
379 // Locate the package
380 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
381 if (Pkg
.end() == true) {
382 return _error
->Error(_("Couldn't find package %s"),S
);
387 ioprintf(c1out
,_("%s set to manually installed.\n"), Pkg
.Name());
389 ioprintf(c1out
,_("%s set to automatically installed.\n"),
392 Cache
->MarkAuto(Pkg
,Action
);
397 _error
->Notice(_("This command is deprecated. Please use 'apt-mark auto' and 'apt-mark manual' instead."));
399 if (AutoMarkChanged
&& ! _config
->FindB("APT::Get::Simulate",false))
400 return Cache
->writeStateFile(NULL
);
404 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
405 // ---------------------------------------------------------------------
406 /* Follows dselect's selections */
407 bool DoDSelectUpgrade(CommandLine
&CmdL
)
410 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
413 pkgDepCache::ActionGroup
group(Cache
);
415 // Install everything with the install flag set
416 pkgCache::PkgIterator I
= Cache
->PkgBegin();
417 for (;I
.end() != true; ++I
)
419 /* Install the package only if it is a new install, the autoupgrader
420 will deal with the rest */
421 if (I
->SelectedState
== pkgCache::State::Install
)
422 Cache
->MarkInstall(I
,false);
425 /* Now install their deps too, if we do this above then order of
426 the status file is significant for | groups */
427 for (I
= Cache
->PkgBegin();I
.end() != true; ++I
)
429 /* Install the package only if it is a new install, the autoupgrader
430 will deal with the rest */
431 if (I
->SelectedState
== pkgCache::State::Install
)
432 Cache
->MarkInstall(I
,true);
435 // Apply erasures now, they override everything else.
436 for (I
= Cache
->PkgBegin();I
.end() != true; ++I
)
439 if (I
->SelectedState
== pkgCache::State::DeInstall
||
440 I
->SelectedState
== pkgCache::State::Purge
)
441 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
444 /* Resolve any problems that dselect created, allupgrade cannot handle
445 such things. We do so quite agressively too.. */
446 if (Cache
->BrokenCount() != 0)
448 pkgProblemResolver
Fix(Cache
);
450 // Hold back held packages.
451 if (_config
->FindB("APT::Ignore-Hold",false) == false)
453 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; ++I
)
455 if (I
->SelectedState
== pkgCache::State::Hold
)
463 if (Fix
.Resolve() == false)
465 ShowBroken(c1out
,Cache
,false);
466 return _error
->Error(_("Internal error, problem resolver broke stuff"));
470 // Now upgrade everything
471 if (pkgAllUpgrade(Cache
) == false)
473 ShowBroken(c1out
,Cache
,false);
474 return _error
->Error(_("Internal error, problem resolver broke stuff"));
477 return InstallPackages(Cache
,false);
480 // DoClean - Remove download archives /*{{{*/
481 // ---------------------------------------------------------------------
483 bool DoClean(CommandLine
&CmdL
)
485 std::string
const archivedir
= _config
->FindDir("Dir::Cache::archives");
486 std::string
const pkgcache
= _config
->FindFile("Dir::cache::pkgcache");
487 std::string
const srcpkgcache
= _config
->FindFile("Dir::cache::srcpkgcache");
489 if (_config
->FindB("APT::Get::Simulate") == true)
491 cout
<< "Del " << archivedir
<< "* " << archivedir
<< "partial/*"<< endl
492 << "Del " << pkgcache
<< " " << srcpkgcache
<< endl
;
496 // Lock the archive directory
498 if (_config
->FindB("Debug::NoLocking",false) == false)
500 int lock_fd
= GetLock(archivedir
+ "lock");
502 return _error
->Error(_("Unable to lock the download directory"));
507 Fetcher
.Clean(archivedir
);
508 Fetcher
.Clean(archivedir
+ "partial/");
510 pkgCacheFile::RemoveCaches();
515 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
516 // ---------------------------------------------------------------------
517 /* This is similar to clean but it only purges things that cannot be
518 downloaded, that is old versions of cached packages. */
519 class LogCleaner
: public pkgArchiveCleaner
522 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
524 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
526 if (_config
->FindB("APT::Get::Simulate") == false)
531 bool DoAutoClean(CommandLine
&CmdL
)
533 // Lock the archive directory
535 if (_config
->FindB("Debug::NoLocking",false) == false)
537 int lock_fd
= GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock");
539 return _error
->Error(_("Unable to lock the download directory"));
544 if (Cache
.Open() == false)
549 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
550 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
553 // DoDownload - download a binary /*{{{*/
554 // ---------------------------------------------------------------------
555 bool DoDownload(CommandLine
&CmdL
)
558 if (Cache
.ReadOnlyOpen() == false)
561 APT::CacheSetHelper
helper(c0out
);
562 APT::VersionList verset
= APT::VersionList::FromCommandLine(Cache
,
563 CmdL
.FileList
+ 1, APT::VersionList::CANDIDATE
, helper
);
565 if (verset
.empty() == true)
568 AcqTextStatus
Stat(ScreenWidth
, _config
->FindI("quiet", 0));
570 if (Fetcher
.Setup(&Stat
) == false)
573 pkgRecords
Recs(Cache
);
574 pkgSourceList
*SrcList
= Cache
.GetSourceList();
576 // reuse the usual acquire methods for deb files, but don't drop them into
577 // the usual directories - keep everything in the current directory
578 std::vector
<std::string
> storefile(verset
.size());
579 std::string
const cwd
= SafeGetCWD();
580 _config
->Set("Dir::Cache::Archives", cwd
);
582 for (APT::VersionList::const_iterator Ver
= verset
.begin();
583 Ver
!= verset
.end(); ++Ver
, ++i
)
585 pkgAcquire::Item
*I
= new pkgAcqArchive(&Fetcher
, SrcList
, &Recs
, *Ver
, storefile
[i
]);
586 std::string
const filename
= cwd
+ flNotDir(storefile
[i
]);
587 storefile
[i
].assign(filename
);
588 I
->DestFile
.assign(filename
);
591 // Just print out the uris and exit if the --print-uris flag was used
592 if (_config
->FindB("APT::Get::Print-URIs") == true)
594 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
595 for (; I
!= Fetcher
.UriEnd(); ++I
)
596 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
597 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
601 if (_error
->PendingError() == true || CheckAuth(Fetcher
, false) == false)
605 if (AcquireRun(Fetcher
, 0, &Failed
, NULL
) == false)
608 // copy files in local sources to the current directory
609 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); ++I
)
610 if ((*I
)->Local
== true && (*I
)->Status
== pkgAcquire::Item::StatDone
)
612 std::string
const filename
= cwd
+ flNotDir((*I
)->DestFile
);
613 std::ifstream
src((*I
)->DestFile
.c_str(), std::ios::binary
);
614 std::ofstream
dst(filename
.c_str(), std::ios::binary
);
618 return Failed
== false;
621 // DoCheck - Perform the check operation /*{{{*/
622 // ---------------------------------------------------------------------
623 /* Opening automatically checks the system, this command is mostly used
625 bool DoCheck(CommandLine
&CmdL
)
634 // DoSource - Fetch a source archive /*{{{*/
635 // ---------------------------------------------------------------------
636 /* Fetch souce packages */
644 bool DoSource(CommandLine
&CmdL
)
647 if (Cache
.Open(false) == false)
650 if (CmdL
.FileSize() <= 1)
651 return _error
->Error(_("Must specify at least one package to fetch source for"));
653 // Read the source list
654 if (Cache
.BuildSourceList() == false)
656 pkgSourceList
*List
= Cache
.GetSourceList();
658 // Create the text record parsers
659 pkgRecords
Recs(Cache
);
660 pkgSrcRecords
SrcRecs(*List
);
661 if (_error
->PendingError() == true)
664 // Create the download object
665 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
667 Fetcher
.SetLog(&Stat
);
669 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
671 // insert all downloaded uris into this set to avoid downloading them
675 // Diff only mode only fetches .diff files
676 bool const diffOnly
= _config
->FindB("APT::Get::Diff-Only", false);
677 // Tar only mode only fetches .tar files
678 bool const tarOnly
= _config
->FindB("APT::Get::Tar-Only", false);
679 // Dsc only mode only fetches .dsc files
680 bool const dscOnly
= _config
->FindB("APT::Get::Dsc-Only", false);
682 // Load the requestd sources into the fetcher
684 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
687 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,Cache
);
691 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
694 string srec
= Last
->AsStr();
695 string::size_type pos
= srec
.find("\nVcs-");
696 while (pos
!= string::npos
)
698 pos
+= strlen("\nVcs-");
699 string vcs
= srec
.substr(pos
,srec
.find(":",pos
)-pos
);
702 pos
= srec
.find("\nVcs-", pos
);
705 pos
+= vcs
.length()+2;
706 string::size_type epos
= srec
.find("\n", pos
);
707 string uri
= srec
.substr(pos
,epos
-pos
).c_str();
708 ioprintf(c1out
, _("NOTICE: '%s' packaging is maintained in "
709 "the '%s' version control system at:\n"
711 Src
.c_str(), vcs
.c_str(), uri
.c_str());
713 ioprintf(c1out
,_("Please use:\n"
715 "to retrieve the latest (possibly unreleased) "
716 "updates to the package.\n"),
722 vector
<pkgSrcRecords::File
> Lst
;
723 if (Last
->Files(Lst
) == false) {
728 // Load them into the fetcher
729 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
732 // Try to guess what sort of file it is we are getting.
733 if (I
->Type
== "dsc")
735 Dsc
[J
].Package
= Last
->Package();
736 Dsc
[J
].Version
= Last
->Version();
737 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
740 // Handle the only options so that multiple can be used at once
741 if (diffOnly
== true || tarOnly
== true || dscOnly
== true)
743 if ((diffOnly
== true && I
->Type
== "diff") ||
744 (tarOnly
== true && I
->Type
== "tar") ||
745 (dscOnly
== true && I
->Type
== "dsc"))
746 ; // Fine, we want this file downloaded
751 // don't download the same uri twice (should this be moved to
752 // the fetcher interface itself?)
753 if(queued
.find(Last
->Index().ArchiveURI(I
->Path
)) != queued
.end())
755 queued
.insert(Last
->Index().ArchiveURI(I
->Path
));
757 // check if we have a file with that md5 sum already localy
758 if(!I
->MD5Hash
.empty() && FileExists(flNotDir(I
->Path
)))
760 FileFd
Fd(flNotDir(I
->Path
), FileFd::ReadOnly
);
762 sum
.AddFD(Fd
.Fd(), Fd
.Size());
764 if((string
)sum
.Result() == I
->MD5Hash
)
766 ioprintf(c1out
,_("Skipping already downloaded file '%s'\n"),
767 flNotDir(I
->Path
).c_str());
772 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
774 Last
->Index().SourceInfo(*Last
,*I
),Src
);
778 // Display statistics
779 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
780 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
781 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
783 // Check for enough free space
785 string OutputDir
= ".";
786 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
788 if (errno
== EOVERFLOW
)
789 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
792 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
794 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
797 if (statfs(OutputDir
.c_str(),&Stat
) != 0
798 #if HAVE_STRUCT_STATFS_F_TYPE
799 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
803 return _error
->Error(_("You don't have enough free space in %s"),
809 if (DebBytes
!= FetchBytes
)
810 //TRANSLATOR: The required space between number and unit is already included
811 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
812 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
813 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
815 //TRANSLATOR: The required space between number and unit is already included
816 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
817 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
818 SizeToStr(DebBytes
).c_str());
820 if (_config
->FindB("APT::Get::Simulate",false) == true)
822 for (unsigned I
= 0; I
!= J
; I
++)
823 ioprintf(cout
,_("Fetch source %s\n"),Dsc
[I
].Package
.c_str());
828 // Just print out the uris an exit if the --print-uris flag was used
829 if (_config
->FindB("APT::Get::Print-URIs") == true)
831 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
832 for (; I
!= Fetcher
.UriEnd(); ++I
)
833 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
834 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
841 if (AcquireRun(Fetcher
, 0, &Failed
, NULL
) == false || Failed
== true)
844 return _error
->Error(_("Failed to fetch some archives."));
847 if (_config
->FindB("APT::Get::Download-only",false) == true)
849 c1out
<< _("Download complete and in download only mode") << endl
;
854 // Unpack the sources
855 pid_t Process
= ExecFork();
859 bool const fixBroken
= _config
->FindB("APT::Get::Fix-Broken", false);
860 for (unsigned I
= 0; I
!= J
; ++I
)
862 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
864 // Diff only mode only fetches .diff files
865 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
866 _config
->FindB("APT::Get::Tar-Only",false) == true ||
867 Dsc
[I
].Dsc
.empty() == true)
870 // See if the package is already unpacked
872 if (fixBroken
== false && stat(Dir
.c_str(),&Stat
) == 0 &&
873 S_ISDIR(Stat
.st_mode
) != 0)
875 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
882 snprintf(S
,sizeof(S
),"%s -x %s",
883 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
887 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
888 fprintf(stderr
,_("Check if the 'dpkg-dev' package is installed.\n"));
893 // Try to compile it with dpkg-buildpackage
894 if (_config
->FindB("APT::Get::Compile",false) == true)
896 string buildopts
= _config
->Find("APT::Get::Host-Architecture");
897 if (buildopts
.empty() == false)
898 buildopts
= "-a" + buildopts
+ " ";
899 buildopts
.append(_config
->Find("DPkg::Build-Options","-b -uc"));
901 // Call dpkg-buildpackage
903 snprintf(S
,sizeof(S
),"cd %s && %s %s",
905 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
910 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
920 // Wait for the subprocess
922 while (waitpid(Process
,&Status
,0) != Process
)
926 return _error
->Errno("waitpid","Couldn't wait for subprocess");
929 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
930 return _error
->Error(_("Child process failed"));
935 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
936 // ---------------------------------------------------------------------
937 /* This function will look at the build depends list of the given source
938 package and install the necessary packages to make it true, or fail. */
939 bool DoBuildDep(CommandLine
&CmdL
)
943 _config
->Set("APT::Install-Recommends", false);
945 if (Cache
.Open(true) == false)
948 if (CmdL
.FileSize() <= 1)
949 return _error
->Error(_("Must specify at least one package to check builddeps for"));
951 // Read the source list
952 if (Cache
.BuildSourceList() == false)
954 pkgSourceList
*List
= Cache
.GetSourceList();
956 // Create the text record parsers
957 pkgRecords
Recs(Cache
);
958 pkgSrcRecords
SrcRecs(*List
);
959 if (_error
->PendingError() == true)
962 // Create the download object
963 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
965 if (Fetcher
.Setup(&Stat
) == false)
969 string hostArch
= _config
->Find("APT::Get::Host-Architecture");
970 if (hostArch
.empty() == false)
972 std::vector
<std::string
> archs
= APT::Configuration::getArchitectures();
973 if (std::find(archs
.begin(), archs
.end(), hostArch
) == archs
.end())
974 return _error
->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch
.c_str());
975 StripMultiArch
= false;
978 StripMultiArch
= true;
981 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
984 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,Cache
);
986 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
988 // Process the build-dependencies
989 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
990 // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary
991 if (hostArch
.empty() == false)
993 std::string nativeArch
= _config
->Find("APT::Architecture");
994 _config
->Set("APT::Architecture", hostArch
);
995 bool Success
= Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only", false), StripMultiArch
);
996 _config
->Set("APT::Architecture", nativeArch
);
997 if (Success
== false)
998 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
1000 else if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only", false), StripMultiArch
) == false)
1001 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
1003 // Also ensure that build-essential packages are present
1004 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
1007 for (; Opts
; Opts
= Opts
->Next
)
1009 if (Opts
->Value
.empty() == true)
1012 pkgSrcRecords::Parser::BuildDepRec rec
;
1013 rec
.Package
= Opts
->Value
;
1014 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
1016 BuildDeps
.push_back(rec
);
1019 if (BuildDeps
.empty() == true)
1021 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
1025 // Install the requested packages
1026 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
1027 pkgProblemResolver
Fix(Cache
);
1028 bool skipAlternatives
= false; // skip remaining alternatives in an or group
1029 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); ++D
)
1031 bool hasAlternatives
= (((*D
).Op
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
);
1033 if (skipAlternatives
== true)
1036 * if there are alternatives, we've already picked one, so skip
1039 * TODO: this means that if there's a build-dep on A|B and B is
1040 * installed, we'll still try to install A; more importantly,
1041 * if A is currently broken, we cannot go back and try B. To fix
1042 * this would require we do a Resolve cycle for each package we
1043 * add to the install list. Ugh
1045 if (!hasAlternatives
)
1046 skipAlternatives
= false; // end of or group
1050 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1051 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1053 pkgCache::GrpIterator Grp
= Cache
->FindGrp((*D
).Package
);
1054 // Build-conflicts on unknown packages are silently ignored
1055 if (Grp
.end() == true)
1058 for (pkgCache::PkgIterator Pkg
= Grp
.PackageList(); Pkg
.end() == false; Pkg
= Grp
.NextPkg(Pkg
))
1060 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1062 * Remove if we have an installed version that satisfies the
1065 if (IV
.end() == false &&
1066 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1067 TryToInstallBuildDep(Pkg
,Cache
,Fix
,true,false);
1070 else // BuildDep || BuildDepIndep
1072 if (_config
->FindB("Debug::BuildDeps",false) == true)
1073 cout
<< "Looking for " << (*D
).Package
<< "...\n";
1075 pkgCache::PkgIterator Pkg
;
1078 if (StripMultiArch
== false && D
->Type
!= pkgSrcRecords::Parser::BuildDependIndep
)
1080 size_t const colon
= D
->Package
.find(":");
1081 if (colon
!= string::npos
)
1083 if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0 || strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1084 Pkg
= Cache
->FindPkg(D
->Package
.substr(0,colon
));
1086 Pkg
= Cache
->FindPkg(D
->Package
);
1089 Pkg
= Cache
->FindPkg(D
->Package
, hostArch
);
1091 // a bad version either is invalid or doesn't satify dependency
1092 #define BADVER(Ver) (Ver.end() == true || \
1093 (D->Version.empty() == false && \
1094 Cache->VS().CheckDep(Ver.VerStr(),D->Op,D->Version.c_str()) == false))
1096 APT::VersionList verlist
;
1097 if (Pkg
.end() == false)
1099 pkgCache::VerIterator Ver
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1100 if (BADVER(Ver
) == false)
1101 verlist
.insert(Ver
);
1102 Ver
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1103 if (BADVER(Ver
) == false)
1104 verlist
.insert(Ver
);
1106 if (verlist
.empty() == true)
1108 pkgCache::PkgIterator BuildPkg
= Cache
->FindPkg(D
->Package
, "native");
1109 if (BuildPkg
.end() == false && Pkg
!= BuildPkg
)
1111 pkgCache::VerIterator Ver
= (*Cache
)[BuildPkg
].InstVerIter(*Cache
);
1112 if (BADVER(Ver
) == false)
1113 verlist
.insert(Ver
);
1114 Ver
= (*Cache
)[BuildPkg
].CandidateVerIter(*Cache
);
1115 if (BADVER(Ver
) == false)
1116 verlist
.insert(Ver
);
1122 // We need to decide if host or build arch, so find a version we can look at
1123 APT::VersionList::const_iterator Ver
= verlist
.begin();
1124 for (; Ver
!= verlist
.end(); ++Ver
)
1127 if (Ver
->MultiArch
== pkgCache::Version::None
|| Ver
->MultiArch
== pkgCache::Version::All
)
1129 if (colon
== string::npos
)
1130 Pkg
= Ver
.ParentPkg().Group().FindPkg(hostArch
);
1131 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0)
1132 forbidden
= "Multi-Arch: none";
1133 else if (strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1134 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1136 else if (Ver
->MultiArch
== pkgCache::Version::Same
)
1138 if (colon
== string::npos
)
1139 Pkg
= Ver
.ParentPkg().Group().FindPkg(hostArch
);
1140 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0)
1141 forbidden
= "Multi-Arch: same";
1142 else if (strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1143 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1145 else if ((Ver
->MultiArch
& pkgCache::Version::Foreign
) == pkgCache::Version::Foreign
)
1147 if (colon
== string::npos
)
1148 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1149 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0 ||
1150 strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1151 forbidden
= "Multi-Arch: foreign";
1153 else if ((Ver
->MultiArch
& pkgCache::Version::Allowed
) == pkgCache::Version::Allowed
)
1155 if (colon
== string::npos
)
1156 Pkg
= Ver
.ParentPkg().Group().FindPkg(hostArch
);
1157 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0)
1159 // prefer any installed over preferred non-installed architectures
1160 pkgCache::GrpIterator Grp
= Ver
.ParentPkg().Group();
1161 // we don't check for version here as we are better of with upgrading than remove and install
1162 for (Pkg
= Grp
.PackageList(); Pkg
.end() == false; Pkg
= Grp
.NextPkg(Pkg
))
1163 if (Pkg
.CurrentVer().end() == false)
1165 if (Pkg
.end() == true)
1166 Pkg
= Grp
.FindPreferredPkg(true);
1168 else if (strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1169 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1172 if (forbidden
.empty() == false)
1174 if (_config
->FindB("Debug::BuildDeps",false) == true)
1175 cout
<< D
->Package
.substr(colon
, string::npos
) << " is not allowed from " << forbidden
<< " package " << (*D
).Package
<< " (" << Ver
.VerStr() << ")" << endl
;
1179 //we found a good version
1182 if (Ver
== verlist
.end())
1184 if (_config
->FindB("Debug::BuildDeps",false) == true)
1185 cout
<< " No multiarch info as we have no satisfying installed nor candidate for " << D
->Package
<< " on build or host arch" << endl
;
1187 if (forbidden
.empty() == false)
1189 if (hasAlternatives
)
1191 return _error
->Error(_("%s dependency for %s can't be satisfied "
1192 "because %s is not allowed on '%s' packages"),
1193 Last
->BuildDepType(D
->Type
), Src
.c_str(),
1194 D
->Package
.c_str(), forbidden
.c_str());
1199 Pkg
= Cache
->FindPkg(D
->Package
);
1201 if (Pkg
.end() == true || (Pkg
->VersionList
== 0 && Pkg
->ProvidesList
== 0))
1203 if (_config
->FindB("Debug::BuildDeps",false) == true)
1204 cout
<< " (not found)" << (*D
).Package
<< endl
;
1206 if (hasAlternatives
)
1209 return _error
->Error(_("%s dependency for %s cannot be satisfied "
1210 "because the package %s cannot be found"),
1211 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
1212 (*D
).Package
.c_str());
1215 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1216 if (IV
.end() == false)
1218 if (_config
->FindB("Debug::BuildDeps",false) == true)
1219 cout
<< " Is installed\n";
1221 if (D
->Version
.empty() == true ||
1222 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1224 skipAlternatives
= hasAlternatives
;
1228 if (_config
->FindB("Debug::BuildDeps",false) == true)
1229 cout
<< " ...but the installed version doesn't meet the version requirement\n";
1231 if (((*D
).Op
& pkgCache::Dep::LessEq
) == pkgCache::Dep::LessEq
)
1232 return _error
->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
1233 Last
->BuildDepType((*D
).Type
), Src
.c_str(), Pkg
.FullName(true).c_str());
1236 // Only consider virtual packages if there is no versioned dependency
1237 if ((*D
).Version
.empty() == true)
1240 * If this is a virtual package, we need to check the list of
1241 * packages that provide it and see if any of those are
1244 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
1245 for (; Prv
.end() != true; ++Prv
)
1247 if (_config
->FindB("Debug::BuildDeps",false) == true)
1248 cout
<< " Checking provider " << Prv
.OwnerPkg().FullName() << endl
;
1250 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
1254 if (Prv
.end() == false)
1256 if (_config
->FindB("Debug::BuildDeps",false) == true)
1257 cout
<< " Is provided by installed package " << Prv
.OwnerPkg().FullName() << endl
;
1258 skipAlternatives
= hasAlternatives
;
1262 else // versioned dependency
1264 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1265 if (CV
.end() == true ||
1266 Cache
->VS().CheckDep(CV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == false)
1268 if (hasAlternatives
)
1270 else if (CV
.end() == false)
1271 return _error
->Error(_("%s dependency for %s cannot be satisfied "
1272 "because candidate version of package %s "
1273 "can't satisfy version requirements"),
1274 Last
->BuildDepType(D
->Type
), Src
.c_str(),
1275 D
->Package
.c_str());
1277 return _error
->Error(_("%s dependency for %s cannot be satisfied "
1278 "because package %s has no candidate version"),
1279 Last
->BuildDepType(D
->Type
), Src
.c_str(),
1280 D
->Package
.c_str());
1284 if (TryToInstallBuildDep(Pkg
,Cache
,Fix
,false,false,false) == true)
1286 // We successfully installed something; skip remaining alternatives
1287 skipAlternatives
= hasAlternatives
;
1288 if(_config
->FindB("APT::Get::Build-Dep-Automatic", false) == true)
1289 Cache
->MarkAuto(Pkg
, true);
1292 else if (hasAlternatives
)
1294 if (_config
->FindB("Debug::BuildDeps",false) == true)
1295 cout
<< " Unsatisfiable, trying alternatives\n";
1300 return _error
->Error(_("Failed to satisfy %s dependency for %s: %s"),
1301 Last
->BuildDepType((*D
).Type
),
1303 (*D
).Package
.c_str());
1308 if (Fix
.Resolve(true) == false)
1311 // Now we check the state of the packages,
1312 if (Cache
->BrokenCount() != 0)
1314 ShowBroken(cout
, Cache
, false);
1315 return _error
->Error(_("Build-dependencies for %s could not be satisfied."),*I
);
1319 if (InstallPackages(Cache
, false, true) == false)
1320 return _error
->Error(_("Failed to process build dependencies"));
1324 // GetChangelogPath - return a path pointing to a changelog file or dir /*{{{*/
1325 // ---------------------------------------------------------------------
1326 /* This returns a "path" string for the changelog url construction.
1327 * Please note that its not complete, it either needs a "/changelog"
1328 * appended (for the packages.debian.org/changelogs site) or a
1329 * ".changelog" (for third party sites that store the changelog in the
1330 * pool/ next to the deb itself)
1331 * Example return: "pool/main/a/apt/apt_0.8.8ubuntu3"
1333 string
GetChangelogPath(CacheFile
&Cache
,
1334 pkgCache::PkgIterator Pkg
,
1335 pkgCache::VerIterator Ver
)
1339 pkgRecords
Recs(Cache
);
1340 pkgRecords::Parser
&rec
=Recs
.Lookup(Ver
.FileList());
1341 string srcpkg
= rec
.SourcePkg().empty() ? Pkg
.Name() : rec
.SourcePkg();
1342 string ver
= Ver
.VerStr();
1343 // if there is a source version it always wins
1344 if (rec
.SourceVer() != "")
1345 ver
= rec
.SourceVer();
1346 path
= flNotFile(rec
.FileName());
1347 path
+= srcpkg
+ "_" + StripEpoch(ver
);
1351 // GuessThirdPartyChangelogUri - return url /*{{{*/
1352 // ---------------------------------------------------------------------
1353 /* Contruct a changelog file path for third party sites that do not use
1354 * packages.debian.org/changelogs
1355 * This simply uses the ArchiveURI() of the source pkg and looks for
1356 * a .changelog file there, Example for "mediabuntu":
1357 * apt-get changelog mplayer-doc:
1358 * http://packages.medibuntu.org/pool/non-free/m/mplayer/mplayer_1.0~rc4~try1.dsfg1-1ubuntu1+medibuntu1.changelog
1360 bool GuessThirdPartyChangelogUri(CacheFile
&Cache
,
1361 pkgCache::PkgIterator Pkg
,
1362 pkgCache::VerIterator Ver
,
1365 // get the binary deb server path
1366 pkgCache::VerFileIterator Vf
= Ver
.FileList();
1367 if (Vf
.end() == true)
1369 pkgCache::PkgFileIterator F
= Vf
.File();
1370 pkgIndexFile
*index
;
1371 pkgSourceList
*SrcList
= Cache
.GetSourceList();
1372 if(SrcList
->FindIndex(F
, index
) == false)
1375 // get archive uri for the binary deb
1376 string path_without_dot_changelog
= GetChangelogPath(Cache
, Pkg
, Ver
);
1377 out_uri
= index
->ArchiveURI(path_without_dot_changelog
+ ".changelog");
1379 // now strip away the filename and add srcpkg_srcver.changelog
1383 // DownloadChangelog - Download the changelog /*{{{*/
1384 // ---------------------------------------------------------------------
1385 bool DownloadChangelog(CacheFile
&CacheFile
, pkgAcquire
&Fetcher
,
1386 pkgCache::VerIterator Ver
, string targetfile
)
1387 /* Download a changelog file for the given package version to
1388 * targetfile. This will first try the server from Apt::Changelogs::Server
1389 * (http://packages.debian.org/changelogs by default) and if that gives
1390 * a 404 tries to get it from the archive directly (see
1391 * GuessThirdPartyChangelogUri for details how)
1397 string changelog_uri
;
1399 // data structures we need
1400 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
1402 // make the server root configurable
1403 server
= _config
->Find("Apt::Changelogs::Server",
1404 "http://packages.debian.org/changelogs");
1405 path
= GetChangelogPath(CacheFile
, Pkg
, Ver
);
1406 strprintf(changelog_uri
, "%s/%s/changelog", server
.c_str(), path
.c_str());
1407 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
1409 std::cout
<< '\'' << changelog_uri
<< '\'' << std::endl
;
1413 strprintf(descr
, _("Changelog for %s (%s)"), Pkg
.Name(), changelog_uri
.c_str());
1415 new pkgAcqFile(&Fetcher
, changelog_uri
, "", 0, descr
, Pkg
.Name(), "ignored", targetfile
);
1417 // try downloading it, if that fails, try third-party-changelogs location
1418 // FIXME: Fetcher.Run() is "Continue" even if I get a 404?!?
1420 if (!FileExists(targetfile
))
1422 string third_party_uri
;
1423 if (GuessThirdPartyChangelogUri(CacheFile
, Pkg
, Ver
, third_party_uri
))
1425 strprintf(descr
, _("Changelog for %s (%s)"), Pkg
.Name(), third_party_uri
.c_str());
1426 new pkgAcqFile(&Fetcher
, third_party_uri
, "", 0, descr
, Pkg
.Name(), "ignored", targetfile
);
1431 if (FileExists(targetfile
))
1435 return _error
->Error("changelog download failed");
1438 // DoChangelog - Get changelog from the command line /*{{{*/
1439 // ---------------------------------------------------------------------
1440 bool DoChangelog(CommandLine
&CmdL
)
1443 if (Cache
.ReadOnlyOpen() == false)
1446 APT::CacheSetHelper
helper(c0out
);
1447 APT::VersionList verset
= APT::VersionList::FromCommandLine(Cache
,
1448 CmdL
.FileList
+ 1, APT::VersionList::CANDIDATE
, helper
);
1449 if (verset
.empty() == true)
1453 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
1455 bool Success
= true;
1456 for (APT::VersionList::const_iterator Ver
= verset
.begin();
1457 Ver
!= verset
.end(); ++Ver
)
1458 Success
&= DownloadChangelog(Cache
, Fetcher
, Ver
, "");
1462 AcqTextStatus
Stat(ScreenWidth
, _config
->FindI("quiet",0));
1463 Fetcher
.Setup(&Stat
);
1465 bool const downOnly
= _config
->FindB("APT::Get::Download-Only", false);
1468 char* tmpdir
= NULL
;
1469 if (downOnly
== false)
1471 const char* const tmpDir
= getenv("TMPDIR");
1472 if (tmpDir
!= NULL
&& *tmpDir
!= '\0')
1473 snprintf(tmpname
, sizeof(tmpname
), "%s/apt-changelog-XXXXXX", tmpDir
);
1475 strncpy(tmpname
, "/tmp/apt-changelog-XXXXXX", sizeof(tmpname
));
1476 tmpdir
= mkdtemp(tmpname
);
1478 return _error
->Errno("mkdtemp", "mkdtemp failed");
1481 for (APT::VersionList::const_iterator Ver
= verset
.begin();
1482 Ver
!= verset
.end();
1485 string changelogfile
;
1486 if (downOnly
== false)
1487 changelogfile
.append(tmpname
).append("changelog");
1489 changelogfile
.append(Ver
.ParentPkg().Name()).append(".changelog");
1490 if (DownloadChangelog(Cache
, Fetcher
, Ver
, changelogfile
) && downOnly
== false)
1492 DisplayFileInPager(changelogfile
);
1493 // cleanup temp file
1494 unlink(changelogfile
.c_str());
1503 // ShowHelp - Show a help screen /*{{{*/
1504 // ---------------------------------------------------------------------
1506 bool ShowHelp(CommandLine
&CmdL
)
1508 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,PACKAGE_VERSION
,
1509 COMMON_ARCH
,__DATE__
,__TIME__
);
1511 if (_config
->FindB("version") == true)
1513 cout
<< _("Supported modules:") << endl
;
1515 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
1517 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
1518 if (_system
!= 0 && _system
->VS
== VS
)
1522 cout
<< "Ver: " << VS
->Label
<< endl
;
1524 /* Print out all the packaging systems that will work with
1526 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
1528 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
1533 if (Sys
->VS
->TestCompatibility(*VS
) == true)
1534 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
1538 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
1540 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
1541 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
1544 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
1546 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
1547 cout
<< " Idx: " << Type
->Label
<< endl
;
1554 _("Usage: apt-get [options] command\n"
1555 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
1556 " apt-get [options] source pkg1 [pkg2 ...]\n"
1558 "apt-get is a simple command line interface for downloading and\n"
1559 "installing packages. The most frequently used commands are update\n"
1563 " update - Retrieve new lists of packages\n"
1564 " upgrade - Perform an upgrade\n"
1565 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
1566 " remove - Remove packages\n"
1567 " autoremove - Remove automatically all unused packages\n"
1568 " purge - Remove packages and config files\n"
1569 " source - Download source archives\n"
1570 " build-dep - Configure build-dependencies for source packages\n"
1571 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
1572 " dselect-upgrade - Follow dselect selections\n"
1573 " clean - Erase downloaded archive files\n"
1574 " autoclean - Erase old downloaded archive files\n"
1575 " check - Verify that there are no broken dependencies\n"
1576 " changelog - Download and display the changelog for the given package\n"
1577 " download - Download the binary package into the current directory\n"
1580 " -h This help text.\n"
1581 " -q Loggable output - no progress indicator\n"
1582 " -qq No output except for errors\n"
1583 " -d Download only - do NOT install or unpack archives\n"
1584 " -s No-act. Perform ordering simulation\n"
1585 " -y Assume Yes to all queries and do not prompt\n"
1586 " -f Attempt to correct a system with broken dependencies in place\n"
1587 " -m Attempt to continue if archives are unlocatable\n"
1588 " -u Show a list of upgraded packages as well\n"
1589 " -b Build the source package after fetching it\n"
1590 " -V Show verbose version numbers\n"
1591 " -c=? Read this configuration file\n"
1592 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
1593 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
1594 "pages for more information and options.\n"
1595 " This APT has Super Cow Powers.\n");
1599 // SigWinch - Window size change signal handler /*{{{*/
1600 // ---------------------------------------------------------------------
1604 // Riped from GNU ls
1608 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
1609 ScreenWidth
= ws
.ws_col
- 1;
1613 bool DoUpgrade(CommandLine
&CmdL
) /*{{{*/
1615 if (_config
->FindB("APT::Get::Upgrade-Allow-New", false) == true)
1616 return DoUpgradeWithAllowNewPackages(CmdL
);
1618 return DoUpgradeNoNewPackages(CmdL
);
1621 int main(int argc
,const char *argv
[]) /*{{{*/
1623 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
1624 {"upgrade",&DoUpgrade
},
1625 {"install",&DoInstall
},
1626 {"remove",&DoInstall
},
1627 {"purge",&DoInstall
},
1628 {"autoremove",&DoInstall
},
1629 {"markauto",&DoMarkAuto
},
1630 {"unmarkauto",&DoMarkAuto
},
1631 {"dist-upgrade",&DoDistUpgrade
},
1632 {"dselect-upgrade",&DoDSelectUpgrade
},
1633 {"build-dep",&DoBuildDep
},
1635 {"autoclean",&DoAutoClean
},
1637 {"source",&DoSource
},
1638 {"download",&DoDownload
},
1639 {"changelog",&DoChangelog
},
1644 std::vector
<CommandLine::Args
> Args
= getCommandArgs("apt-get", CommandLine::GetCommand(Cmds
, argc
, argv
));
1646 // Set up gettext support
1647 setlocale(LC_ALL
,"");
1648 textdomain(PACKAGE
);
1650 // Parse the command line and initialize the package library
1651 CommandLine
CmdL(Args
.data(),_config
);
1652 if (pkgInitConfig(*_config
) == false ||
1653 CmdL
.Parse(argc
,argv
) == false ||
1654 pkgInitSystem(*_config
,_system
) == false)
1656 if (_config
->FindB("version") == true)
1659 _error
->DumpErrors();
1663 // See if the help should be shown
1664 if (_config
->FindB("help") == true ||
1665 _config
->FindB("version") == true ||
1666 CmdL
.FileSize() == 0)
1672 // see if we are in simulate mode
1673 CheckSimulateMode(CmdL
);
1675 // Deal with stdout not being a tty
1676 if (!isatty(STDOUT_FILENO
) && _config
->FindI("quiet", -1) == -1)
1677 _config
->Set("quiet","1");
1679 // Setup the output streams
1682 // Setup the signals
1683 signal(SIGPIPE
,SIG_IGN
);
1684 signal(SIGWINCH
,SigWinch
);
1687 // Match the operation
1688 CmdL
.DispatchArg(Cmds
);
1690 // Print any errors or warnings found during parsing
1691 bool const Errors
= _error
->PendingError();
1692 if (_config
->FindI("quiet",0) > 0)
1693 _error
->DumpErrors();
1695 _error
->DumpErrors(GlobalError::DEBUG
);
1696 return Errors
== true ? 100 : 0;