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-private/acqprogress.h>
75 #include <sys/ioctl.h>
77 #include <sys/statfs.h>
78 #include <sys/statvfs.h>
86 #include <apt-private/private-output.h>
87 #include <apt-private/private-main.h>
94 // TryToInstallBuildDep - Try to install a single package /*{{{*/
95 // ---------------------------------------------------------------------
96 /* This used to be inlined in DoInstall, but with the advent of regex package
97 name matching it was split out.. */
98 bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg
,pkgCacheFile
&Cache
,
99 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
100 bool AllowFail
= true)
102 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0)
104 CacheSetHelperAPTGet
helper(c1out
);
105 helper
.showErrors(false);
106 pkgCache::VerIterator Ver
= helper
.canNotFindNewestVer(Cache
, Pkg
);
107 if (Ver
.end() == false)
108 Pkg
= Ver
.ParentPkg();
109 else if (helper
.showVirtualPackageErrors(Cache
) == false)
113 if (_config
->FindB("Debug::BuildDeps",false) == true)
116 cout
<< " Trying to remove " << Pkg
<< endl
;
118 cout
<< " Trying to install " << Pkg
<< endl
;
123 TryToRemove
RemoveAction(Cache
, &Fix
);
124 RemoveAction(Pkg
.VersionList());
125 } else if (Cache
[Pkg
].CandidateVer
!= 0) {
126 TryToInstall
InstallAction(Cache
, &Fix
, BrokenFix
);
127 InstallAction(Cache
[Pkg
].CandidateVerIter(Cache
));
128 InstallAction
.doAutoInstall();
135 // FindSrc - Find a source record /*{{{*/
136 // ---------------------------------------------------------------------
138 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
139 pkgSrcRecords
&SrcRecs
,string
&Src
,
140 CacheFile
&CacheFile
)
143 string DefRel
= _config
->Find("APT::Default-Release");
144 string TmpSrc
= Name
;
145 pkgDepCache
*Cache
= CacheFile
.GetDepCache();
147 // extract the version/release from the pkgname
148 const size_t found
= TmpSrc
.find_last_of("/=");
149 if (found
!= string::npos
) {
150 if (TmpSrc
[found
] == '/')
151 DefRel
= TmpSrc
.substr(found
+1);
153 VerTag
= TmpSrc
.substr(found
+1);
154 TmpSrc
= TmpSrc
.substr(0,found
);
157 /* Lookup the version of the package we would install if we were to
158 install a version and determine the source package name, then look
159 in the archive for a source package of the same name. */
160 bool MatchSrcOnly
= _config
->FindB("APT::Get::Only-Source");
161 const pkgCache::PkgIterator Pkg
= Cache
->FindPkg(TmpSrc
);
162 if (MatchSrcOnly
== false && Pkg
.end() == false)
164 if(VerTag
.empty() == false || DefRel
.empty() == false)
167 // we have a default release, try to locate the pkg. we do it like
168 // this because GetCandidateVer() will not "downgrade", that means
169 // "apt-get source -t stable apt" won't work on a unstable system
170 for (pkgCache::VerIterator Ver
= Pkg
.VersionList();; ++Ver
)
172 // try first only exact matches, later fuzzy matches
173 if (Ver
.end() == true)
178 Ver
= Pkg
.VersionList();
179 // exit right away from the Pkg.VersionList() loop if we
180 // don't have any versions
181 if (Ver
.end() == true)
184 // We match against a concrete version (or a part of this version)
185 if (VerTag
.empty() == false &&
186 (fuzzy
== true || Cache
->VS().CmpVersion(VerTag
, Ver
.VerStr()) != 0) && // exact match
187 (fuzzy
== false || strncmp(VerTag
.c_str(), Ver
.VerStr(), VerTag
.size()) != 0)) // fuzzy match
190 for (pkgCache::VerFileIterator VF
= Ver
.FileList();
191 VF
.end() == false; ++VF
)
193 /* If this is the status file, and the current version is not the
194 version in the status file (ie it is not installed, or somesuch)
195 then it is not a candidate for installation, ever. This weeds
196 out bogus entries that may be due to config-file states, or
198 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) ==
199 pkgCache::Flag::NotSource
&& Pkg
.CurrentVer() != Ver
)
202 // or we match against a release
203 if(VerTag
.empty() == false ||
204 (VF
.File().Archive() != 0 && VF
.File().Archive() == DefRel
) ||
205 (VF
.File().Codename() != 0 && VF
.File().Codename() == DefRel
))
207 pkgRecords::Parser
&Parse
= Recs
.Lookup(VF
);
208 Src
= Parse
.SourcePkg();
209 // no SourcePkg name, so it is the "binary" name
210 if (Src
.empty() == true)
212 // the Version we have is possibly fuzzy or includes binUploads,
213 // so we use the Version of the SourcePkg (empty if same as package)
214 VerTag
= Parse
.SourceVer();
215 if (VerTag
.empty() == true)
216 VerTag
= Ver
.VerStr();
220 if (Src
.empty() == false)
224 if (Src
.empty() == true)
226 // Sources files have no codename information
227 if (VerTag
.empty() == true && DefRel
.empty() == false)
229 _error
->Warning(_("Ignore unavailable target release '%s' of package '%s'"), DefRel
.c_str(), TmpSrc
.c_str());
235 if (Src
.empty() == true)
237 // if we don't have found a fitting package yet so we will
238 // choose a good candidate and proceed with that.
239 // Maybe we will find a source later on with the right VerTag
240 pkgCache::VerIterator Ver
= Cache
->GetCandidateVer(Pkg
);
241 if (Ver
.end() == false)
243 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
244 Src
= Parse
.SourcePkg();
245 if (VerTag
.empty() == true)
246 VerTag
= Parse
.SourceVer();
251 if (Src
.empty() == true)
255 /* if we have a source pkg name, make sure to only search
256 for srcpkg names, otherwise apt gets confused if there
257 is a binary package "pkg1" and a source package "pkg1"
258 with the same name but that comes from different packages */
262 ioprintf(c1out
, _("Picking '%s' as source package instead of '%s'\n"), Src
.c_str(), TmpSrc
.c_str());
267 pkgSrcRecords::Parser
*Last
= 0;
268 unsigned long Offset
= 0;
272 /* Iterate over all of the hits, which includes the resulting
273 binary packages in the search */
274 pkgSrcRecords::Parser
*Parse
;
278 while ((Parse
= SrcRecs
.Find(Src
.c_str(), MatchSrcOnly
)) != 0)
280 const string Ver
= Parse
->Version();
284 const pkgIndexFile
& SI
= Parse
->Index();
285 pkgSourceList
*SrcList
= CacheFile
.GetSourceList();
286 for (pkgSourceList::const_iterator S
= SrcList
->begin();
287 S
!= SrcList
->end(); ++S
)
289 vector
<pkgIndexFile
*> *Indexes
= (*S
)->GetIndexFiles();
290 for (vector
<pkgIndexFile
*>::const_iterator IF
= Indexes
->begin();
291 IF
!= Indexes
->end(); ++IF
)
295 std::string dirname
= _config
->FindDir("Dir::State::lists");
296 std::string path
= dirname
+ URItoFileName((*S
)->GetURI()) + "dists_" + (*S
)->GetDist() + "_Release";
297 indexRecords records
;
299 if (records
.GetSuite() == DefRel
)
301 ioprintf(clog
, "Selectied version '%s' (%s) for %s\n",
302 Ver
.c_str(), DefRel
.c_str(), Src
.c_str());
304 Offset
= Parse
->Offset();
312 if (DefRel
.empty() == false && (DefRel
== FoundRel
))
315 // Ignore all versions which doesn't fit
316 if (VerTag
.empty() == false &&
317 Cache
->VS().CmpVersion(VerTag
, Ver
) != 0) // exact match
320 // Newer version or an exact match? Save the hit
321 if (Last
== 0 || Cache
->VS().CmpVersion(Version
,Ver
) < 0) {
323 Offset
= Parse
->Offset();
327 // was the version check above an exact match? If so, we don't need to look further
328 if (VerTag
.empty() == false && (VerTag
== Ver
))
330 std::cerr
<< "meep" << std::endl
;
334 if (Last
!= 0 || VerTag
.empty() == true)
339 if (Last
== 0 || Last
->Jump(Offset
) == false)
345 /* mark packages as automatically/manually installed. {{{*/
346 bool DoMarkAuto(CommandLine
&CmdL
)
349 int AutoMarkChanged
= 0;
350 OpTextProgress progress
;
352 if (Cache
.Open() == false)
355 if (strcasecmp(CmdL
.FileList
[0],"markauto") == 0)
357 else if (strcasecmp(CmdL
.FileList
[0],"unmarkauto") == 0)
360 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
363 // Locate the package
364 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
365 if (Pkg
.end() == true) {
366 return _error
->Error(_("Couldn't find package %s"),S
);
371 ioprintf(c1out
,_("%s set to manually installed.\n"), Pkg
.Name());
373 ioprintf(c1out
,_("%s set to automatically installed.\n"),
376 Cache
->MarkAuto(Pkg
,Action
);
381 _error
->Notice(_("This command is deprecated. Please use 'apt-mark auto' and 'apt-mark manual' instead."));
383 if (AutoMarkChanged
&& ! _config
->FindB("APT::Get::Simulate",false))
384 return Cache
->writeStateFile(NULL
);
388 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
389 // ---------------------------------------------------------------------
390 /* Follows dselect's selections */
391 bool DoDSelectUpgrade(CommandLine
&CmdL
)
394 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
397 pkgDepCache::ActionGroup
group(Cache
);
399 // Install everything with the install flag set
400 pkgCache::PkgIterator I
= Cache
->PkgBegin();
401 for (;I
.end() != true; ++I
)
403 /* Install the package only if it is a new install, the autoupgrader
404 will deal with the rest */
405 if (I
->SelectedState
== pkgCache::State::Install
)
406 Cache
->MarkInstall(I
,false);
409 /* Now install their deps too, if we do this above then order of
410 the status file is significant for | groups */
411 for (I
= Cache
->PkgBegin();I
.end() != true; ++I
)
413 /* Install the package only if it is a new install, the autoupgrader
414 will deal with the rest */
415 if (I
->SelectedState
== pkgCache::State::Install
)
416 Cache
->MarkInstall(I
,true);
419 // Apply erasures now, they override everything else.
420 for (I
= Cache
->PkgBegin();I
.end() != true; ++I
)
423 if (I
->SelectedState
== pkgCache::State::DeInstall
||
424 I
->SelectedState
== pkgCache::State::Purge
)
425 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
428 /* Resolve any problems that dselect created, allupgrade cannot handle
429 such things. We do so quite agressively too.. */
430 if (Cache
->BrokenCount() != 0)
432 pkgProblemResolver
Fix(Cache
);
434 // Hold back held packages.
435 if (_config
->FindB("APT::Ignore-Hold",false) == false)
437 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; ++I
)
439 if (I
->SelectedState
== pkgCache::State::Hold
)
447 if (Fix
.Resolve() == false)
449 ShowBroken(c1out
,Cache
,false);
450 return _error
->Error(_("Internal error, problem resolver broke stuff"));
454 // Now upgrade everything
455 if (pkgAllUpgrade(Cache
) == false)
457 ShowBroken(c1out
,Cache
,false);
458 return _error
->Error(_("Internal error, problem resolver broke stuff"));
461 return InstallPackages(Cache
,false);
464 // DoClean - Remove download archives /*{{{*/
465 // ---------------------------------------------------------------------
467 bool DoClean(CommandLine
&CmdL
)
469 std::string
const archivedir
= _config
->FindDir("Dir::Cache::archives");
470 std::string
const pkgcache
= _config
->FindFile("Dir::cache::pkgcache");
471 std::string
const srcpkgcache
= _config
->FindFile("Dir::cache::srcpkgcache");
473 if (_config
->FindB("APT::Get::Simulate") == true)
475 cout
<< "Del " << archivedir
<< "* " << archivedir
<< "partial/*"<< endl
476 << "Del " << pkgcache
<< " " << srcpkgcache
<< endl
;
480 // Lock the archive directory
482 if (_config
->FindB("Debug::NoLocking",false) == false)
484 int lock_fd
= GetLock(archivedir
+ "lock");
486 return _error
->Error(_("Unable to lock the download directory"));
491 Fetcher
.Clean(archivedir
);
492 Fetcher
.Clean(archivedir
+ "partial/");
494 pkgCacheFile::RemoveCaches();
499 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
500 // ---------------------------------------------------------------------
501 /* This is similar to clean but it only purges things that cannot be
502 downloaded, that is old versions of cached packages. */
503 class LogCleaner
: public pkgArchiveCleaner
506 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
508 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
510 if (_config
->FindB("APT::Get::Simulate") == false)
515 bool DoAutoClean(CommandLine
&CmdL
)
517 // Lock the archive directory
519 if (_config
->FindB("Debug::NoLocking",false) == false)
521 int lock_fd
= GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock");
523 return _error
->Error(_("Unable to lock the download directory"));
528 if (Cache
.Open() == false)
533 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
534 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
537 // DoDownload - download a binary /*{{{*/
538 // ---------------------------------------------------------------------
539 bool DoDownload(CommandLine
&CmdL
)
542 if (Cache
.ReadOnlyOpen() == false)
545 APT::CacheSetHelper
helper(c0out
);
546 APT::VersionList verset
= APT::VersionList::FromCommandLine(Cache
,
547 CmdL
.FileList
+ 1, APT::VersionList::CANDIDATE
, helper
);
549 if (verset
.empty() == true)
552 AcqTextStatus
Stat(ScreenWidth
, _config
->FindI("quiet", 0));
554 if (Fetcher
.Setup(&Stat
) == false)
557 pkgRecords
Recs(Cache
);
558 pkgSourceList
*SrcList
= Cache
.GetSourceList();
560 // reuse the usual acquire methods for deb files, but don't drop them into
561 // the usual directories - keep everything in the current directory
562 std::vector
<std::string
> storefile(verset
.size());
563 std::string
const cwd
= SafeGetCWD();
564 _config
->Set("Dir::Cache::Archives", cwd
);
566 for (APT::VersionList::const_iterator Ver
= verset
.begin();
567 Ver
!= verset
.end(); ++Ver
, ++i
)
569 pkgAcquire::Item
*I
= new pkgAcqArchive(&Fetcher
, SrcList
, &Recs
, *Ver
, storefile
[i
]);
570 std::string
const filename
= cwd
+ flNotDir(storefile
[i
]);
571 storefile
[i
].assign(filename
);
572 I
->DestFile
.assign(filename
);
575 // Just print out the uris and exit if the --print-uris flag was used
576 if (_config
->FindB("APT::Get::Print-URIs") == true)
578 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
579 for (; I
!= Fetcher
.UriEnd(); ++I
)
580 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
581 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
585 if (_error
->PendingError() == true || CheckAuth(Fetcher
, false) == false)
589 if (AcquireRun(Fetcher
, 0, &Failed
, NULL
) == false)
592 // copy files in local sources to the current directory
593 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); ++I
)
594 if ((*I
)->Local
== true && (*I
)->Status
== pkgAcquire::Item::StatDone
)
596 std::string
const filename
= cwd
+ flNotDir((*I
)->DestFile
);
597 std::ifstream
src((*I
)->DestFile
.c_str(), std::ios::binary
);
598 std::ofstream
dst(filename
.c_str(), std::ios::binary
);
602 return Failed
== false;
605 // DoCheck - Perform the check operation /*{{{*/
606 // ---------------------------------------------------------------------
607 /* Opening automatically checks the system, this command is mostly used
609 bool DoCheck(CommandLine
&CmdL
)
618 // DoSource - Fetch a source archive /*{{{*/
619 // ---------------------------------------------------------------------
620 /* Fetch souce packages */
628 bool DoSource(CommandLine
&CmdL
)
631 if (Cache
.Open(false) == false)
634 if (CmdL
.FileSize() <= 1)
635 return _error
->Error(_("Must specify at least one package to fetch source for"));
637 // Read the source list
638 if (Cache
.BuildSourceList() == false)
640 pkgSourceList
*List
= Cache
.GetSourceList();
642 // Create the text record parsers
643 pkgRecords
Recs(Cache
);
644 pkgSrcRecords
SrcRecs(*List
);
645 if (_error
->PendingError() == true)
648 // Create the download object
649 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
651 Fetcher
.SetLog(&Stat
);
653 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
655 // insert all downloaded uris into this set to avoid downloading them
659 // Diff only mode only fetches .diff files
660 bool const diffOnly
= _config
->FindB("APT::Get::Diff-Only", false);
661 // Tar only mode only fetches .tar files
662 bool const tarOnly
= _config
->FindB("APT::Get::Tar-Only", false);
663 // Dsc only mode only fetches .dsc files
664 bool const dscOnly
= _config
->FindB("APT::Get::Dsc-Only", false);
666 // Load the requestd sources into the fetcher
668 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
671 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,Cache
);
675 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
678 string srec
= Last
->AsStr();
679 string::size_type pos
= srec
.find("\nVcs-");
680 while (pos
!= string::npos
)
682 pos
+= strlen("\nVcs-");
683 string vcs
= srec
.substr(pos
,srec
.find(":",pos
)-pos
);
686 pos
= srec
.find("\nVcs-", pos
);
689 pos
+= vcs
.length()+2;
690 string::size_type epos
= srec
.find("\n", pos
);
691 string uri
= srec
.substr(pos
,epos
-pos
).c_str();
692 ioprintf(c1out
, _("NOTICE: '%s' packaging is maintained in "
693 "the '%s' version control system at:\n"
695 Src
.c_str(), vcs
.c_str(), uri
.c_str());
697 ioprintf(c1out
,_("Please use:\n"
699 "to retrieve the latest (possibly unreleased) "
700 "updates to the package.\n"),
706 vector
<pkgSrcRecords::File
> Lst
;
707 if (Last
->Files(Lst
) == false) {
712 // Load them into the fetcher
713 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
716 // Try to guess what sort of file it is we are getting.
717 if (I
->Type
== "dsc")
719 Dsc
[J
].Package
= Last
->Package();
720 Dsc
[J
].Version
= Last
->Version();
721 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
724 // Handle the only options so that multiple can be used at once
725 if (diffOnly
== true || tarOnly
== true || dscOnly
== true)
727 if ((diffOnly
== true && I
->Type
== "diff") ||
728 (tarOnly
== true && I
->Type
== "tar") ||
729 (dscOnly
== true && I
->Type
== "dsc"))
730 ; // Fine, we want this file downloaded
735 // don't download the same uri twice (should this be moved to
736 // the fetcher interface itself?)
737 if(queued
.find(Last
->Index().ArchiveURI(I
->Path
)) != queued
.end())
739 queued
.insert(Last
->Index().ArchiveURI(I
->Path
));
741 // check if we have a file with that md5 sum already localy
742 if(!I
->MD5Hash
.empty() && FileExists(flNotDir(I
->Path
)))
744 FileFd
Fd(flNotDir(I
->Path
), FileFd::ReadOnly
);
746 sum
.AddFD(Fd
.Fd(), Fd
.Size());
748 if((string
)sum
.Result() == I
->MD5Hash
)
750 ioprintf(c1out
,_("Skipping already downloaded file '%s'\n"),
751 flNotDir(I
->Path
).c_str());
756 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
758 Last
->Index().SourceInfo(*Last
,*I
),Src
);
762 // Display statistics
763 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
764 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
765 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
767 // Check for enough free space
769 string OutputDir
= ".";
770 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
772 if (errno
== EOVERFLOW
)
773 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
776 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
778 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
781 if (statfs(OutputDir
.c_str(),&Stat
) != 0
782 #if HAVE_STRUCT_STATFS_F_TYPE
783 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
787 return _error
->Error(_("You don't have enough free space in %s"),
793 if (DebBytes
!= FetchBytes
)
794 //TRANSLATOR: The required space between number and unit is already included
795 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
796 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
797 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
799 //TRANSLATOR: The required space between number and unit is already included
800 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
801 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
802 SizeToStr(DebBytes
).c_str());
804 if (_config
->FindB("APT::Get::Simulate",false) == true)
806 for (unsigned I
= 0; I
!= J
; I
++)
807 ioprintf(cout
,_("Fetch source %s\n"),Dsc
[I
].Package
.c_str());
812 // Just print out the uris an exit if the --print-uris flag was used
813 if (_config
->FindB("APT::Get::Print-URIs") == true)
815 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
816 for (; I
!= Fetcher
.UriEnd(); ++I
)
817 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
818 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
825 if (AcquireRun(Fetcher
, 0, &Failed
, NULL
) == false || Failed
== true)
828 return _error
->Error(_("Failed to fetch some archives."));
831 if (_config
->FindB("APT::Get::Download-only",false) == true)
833 c1out
<< _("Download complete and in download only mode") << endl
;
838 // Unpack the sources
839 pid_t Process
= ExecFork();
843 bool const fixBroken
= _config
->FindB("APT::Get::Fix-Broken", false);
844 for (unsigned I
= 0; I
!= J
; ++I
)
846 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
848 // Diff only mode only fetches .diff files
849 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
850 _config
->FindB("APT::Get::Tar-Only",false) == true ||
851 Dsc
[I
].Dsc
.empty() == true)
854 // See if the package is already unpacked
856 if (fixBroken
== false && stat(Dir
.c_str(),&Stat
) == 0 &&
857 S_ISDIR(Stat
.st_mode
) != 0)
859 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
866 snprintf(S
,sizeof(S
),"%s -x %s",
867 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
871 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
872 fprintf(stderr
,_("Check if the 'dpkg-dev' package is installed.\n"));
877 // Try to compile it with dpkg-buildpackage
878 if (_config
->FindB("APT::Get::Compile",false) == true)
880 string buildopts
= _config
->Find("APT::Get::Host-Architecture");
881 if (buildopts
.empty() == false)
882 buildopts
= "-a" + buildopts
+ " ";
883 buildopts
.append(_config
->Find("DPkg::Build-Options","-b -uc"));
885 // Call dpkg-buildpackage
887 snprintf(S
,sizeof(S
),"cd %s && %s %s",
889 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
894 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
904 // Wait for the subprocess
906 while (waitpid(Process
,&Status
,0) != Process
)
910 return _error
->Errno("waitpid","Couldn't wait for subprocess");
913 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
914 return _error
->Error(_("Child process failed"));
919 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
920 // ---------------------------------------------------------------------
921 /* This function will look at the build depends list of the given source
922 package and install the necessary packages to make it true, or fail. */
923 bool DoBuildDep(CommandLine
&CmdL
)
927 _config
->Set("APT::Install-Recommends", false);
929 if (Cache
.Open(true) == false)
932 if (CmdL
.FileSize() <= 1)
933 return _error
->Error(_("Must specify at least one package to check builddeps for"));
935 // Read the source list
936 if (Cache
.BuildSourceList() == false)
938 pkgSourceList
*List
= Cache
.GetSourceList();
940 // Create the text record parsers
941 pkgRecords
Recs(Cache
);
942 pkgSrcRecords
SrcRecs(*List
);
943 if (_error
->PendingError() == true)
946 // Create the download object
947 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
949 if (Fetcher
.Setup(&Stat
) == false)
953 string hostArch
= _config
->Find("APT::Get::Host-Architecture");
954 if (hostArch
.empty() == false)
956 std::vector
<std::string
> archs
= APT::Configuration::getArchitectures();
957 if (std::find(archs
.begin(), archs
.end(), hostArch
) == archs
.end())
958 return _error
->Error(_("No architecture information available for %s. See apt.conf(5) APT::Architectures for setup"), hostArch
.c_str());
959 StripMultiArch
= false;
962 StripMultiArch
= true;
965 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
968 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,Cache
);
970 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
972 // Process the build-dependencies
973 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
974 // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary
975 if (hostArch
.empty() == false)
977 std::string nativeArch
= _config
->Find("APT::Architecture");
978 _config
->Set("APT::Architecture", hostArch
);
979 bool Success
= Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only", false), StripMultiArch
);
980 _config
->Set("APT::Architecture", nativeArch
);
981 if (Success
== false)
982 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
984 else if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only", false), StripMultiArch
) == false)
985 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
987 // Also ensure that build-essential packages are present
988 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
991 for (; Opts
; Opts
= Opts
->Next
)
993 if (Opts
->Value
.empty() == true)
996 pkgSrcRecords::Parser::BuildDepRec rec
;
997 rec
.Package
= Opts
->Value
;
998 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
1000 BuildDeps
.push_back(rec
);
1003 if (BuildDeps
.empty() == true)
1005 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
1009 // Install the requested packages
1010 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
1011 pkgProblemResolver
Fix(Cache
);
1012 bool skipAlternatives
= false; // skip remaining alternatives in an or group
1013 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); ++D
)
1015 bool hasAlternatives
= (((*D
).Op
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
);
1017 if (skipAlternatives
== true)
1020 * if there are alternatives, we've already picked one, so skip
1023 * TODO: this means that if there's a build-dep on A|B and B is
1024 * installed, we'll still try to install A; more importantly,
1025 * if A is currently broken, we cannot go back and try B. To fix
1026 * this would require we do a Resolve cycle for each package we
1027 * add to the install list. Ugh
1029 if (!hasAlternatives
)
1030 skipAlternatives
= false; // end of or group
1034 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1035 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1037 pkgCache::GrpIterator Grp
= Cache
->FindGrp((*D
).Package
);
1038 // Build-conflicts on unknown packages are silently ignored
1039 if (Grp
.end() == true)
1042 for (pkgCache::PkgIterator Pkg
= Grp
.PackageList(); Pkg
.end() == false; Pkg
= Grp
.NextPkg(Pkg
))
1044 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1046 * Remove if we have an installed version that satisfies the
1049 if (IV
.end() == false &&
1050 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1051 TryToInstallBuildDep(Pkg
,Cache
,Fix
,true,false);
1054 else // BuildDep || BuildDepIndep
1056 if (_config
->FindB("Debug::BuildDeps",false) == true)
1057 cout
<< "Looking for " << (*D
).Package
<< "...\n";
1059 pkgCache::PkgIterator Pkg
;
1062 if (StripMultiArch
== false && D
->Type
!= pkgSrcRecords::Parser::BuildDependIndep
)
1064 size_t const colon
= D
->Package
.find(":");
1065 if (colon
!= string::npos
)
1067 if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0 || strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1068 Pkg
= Cache
->FindPkg(D
->Package
.substr(0,colon
));
1070 Pkg
= Cache
->FindPkg(D
->Package
);
1073 Pkg
= Cache
->FindPkg(D
->Package
, hostArch
);
1075 // a bad version either is invalid or doesn't satify dependency
1076 #define BADVER(Ver) (Ver.end() == true || \
1077 (D->Version.empty() == false && \
1078 Cache->VS().CheckDep(Ver.VerStr(),D->Op,D->Version.c_str()) == false))
1080 APT::VersionList verlist
;
1081 if (Pkg
.end() == false)
1083 pkgCache::VerIterator Ver
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1084 if (BADVER(Ver
) == false)
1085 verlist
.insert(Ver
);
1086 Ver
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1087 if (BADVER(Ver
) == false)
1088 verlist
.insert(Ver
);
1090 if (verlist
.empty() == true)
1092 pkgCache::PkgIterator BuildPkg
= Cache
->FindPkg(D
->Package
, "native");
1093 if (BuildPkg
.end() == false && Pkg
!= BuildPkg
)
1095 pkgCache::VerIterator Ver
= (*Cache
)[BuildPkg
].InstVerIter(*Cache
);
1096 if (BADVER(Ver
) == false)
1097 verlist
.insert(Ver
);
1098 Ver
= (*Cache
)[BuildPkg
].CandidateVerIter(*Cache
);
1099 if (BADVER(Ver
) == false)
1100 verlist
.insert(Ver
);
1106 // We need to decide if host or build arch, so find a version we can look at
1107 APT::VersionList::const_iterator Ver
= verlist
.begin();
1108 for (; Ver
!= verlist
.end(); ++Ver
)
1111 if (Ver
->MultiArch
== pkgCache::Version::None
|| Ver
->MultiArch
== pkgCache::Version::All
)
1113 if (colon
== string::npos
)
1114 Pkg
= Ver
.ParentPkg().Group().FindPkg(hostArch
);
1115 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0)
1116 forbidden
= "Multi-Arch: none";
1117 else if (strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1118 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1120 else if (Ver
->MultiArch
== pkgCache::Version::Same
)
1122 if (colon
== string::npos
)
1123 Pkg
= Ver
.ParentPkg().Group().FindPkg(hostArch
);
1124 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0)
1125 forbidden
= "Multi-Arch: same";
1126 else if (strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1127 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1129 else if ((Ver
->MultiArch
& pkgCache::Version::Foreign
) == pkgCache::Version::Foreign
)
1131 if (colon
== string::npos
)
1132 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1133 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0 ||
1134 strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1135 forbidden
= "Multi-Arch: foreign";
1137 else if ((Ver
->MultiArch
& pkgCache::Version::Allowed
) == pkgCache::Version::Allowed
)
1139 if (colon
== string::npos
)
1140 Pkg
= Ver
.ParentPkg().Group().FindPkg(hostArch
);
1141 else if (strcmp(D
->Package
.c_str() + colon
, ":any") == 0)
1143 // prefer any installed over preferred non-installed architectures
1144 pkgCache::GrpIterator Grp
= Ver
.ParentPkg().Group();
1145 // we don't check for version here as we are better of with upgrading than remove and install
1146 for (Pkg
= Grp
.PackageList(); Pkg
.end() == false; Pkg
= Grp
.NextPkg(Pkg
))
1147 if (Pkg
.CurrentVer().end() == false)
1149 if (Pkg
.end() == true)
1150 Pkg
= Grp
.FindPreferredPkg(true);
1152 else if (strcmp(D
->Package
.c_str() + colon
, ":native") == 0)
1153 Pkg
= Ver
.ParentPkg().Group().FindPkg("native");
1156 if (forbidden
.empty() == false)
1158 if (_config
->FindB("Debug::BuildDeps",false) == true)
1159 cout
<< D
->Package
.substr(colon
, string::npos
) << " is not allowed from " << forbidden
<< " package " << (*D
).Package
<< " (" << Ver
.VerStr() << ")" << endl
;
1163 //we found a good version
1166 if (Ver
== verlist
.end())
1168 if (_config
->FindB("Debug::BuildDeps",false) == true)
1169 cout
<< " No multiarch info as we have no satisfying installed nor candidate for " << D
->Package
<< " on build or host arch" << endl
;
1171 if (forbidden
.empty() == false)
1173 if (hasAlternatives
)
1175 return _error
->Error(_("%s dependency for %s can't be satisfied "
1176 "because %s is not allowed on '%s' packages"),
1177 Last
->BuildDepType(D
->Type
), Src
.c_str(),
1178 D
->Package
.c_str(), forbidden
.c_str());
1183 Pkg
= Cache
->FindPkg(D
->Package
);
1185 if (Pkg
.end() == true || (Pkg
->VersionList
== 0 && Pkg
->ProvidesList
== 0))
1187 if (_config
->FindB("Debug::BuildDeps",false) == true)
1188 cout
<< " (not found)" << (*D
).Package
<< endl
;
1190 if (hasAlternatives
)
1193 return _error
->Error(_("%s dependency for %s cannot be satisfied "
1194 "because the package %s cannot be found"),
1195 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
1196 (*D
).Package
.c_str());
1199 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1200 if (IV
.end() == false)
1202 if (_config
->FindB("Debug::BuildDeps",false) == true)
1203 cout
<< " Is installed\n";
1205 if (D
->Version
.empty() == true ||
1206 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1208 skipAlternatives
= hasAlternatives
;
1212 if (_config
->FindB("Debug::BuildDeps",false) == true)
1213 cout
<< " ...but the installed version doesn't meet the version requirement\n";
1215 if (((*D
).Op
& pkgCache::Dep::LessEq
) == pkgCache::Dep::LessEq
)
1216 return _error
->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
1217 Last
->BuildDepType((*D
).Type
), Src
.c_str(), Pkg
.FullName(true).c_str());
1220 // Only consider virtual packages if there is no versioned dependency
1221 if ((*D
).Version
.empty() == true)
1224 * If this is a virtual package, we need to check the list of
1225 * packages that provide it and see if any of those are
1228 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
1229 for (; Prv
.end() != true; ++Prv
)
1231 if (_config
->FindB("Debug::BuildDeps",false) == true)
1232 cout
<< " Checking provider " << Prv
.OwnerPkg().FullName() << endl
;
1234 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
1238 if (Prv
.end() == false)
1240 if (_config
->FindB("Debug::BuildDeps",false) == true)
1241 cout
<< " Is provided by installed package " << Prv
.OwnerPkg().FullName() << endl
;
1242 skipAlternatives
= hasAlternatives
;
1246 else // versioned dependency
1248 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1249 if (CV
.end() == true ||
1250 Cache
->VS().CheckDep(CV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == false)
1252 if (hasAlternatives
)
1254 else if (CV
.end() == false)
1255 return _error
->Error(_("%s dependency for %s cannot be satisfied "
1256 "because candidate version of package %s "
1257 "can't satisfy version requirements"),
1258 Last
->BuildDepType(D
->Type
), Src
.c_str(),
1259 D
->Package
.c_str());
1261 return _error
->Error(_("%s dependency for %s cannot be satisfied "
1262 "because package %s has no candidate version"),
1263 Last
->BuildDepType(D
->Type
), Src
.c_str(),
1264 D
->Package
.c_str());
1268 if (TryToInstallBuildDep(Pkg
,Cache
,Fix
,false,false,false) == true)
1270 // We successfully installed something; skip remaining alternatives
1271 skipAlternatives
= hasAlternatives
;
1272 if(_config
->FindB("APT::Get::Build-Dep-Automatic", false) == true)
1273 Cache
->MarkAuto(Pkg
, true);
1276 else if (hasAlternatives
)
1278 if (_config
->FindB("Debug::BuildDeps",false) == true)
1279 cout
<< " Unsatisfiable, trying alternatives\n";
1284 return _error
->Error(_("Failed to satisfy %s dependency for %s: %s"),
1285 Last
->BuildDepType((*D
).Type
),
1287 (*D
).Package
.c_str());
1292 if (Fix
.Resolve(true) == false)
1295 // Now we check the state of the packages,
1296 if (Cache
->BrokenCount() != 0)
1298 ShowBroken(cout
, Cache
, false);
1299 return _error
->Error(_("Build-dependencies for %s could not be satisfied."),*I
);
1303 if (InstallPackages(Cache
, false, true) == false)
1304 return _error
->Error(_("Failed to process build dependencies"));
1308 // GetChangelogPath - return a path pointing to a changelog file or dir /*{{{*/
1309 // ---------------------------------------------------------------------
1310 /* This returns a "path" string for the changelog url construction.
1311 * Please note that its not complete, it either needs a "/changelog"
1312 * appended (for the packages.debian.org/changelogs site) or a
1313 * ".changelog" (for third party sites that store the changelog in the
1314 * pool/ next to the deb itself)
1315 * Example return: "pool/main/a/apt/apt_0.8.8ubuntu3"
1317 string
GetChangelogPath(CacheFile
&Cache
,
1318 pkgCache::PkgIterator Pkg
,
1319 pkgCache::VerIterator Ver
)
1323 pkgRecords
Recs(Cache
);
1324 pkgRecords::Parser
&rec
=Recs
.Lookup(Ver
.FileList());
1325 string srcpkg
= rec
.SourcePkg().empty() ? Pkg
.Name() : rec
.SourcePkg();
1326 string ver
= Ver
.VerStr();
1327 // if there is a source version it always wins
1328 if (rec
.SourceVer() != "")
1329 ver
= rec
.SourceVer();
1330 path
= flNotFile(rec
.FileName());
1331 path
+= srcpkg
+ "_" + StripEpoch(ver
);
1335 // GuessThirdPartyChangelogUri - return url /*{{{*/
1336 // ---------------------------------------------------------------------
1337 /* Contruct a changelog file path for third party sites that do not use
1338 * packages.debian.org/changelogs
1339 * This simply uses the ArchiveURI() of the source pkg and looks for
1340 * a .changelog file there, Example for "mediabuntu":
1341 * apt-get changelog mplayer-doc:
1342 * http://packages.medibuntu.org/pool/non-free/m/mplayer/mplayer_1.0~rc4~try1.dsfg1-1ubuntu1+medibuntu1.changelog
1344 bool GuessThirdPartyChangelogUri(CacheFile
&Cache
,
1345 pkgCache::PkgIterator Pkg
,
1346 pkgCache::VerIterator Ver
,
1349 // get the binary deb server path
1350 pkgCache::VerFileIterator Vf
= Ver
.FileList();
1351 if (Vf
.end() == true)
1353 pkgCache::PkgFileIterator F
= Vf
.File();
1354 pkgIndexFile
*index
;
1355 pkgSourceList
*SrcList
= Cache
.GetSourceList();
1356 if(SrcList
->FindIndex(F
, index
) == false)
1359 // get archive uri for the binary deb
1360 string path_without_dot_changelog
= GetChangelogPath(Cache
, Pkg
, Ver
);
1361 out_uri
= index
->ArchiveURI(path_without_dot_changelog
+ ".changelog");
1363 // now strip away the filename and add srcpkg_srcver.changelog
1367 // DownloadChangelog - Download the changelog /*{{{*/
1368 // ---------------------------------------------------------------------
1369 bool DownloadChangelog(CacheFile
&CacheFile
, pkgAcquire
&Fetcher
,
1370 pkgCache::VerIterator Ver
, string targetfile
)
1371 /* Download a changelog file for the given package version to
1372 * targetfile. This will first try the server from Apt::Changelogs::Server
1373 * (http://packages.debian.org/changelogs by default) and if that gives
1374 * a 404 tries to get it from the archive directly (see
1375 * GuessThirdPartyChangelogUri for details how)
1381 string changelog_uri
;
1383 // data structures we need
1384 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
1386 // make the server root configurable
1387 server
= _config
->Find("Apt::Changelogs::Server",
1388 "http://packages.debian.org/changelogs");
1389 path
= GetChangelogPath(CacheFile
, Pkg
, Ver
);
1390 strprintf(changelog_uri
, "%s/%s/changelog", server
.c_str(), path
.c_str());
1391 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
1393 std::cout
<< '\'' << changelog_uri
<< '\'' << std::endl
;
1397 strprintf(descr
, _("Changelog for %s (%s)"), Pkg
.Name(), changelog_uri
.c_str());
1399 new pkgAcqFile(&Fetcher
, changelog_uri
, "", 0, descr
, Pkg
.Name(), "ignored", targetfile
);
1401 // try downloading it, if that fails, try third-party-changelogs location
1402 // FIXME: Fetcher.Run() is "Continue" even if I get a 404?!?
1404 if (!FileExists(targetfile
))
1406 string third_party_uri
;
1407 if (GuessThirdPartyChangelogUri(CacheFile
, Pkg
, Ver
, third_party_uri
))
1409 strprintf(descr
, _("Changelog for %s (%s)"), Pkg
.Name(), third_party_uri
.c_str());
1410 new pkgAcqFile(&Fetcher
, third_party_uri
, "", 0, descr
, Pkg
.Name(), "ignored", targetfile
);
1415 if (FileExists(targetfile
))
1419 return _error
->Error("changelog download failed");
1422 // DoChangelog - Get changelog from the command line /*{{{*/
1423 // ---------------------------------------------------------------------
1424 bool DoChangelog(CommandLine
&CmdL
)
1427 if (Cache
.ReadOnlyOpen() == false)
1430 APT::CacheSetHelper
helper(c0out
);
1431 APT::VersionList verset
= APT::VersionList::FromCommandLine(Cache
,
1432 CmdL
.FileList
+ 1, APT::VersionList::CANDIDATE
, helper
);
1433 if (verset
.empty() == true)
1437 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
1439 bool Success
= true;
1440 for (APT::VersionList::const_iterator Ver
= verset
.begin();
1441 Ver
!= verset
.end(); ++Ver
)
1442 Success
&= DownloadChangelog(Cache
, Fetcher
, Ver
, "");
1446 AcqTextStatus
Stat(ScreenWidth
, _config
->FindI("quiet",0));
1447 Fetcher
.Setup(&Stat
);
1449 bool const downOnly
= _config
->FindB("APT::Get::Download-Only", false);
1452 char* tmpdir
= NULL
;
1453 if (downOnly
== false)
1455 const char* const tmpDir
= getenv("TMPDIR");
1456 if (tmpDir
!= NULL
&& *tmpDir
!= '\0')
1457 snprintf(tmpname
, sizeof(tmpname
), "%s/apt-changelog-XXXXXX", tmpDir
);
1459 strncpy(tmpname
, "/tmp/apt-changelog-XXXXXX", sizeof(tmpname
));
1460 tmpdir
= mkdtemp(tmpname
);
1462 return _error
->Errno("mkdtemp", "mkdtemp failed");
1465 for (APT::VersionList::const_iterator Ver
= verset
.begin();
1466 Ver
!= verset
.end();
1469 string changelogfile
;
1470 if (downOnly
== false)
1471 changelogfile
.append(tmpname
).append("changelog");
1473 changelogfile
.append(Ver
.ParentPkg().Name()).append(".changelog");
1474 if (DownloadChangelog(Cache
, Fetcher
, Ver
, changelogfile
) && downOnly
== false)
1476 DisplayFileInPager(changelogfile
);
1477 // cleanup temp file
1478 unlink(changelogfile
.c_str());
1487 // ShowHelp - Show a help screen /*{{{*/
1488 // ---------------------------------------------------------------------
1490 bool ShowHelp(CommandLine
&CmdL
)
1492 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,PACKAGE_VERSION
,
1493 COMMON_ARCH
,__DATE__
,__TIME__
);
1495 if (_config
->FindB("version") == true)
1497 cout
<< _("Supported modules:") << endl
;
1499 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
1501 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
1502 if (_system
!= 0 && _system
->VS
== VS
)
1506 cout
<< "Ver: " << VS
->Label
<< endl
;
1508 /* Print out all the packaging systems that will work with
1510 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
1512 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
1517 if (Sys
->VS
->TestCompatibility(*VS
) == true)
1518 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
1522 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
1524 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
1525 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
1528 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
1530 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
1531 cout
<< " Idx: " << Type
->Label
<< endl
;
1538 _("Usage: apt-get [options] command\n"
1539 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
1540 " apt-get [options] source pkg1 [pkg2 ...]\n"
1542 "apt-get is a simple command line interface for downloading and\n"
1543 "installing packages. The most frequently used commands are update\n"
1547 " update - Retrieve new lists of packages\n"
1548 " upgrade - Perform an upgrade\n"
1549 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
1550 " remove - Remove packages\n"
1551 " autoremove - Remove automatically all unused packages\n"
1552 " purge - Remove packages and config files\n"
1553 " source - Download source archives\n"
1554 " build-dep - Configure build-dependencies for source packages\n"
1555 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
1556 " dselect-upgrade - Follow dselect selections\n"
1557 " clean - Erase downloaded archive files\n"
1558 " autoclean - Erase old downloaded archive files\n"
1559 " check - Verify that there are no broken dependencies\n"
1560 " changelog - Download and display the changelog for the given package\n"
1561 " download - Download the binary package into the current directory\n"
1564 " -h This help text.\n"
1565 " -q Loggable output - no progress indicator\n"
1566 " -qq No output except for errors\n"
1567 " -d Download only - do NOT install or unpack archives\n"
1568 " -s No-act. Perform ordering simulation\n"
1569 " -y Assume Yes to all queries and do not prompt\n"
1570 " -f Attempt to correct a system with broken dependencies in place\n"
1571 " -m Attempt to continue if archives are unlocatable\n"
1572 " -u Show a list of upgraded packages as well\n"
1573 " -b Build the source package after fetching it\n"
1574 " -V Show verbose version numbers\n"
1575 " -c=? Read this configuration file\n"
1576 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
1577 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
1578 "pages for more information and options.\n"
1579 " This APT has Super Cow Powers.\n");
1583 // SigWinch - Window size change signal handler /*{{{*/
1584 // ---------------------------------------------------------------------
1588 // Riped from GNU ls
1592 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
1593 ScreenWidth
= ws
.ws_col
- 1;
1597 bool DoUpgrade(CommandLine
&CmdL
) /*{{{*/
1599 if (_config
->FindB("APT::Get::Upgrade-Allow-New", false) == true)
1600 return DoUpgradeWithAllowNewPackages(CmdL
);
1602 return DoUpgradeNoNewPackages(CmdL
);
1605 int main(int argc
,const char *argv
[]) /*{{{*/
1607 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
1608 {"upgrade",&DoUpgrade
},
1609 {"install",&DoInstall
},
1610 {"remove",&DoInstall
},
1611 {"purge",&DoInstall
},
1612 {"autoremove",&DoInstall
},
1613 {"markauto",&DoMarkAuto
},
1614 {"unmarkauto",&DoMarkAuto
},
1615 {"dist-upgrade",&DoDistUpgrade
},
1616 {"dselect-upgrade",&DoDSelectUpgrade
},
1617 {"build-dep",&DoBuildDep
},
1619 {"autoclean",&DoAutoClean
},
1621 {"source",&DoSource
},
1622 {"download",&DoDownload
},
1623 {"changelog",&DoChangelog
},
1628 std::vector
<CommandLine::Args
> Args
= getCommandArgs("apt-get", CommandLine::GetCommand(Cmds
, argc
, argv
));
1630 // Set up gettext support
1631 setlocale(LC_ALL
,"");
1632 textdomain(PACKAGE
);
1634 // Parse the command line and initialize the package library
1635 CommandLine
CmdL(Args
.data(),_config
);
1636 if (pkgInitConfig(*_config
) == false ||
1637 CmdL
.Parse(argc
,argv
) == false ||
1638 pkgInitSystem(*_config
,_system
) == false)
1640 if (_config
->FindB("version") == true)
1643 _error
->DumpErrors();
1647 // See if the help should be shown
1648 if (_config
->FindB("help") == true ||
1649 _config
->FindB("version") == true ||
1650 CmdL
.FileSize() == 0)
1656 // see if we are in simulate mode
1657 CheckSimulateMode(CmdL
);
1659 // Deal with stdout not being a tty
1660 if (!isatty(STDOUT_FILENO
) && _config
->FindI("quiet", -1) == -1)
1661 _config
->Set("quiet","1");
1663 // Setup the output streams
1666 // Setup the signals
1667 signal(SIGPIPE
,SIG_IGN
);
1668 signal(SIGWINCH
,SigWinch
);
1671 // Match the operation
1672 CmdL
.DispatchArg(Cmds
);
1674 // Print any errors or warnings found during parsing
1675 bool const Errors
= _error
->PendingError();
1676 if (_config
->FindI("quiet",0) > 0)
1677 _error
->DumpErrors();
1679 _error
->DumpErrors(GlobalError::DEBUG
);
1680 return Errors
== true ? 100 : 0;