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 /*{{{*/
28 #define _LARGEFILE_SOURCE
29 #define _LARGEFILE64_SOURCE
31 #include <apt-pkg/aptconfiguration.h>
32 #include <apt-pkg/error.h>
33 #include <apt-pkg/cmndline.h>
34 #include <apt-pkg/init.h>
35 #include <apt-pkg/depcache.h>
36 #include <apt-pkg/sourcelist.h>
37 #include <apt-pkg/algorithms.h>
38 #include <apt-pkg/acquire-item.h>
39 #include <apt-pkg/strutl.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>
52 #include "acqprogress.h"
59 #include <sys/ioctl.h>
61 #include <sys/statfs.h>
62 #include <sys/statvfs.h>
71 #define statfs statfs64
72 #define statvfs statvfs64
75 #define RAMFS_MAGIC 0x858458f6
82 ofstream
devnull("/dev/null");
83 unsigned int ScreenWidth
= 80 - 1; /* - 1 for the cursor */
85 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
86 // ---------------------------------------------------------------------
88 class CacheFile
: public pkgCacheFile
90 static pkgCache
*SortCache
;
91 static int NameComp(const void *a
,const void *b
);
94 pkgCache::Package
**List
;
97 bool CheckDeps(bool AllowBroken
= false);
98 bool BuildCaches(bool WithLock
= true)
100 OpTextProgress
Prog(*_config
);
101 if (pkgCacheFile::BuildCaches(&Prog
,WithLock
) == false)
105 bool Open(bool WithLock
= true)
107 OpTextProgress
Prog(*_config
);
108 if (pkgCacheFile::Open(&Prog
,WithLock
) == false)
114 bool OpenForInstall()
116 if (_config
->FindB("APT::Get::Print-URIs") == true)
121 CacheFile() : List(0) {};
128 // YnPrompt - Yes No Prompt. /*{{{*/
129 // ---------------------------------------------------------------------
130 /* Returns true on a Yes.*/
131 bool YnPrompt(bool Default
=true)
133 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
135 c1out
<< _("Y") << endl
;
139 char response
[1024] = "";
140 cin
.getline(response
, sizeof(response
));
145 if (strlen(response
) == 0)
151 Res
= regcomp(&Pattern
, nl_langinfo(YESEXPR
),
152 REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
156 regerror(Res
,&Pattern
,Error
,sizeof(Error
));
157 return _error
->Error(_("Regex compilation error - %s"),Error
);
160 Res
= regexec(&Pattern
, response
, 0, NULL
, 0);
166 // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
167 // ---------------------------------------------------------------------
168 /* Returns true on a Yes.*/
169 bool AnalPrompt(const char *Text
)
172 cin
.getline(Buf
,sizeof(Buf
));
173 if (strcmp(Buf
,Text
) == 0)
178 // ShowList - Show a list /*{{{*/
179 // ---------------------------------------------------------------------
180 /* This prints out a string of space separated words with a title and
181 a two space indent line wraped to the current screen width. */
182 bool ShowList(ostream
&out
,string Title
,string List
,string VersionsList
)
184 if (List
.empty() == true)
186 // trim trailing space
187 int NonSpace
= List
.find_last_not_of(' ');
190 List
= List
.erase(NonSpace
+ 1);
191 if (List
.empty() == true)
195 // Acount for the leading space
196 int ScreenWidth
= ::ScreenWidth
- 3;
198 out
<< Title
<< endl
;
199 string::size_type Start
= 0;
200 string::size_type VersionsStart
= 0;
201 while (Start
< List
.size())
203 if(_config
->FindB("APT::Get::Show-Versions",false) == true &&
204 VersionsList
.size() > 0) {
205 string::size_type End
;
206 string::size_type VersionsEnd
;
208 End
= List
.find(' ',Start
);
209 VersionsEnd
= VersionsList
.find('\n', VersionsStart
);
211 out
<< " " << string(List
,Start
,End
- Start
) << " (" <<
212 string(VersionsList
,VersionsStart
,VersionsEnd
- VersionsStart
) <<
215 if (End
== string::npos
|| End
< Start
)
216 End
= Start
+ ScreenWidth
;
219 VersionsStart
= VersionsEnd
+ 1;
221 string::size_type End
;
223 if (Start
+ ScreenWidth
>= List
.size())
226 End
= List
.rfind(' ',Start
+ScreenWidth
);
228 if (End
== string::npos
|| End
< Start
)
229 End
= Start
+ ScreenWidth
;
230 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
238 // ShowBroken - Debugging aide /*{{{*/
239 // ---------------------------------------------------------------------
240 /* This prints out the names of all the packages that are broken along
241 with the name of each each broken dependency and a quite version
244 The output looks like:
245 The following packages have unmet dependencies:
246 exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed
247 Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
248 Depends: libsasl7 but it is not going to be installed
250 void ShowBroken(ostream
&out
,CacheFile
&Cache
,bool Now
)
252 out
<< _("The following packages have unmet dependencies:") << endl
;
253 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
255 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
259 if (Cache
[I
].NowBroken() == false)
264 if (Cache
[I
].InstBroken() == false)
268 // Print out each package and the failed dependencies
269 out
<< " " << I
.FullName(true) << " :";
270 unsigned const Indent
= I
.FullName(true).size() + 3;
272 pkgCache::VerIterator Ver
;
275 Ver
= I
.CurrentVer();
277 Ver
= Cache
[I
].InstVerIter(Cache
);
279 if (Ver
.end() == true)
285 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false;)
287 // Compute a single dependency element (glob or)
288 pkgCache::DepIterator Start
;
289 pkgCache::DepIterator End
;
290 D
.GlobOr(Start
,End
); // advances D
292 if (Cache
->IsImportantDep(End
) == false)
297 if ((Cache
[End
] & pkgDepCache::DepGNow
) == pkgDepCache::DepGNow
)
302 if ((Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
310 for (unsigned J
= 0; J
!= Indent
; J
++)
314 if (FirstOr
== false)
316 for (unsigned J
= 0; J
!= strlen(End
.DepType()) + 3; J
++)
320 out
<< ' ' << End
.DepType() << ": ";
323 out
<< Start
.TargetPkg().FullName(true);
325 // Show a quick summary of the version requirements
326 if (Start
.TargetVer() != 0)
327 out
<< " (" << Start
.CompType() << " " << Start
.TargetVer() << ")";
329 /* Show a summary of the target package if possible. In the case
330 of virtual packages we show nothing */
331 pkgCache::PkgIterator Targ
= Start
.TargetPkg();
332 if (Targ
->ProvidesList
== 0)
335 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
337 Ver
= Targ
.CurrentVer();
339 if (Ver
.end() == false)
342 ioprintf(out
,_("but %s is installed"),Ver
.VerStr());
344 ioprintf(out
,_("but %s is to be installed"),Ver
.VerStr());
348 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
350 if (Targ
->ProvidesList
== 0)
351 out
<< _("but it is not installable");
353 out
<< _("but it is a virtual package");
356 out
<< (Now
?_("but it is not installed"):_("but it is not going to be installed"));
372 // ShowNew - Show packages to newly install /*{{{*/
373 // ---------------------------------------------------------------------
375 void ShowNew(ostream
&out
,CacheFile
&Cache
)
377 /* Print out a list of packages that are going to be installed extra
378 to what the user asked */
381 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
383 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
384 if (Cache
[I
].NewInstall() == true) {
385 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
387 List
+= I
.FullName(true) + " ";
388 VersionsList
+= string(Cache
[I
].CandVersion
) + "\n";
392 ShowList(out
,_("The following NEW packages will be installed:"),List
,VersionsList
);
395 // ShowDel - Show packages to delete /*{{{*/
396 // ---------------------------------------------------------------------
398 void ShowDel(ostream
&out
,CacheFile
&Cache
)
400 /* Print out a list of packages that are going to be removed extra
401 to what the user asked */
404 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
406 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
407 if (Cache
[I
].Delete() == true)
409 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
411 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
412 List
+= I
.FullName(true) + "* ";
414 List
+= I
.FullName(true) + " ";
416 VersionsList
+= string(Cache
[I
].CandVersion
)+ "\n";
420 ShowList(out
,_("The following packages will be REMOVED:"),List
,VersionsList
);
423 // ShowKept - Show kept packages /*{{{*/
424 // ---------------------------------------------------------------------
426 void ShowKept(ostream
&out
,CacheFile
&Cache
)
430 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
432 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
435 if (Cache
[I
].Upgrade() == true || Cache
[I
].Upgradable() == false ||
436 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
439 List
+= I
.FullName(true) + " ";
440 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
442 ShowList(out
,_("The following packages have been kept back:"),List
,VersionsList
);
445 // ShowUpgraded - Show upgraded packages /*{{{*/
446 // ---------------------------------------------------------------------
448 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
452 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
454 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
457 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
459 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
462 List
+= I
.FullName(true) + " ";
463 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
465 ShowList(out
,_("The following packages will be upgraded:"),List
,VersionsList
);
468 // ShowDowngraded - Show downgraded packages /*{{{*/
469 // ---------------------------------------------------------------------
471 bool ShowDowngraded(ostream
&out
,CacheFile
&Cache
)
475 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
477 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
480 if (Cache
[I
].Downgrade() == false || Cache
[I
].NewInstall() == true)
482 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
485 List
+= I
.FullName(true) + " ";
486 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
488 return ShowList(out
,_("The following packages will be DOWNGRADED:"),List
,VersionsList
);
491 // ShowHold - Show held but changed packages /*{{{*/
492 // ---------------------------------------------------------------------
494 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
498 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
500 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
501 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
502 I
->SelectedState
== pkgCache::State::Hold
) {
503 List
+= I
.FullName(true) + " ";
504 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
508 return ShowList(out
,_("The following held packages will be changed:"),List
,VersionsList
);
511 // ShowEssential - Show an essential package warning /*{{{*/
512 // ---------------------------------------------------------------------
513 /* This prints out a warning message that is not to be ignored. It shows
514 all essential packages and their dependents that are to be removed.
515 It is insanely risky to remove the dependents of an essential package! */
516 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
520 bool *Added
= new bool[Cache
->Head().PackageCount
];
521 for (unsigned int I
= 0; I
!= Cache
->Head().PackageCount
; I
++)
524 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
526 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
527 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
&&
528 (I
->Flags
& pkgCache::Flag::Important
) != pkgCache::Flag::Important
)
531 // The essential package is being removed
532 if (Cache
[I
].Delete() == true)
534 if (Added
[I
->ID
] == false)
537 List
+= I
.FullName(true) + " ";
538 //VersionsList += string(Cache[I].CurVersion) + "\n"; ???
542 if (I
->CurrentVer
== 0)
545 // Print out any essential package depenendents that are to be removed
546 for (pkgCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
548 // Skip everything but depends
549 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
550 D
->Type
!= pkgCache::Dep::Depends
)
553 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
554 if (Cache
[P
].Delete() == true)
556 if (Added
[P
->ID
] == true)
561 snprintf(S
,sizeof(S
),_("%s (due to %s) "),P
.FullName(true).c_str(),I
.FullName(true).c_str());
563 //VersionsList += "\n"; ???
569 return ShowList(out
,_("WARNING: The following essential packages will be removed.\n"
570 "This should NOT be done unless you know exactly what you are doing!"),List
,VersionsList
);
574 // Stats - Show some statistics /*{{{*/
575 // ---------------------------------------------------------------------
577 void Stats(ostream
&out
,pkgDepCache
&Dep
)
579 unsigned long Upgrade
= 0;
580 unsigned long Downgrade
= 0;
581 unsigned long Install
= 0;
582 unsigned long ReInstall
= 0;
583 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
585 if (pkgCache::VerIterator(Dep
, Dep
[I
].CandidateVer
).Pseudo() == true)
588 if (Dep
[I
].NewInstall() == true)
592 if (Dep
[I
].Upgrade() == true)
595 if (Dep
[I
].Downgrade() == true)
599 if (Dep
[I
].Delete() == false && (Dep
[I
].iFlags
& pkgDepCache::ReInstall
) == pkgDepCache::ReInstall
)
603 ioprintf(out
,_("%lu upgraded, %lu newly installed, "),
607 ioprintf(out
,_("%lu reinstalled, "),ReInstall
);
609 ioprintf(out
,_("%lu downgraded, "),Downgrade
);
611 ioprintf(out
,_("%lu to remove and %lu not upgraded.\n"),
612 Dep
.DelCount(),Dep
.KeepCount());
614 if (Dep
.BadCount() != 0)
615 ioprintf(out
,_("%lu not fully installed or removed.\n"),
619 // CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/
620 class CacheSetHelperAPTGet
: public APT::CacheSetHelper
{
621 /** \brief stream message should be printed to */
623 /** \brief were things like Task or RegEx used to select packages? */
624 bool explicitlyNamed
;
626 APT::PackageSet virtualPkgs
;
629 CacheSetHelperAPTGet(std::ostream
&out
) : APT::CacheSetHelper(true), out(out
) {
630 explicitlyNamed
= true;
633 virtual void showTaskSelection(APT::PackageSet
const &pkgset
, string
const &pattern
) {
634 for (APT::PackageSet::const_iterator Pkg
= pkgset
.begin(); Pkg
!= pkgset
.end(); ++Pkg
)
635 ioprintf(out
, _("Note, selecting '%s' for task '%s'\n"),
636 Pkg
.FullName(true).c_str(), pattern
.c_str());
637 explicitlyNamed
= false;
639 virtual void showRegExSelection(APT::PackageSet
const &pkgset
, string
const &pattern
) {
640 for (APT::PackageSet::const_iterator Pkg
= pkgset
.begin(); Pkg
!= pkgset
.end(); ++Pkg
)
641 ioprintf(out
, _("Note, selecting '%s' for regex '%s'\n"),
642 Pkg
.FullName(true).c_str(), pattern
.c_str());
643 explicitlyNamed
= false;
645 virtual void showSelectedVersion(pkgCache::PkgIterator
const &Pkg
, pkgCache::VerIterator
const Ver
,
646 string
const &ver
, bool const &verIsRel
) {
647 if (ver
!= Ver
.VerStr())
648 ioprintf(out
, _("Selected version '%s' (%s) for '%s'\n"),
649 Ver
.VerStr(), Ver
.RelStr().c_str(), Pkg
.FullName(true).c_str());
652 bool showVirtualPackageErrors(pkgCacheFile
&Cache
) {
653 if (virtualPkgs
.empty() == true)
655 for (APT::PackageSet::const_iterator Pkg
= virtualPkgs
.begin();
656 Pkg
!= virtualPkgs
.end(); ++Pkg
) {
657 if (Pkg
->ProvidesList
!= 0) {
658 ioprintf(c1out
,_("Package %s is a virtual package provided by:\n"),
659 Pkg
.FullName(true).c_str());
661 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
662 unsigned short provider
= 0;
663 for (; I
.end() == false; ++I
) {
664 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
666 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer()) {
667 out
<< " " << Pkg
.FullName(true) << " " << I
.OwnerVer().VerStr();
668 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
669 out
<< _(" [Installed]");
674 // if we found no candidate which provide this package, show non-candidates
676 for (I
= Pkg
.ProvidesList(); I
.end() == false; I
++)
677 out
<< " " << I
.OwnerPkg().FullName(true) << " " << I
.OwnerVer().VerStr()
678 << _(" [Not candidate version]") << endl
;
680 out
<< _("You should explicitly select one to install.") << endl
;
683 _("Package %s is not available, but is referred to by another package.\n"
684 "This may mean that the package is missing, has been obsoleted, or\n"
685 "is only available from another source\n"),Pkg
.FullName(true).c_str());
689 SPtrArray
<bool> Seen
= new bool[Cache
.GetPkgCache()->Head().PackageCount
];
690 memset(Seen
,0,Cache
.GetPkgCache()->Head().PackageCount
*sizeof(*Seen
));
691 for (pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
692 Dep
.end() == false; Dep
++) {
693 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
695 if (Seen
[Dep
.ParentPkg()->ID
] == true)
697 Seen
[Dep
.ParentPkg()->ID
] = true;
698 List
+= Dep
.ParentPkg().FullName(true) + " ";
699 //VersionsList += string(Dep.ParentPkg().CurVersion) + "\n"; ???
701 ShowList(out
,_("However the following packages replace it:"),List
,VersionsList
);
708 virtual pkgCache::VerIterator
canNotFindCandidateVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
709 APT::VersionSet
const verset
= tryVirtualPackage(Cache
, Pkg
, APT::VersionSet::CANDIDATE
);
710 if (verset
.empty() == false)
711 return *(verset
.begin());
712 if (ShowError
== true) {
713 _error
->Error(_("Package '%s' has no installation candidate"),Pkg
.FullName(true).c_str());
714 virtualPkgs
.insert(Pkg
);
716 return pkgCache::VerIterator(Cache
, 0);
719 virtual pkgCache::VerIterator
canNotFindNewestVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
720 APT::VersionSet
const verset
= tryVirtualPackage(Cache
, Pkg
, APT::VersionSet::NEWEST
);
721 if (verset
.empty() == false)
722 return *(verset
.begin());
723 if (ShowError
== true)
724 ioprintf(out
, _("Virtual packages like '%s' can't be removed\n"), Pkg
.FullName(true).c_str());
725 return pkgCache::VerIterator(Cache
, 0);
728 APT::VersionSet
tryVirtualPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
,
729 APT::VersionSet::Version
const &select
) {
730 /* This is a pure virtual package and there is a single available
731 candidate providing it. */
732 if (unlikely(Cache
[Pkg
].CandidateVer
!= 0) || Pkg
->ProvidesList
== 0)
733 return APT::VersionSet();
735 pkgCache::PkgIterator Prov
;
736 bool found_one
= false;
737 for (pkgCache::PrvIterator P
= Pkg
.ProvidesList(); P
; ++P
) {
738 pkgCache::VerIterator
const PVer
= P
.OwnerVer();
739 pkgCache::PkgIterator
const PPkg
= PVer
.ParentPkg();
741 /* Ignore versions that are not a candidate. */
742 if (Cache
[PPkg
].CandidateVer
!= PVer
)
745 if (found_one
== false) {
748 } else if (PPkg
!= Prov
) {
749 found_one
= false; // we found at least two
754 if (found_one
== true) {
755 ioprintf(out
, _("Note, selecting '%s' instead of '%s'\n"),
756 Prov
.FullName(true).c_str(), Pkg
.FullName(true).c_str());
757 return APT::VersionSet::FromPackage(Cache
, Prov
, select
, *this);
759 return APT::VersionSet();
762 inline bool allPkgNamedExplicitly() const { return explicitlyNamed
; }
766 // TryToInstall - Mark a package for installation /*{{{*/
767 struct TryToInstall
{
769 pkgProblemResolver
* Fix
;
771 unsigned long AutoMarkChanged
;
772 APT::PackageSet doAutoInstallLater
;
774 TryToInstall(pkgCacheFile
&Cache
, pkgProblemResolver
&PM
, bool const &FixBroken
) : Cache(&Cache
), Fix(&PM
),
775 FixBroken(FixBroken
), AutoMarkChanged(0) {};
777 void operator() (pkgCache::VerIterator
const &Ver
) {
778 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
780 Cache
->GetDepCache()->SetCandidateVersion(Ver
);
781 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
783 // Handle the no-upgrade case
784 if (_config
->FindB("APT::Get::upgrade",true) == false && Pkg
->CurrentVer
!= 0)
785 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
786 Pkg
.FullName(true).c_str());
787 // Ignore request for install if package would be new
788 else if (_config
->FindB("APT::Get::Only-Upgrade", false) == true && Pkg
->CurrentVer
== 0)
789 ioprintf(c1out
,_("Skipping %s, it is not installed and only upgrades are requested.\n"),
790 Pkg
.FullName(true).c_str());
794 Cache
->GetDepCache()->MarkInstall(Pkg
,false);
796 if (State
.Install() == false) {
797 if (_config
->FindB("APT::Get::ReInstall",false) == true) {
798 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
799 ioprintf(c1out
,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
800 Pkg
.FullName(true).c_str());
802 Cache
->GetDepCache()->SetReInstall(Pkg
, true);
804 ioprintf(c1out
,_("%s is already the newest version.\n"),
805 Pkg
.FullName(true).c_str());
808 // Install it with autoinstalling enabled (if we not respect the minial
809 // required deps or the policy)
810 if (FixBroken
== false)
811 doAutoInstallLater
.insert(Pkg
);
814 // see if we need to fix the auto-mark flag
815 // e.g. apt-get install foo
816 // where foo is marked automatic
817 if (State
.Install() == false &&
818 (State
.Flags
& pkgCache::Flag::Auto
) &&
819 _config
->FindB("APT::Get::ReInstall",false) == false &&
820 _config
->FindB("APT::Get::Only-Upgrade",false) == false &&
821 _config
->FindB("APT::Get::Download-Only",false) == false)
823 ioprintf(c1out
,_("%s set to manually installed.\n"),
824 Pkg
.FullName(true).c_str());
825 Cache
->GetDepCache()->MarkAuto(Pkg
,false);
830 void doAutoInstall() {
831 for (APT::PackageSet::const_iterator P
= doAutoInstallLater
.begin();
832 P
!= doAutoInstallLater
.end(); ++P
) {
833 pkgDepCache::StateCache
&State
= (*Cache
)[P
];
834 if (State
.InstBroken() == false && State
.InstPolicyBroken() == false)
836 Cache
->GetDepCache()->MarkInstall(P
, true);
838 doAutoInstallLater
.clear();
842 // TryToRemove - Mark a package for removal /*{{{*/
845 pkgProblemResolver
* Fix
;
848 unsigned long AutoMarkChanged
;
850 TryToRemove(pkgCacheFile
&Cache
, pkgProblemResolver
&PM
) : Cache(&Cache
), Fix(&PM
),
851 PurgePkgs(_config
->FindB("APT::Get::Purge", false)) {};
853 void operator() (pkgCache::VerIterator
const &Ver
)
855 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
861 if ((Pkg
->CurrentVer
== 0 && PurgePkgs
== false) ||
862 (PurgePkgs
== true && Pkg
->CurrentState
== pkgCache::State::NotInstalled
))
863 ioprintf(c1out
,_("Package %s is not installed, so not removed\n"),Pkg
.FullName(true).c_str());
865 Cache
->GetDepCache()->MarkDelete(Pkg
, PurgePkgs
);
869 // CacheFile::NameComp - QSort compare by name /*{{{*/
870 // ---------------------------------------------------------------------
872 pkgCache
*CacheFile::SortCache
= 0;
873 int CacheFile::NameComp(const void *a
,const void *b
)
875 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
876 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
878 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
879 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
881 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
884 // CacheFile::Sort - Sort by name /*{{{*/
885 // ---------------------------------------------------------------------
887 void CacheFile::Sort()
890 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
891 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
892 pkgCache::PkgIterator I
= Cache
->PkgBegin();
893 for (;I
.end() != true; I
++)
897 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
900 // CacheFile::CheckDeps - Open the cache file /*{{{*/
901 // ---------------------------------------------------------------------
902 /* This routine generates the caches and then opens the dependency cache
903 and verifies that the system is OK. */
904 bool CacheFile::CheckDeps(bool AllowBroken
)
906 bool FixBroken
= _config
->FindB("APT::Get::Fix-Broken",false);
908 if (_error
->PendingError() == true)
911 // Check that the system is OK
912 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
913 return _error
->Error("Internal error, non-zero counts");
915 // Apply corrections for half-installed packages
916 if (pkgApplyStatus(*DCache
) == false)
919 if (_config
->FindB("APT::Get::Fix-Policy-Broken",false) == true)
922 if ((DCache
->PolicyBrokenCount() > 0))
924 // upgrade all policy-broken packages with ForceImportantDeps=True
925 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); !I
.end(); I
++)
926 if ((*DCache
)[I
].NowPolicyBroken() == true)
927 DCache
->MarkInstall(I
,true,0, false, true);
932 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
935 // Attempt to fix broken things
936 if (FixBroken
== true)
938 c1out
<< _("Correcting dependencies...") << flush
;
939 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
941 c1out
<< _(" failed.") << endl
;
942 ShowBroken(c1out
,*this,true);
944 return _error
->Error(_("Unable to correct dependencies"));
946 if (pkgMinimizeUpgrade(*DCache
) == false)
947 return _error
->Error(_("Unable to minimize the upgrade set"));
949 c1out
<< _(" Done") << endl
;
953 c1out
<< _("You might want to run 'apt-get -f install' to correct these.") << endl
;
954 ShowBroken(c1out
,*this,true);
956 return _error
->Error(_("Unmet dependencies. Try using -f."));
962 // CheckAuth - check if each download comes form a trusted source /*{{{*/
963 // ---------------------------------------------------------------------
965 static bool CheckAuth(pkgAcquire
& Fetcher
)
967 string UntrustedList
;
968 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd(); ++I
)
970 if (!(*I
)->IsTrusted())
972 UntrustedList
+= string((*I
)->ShortDesc()) + " ";
976 if (UntrustedList
== "")
981 ShowList(c2out
,_("WARNING: The following packages cannot be authenticated!"),UntrustedList
,"");
983 if (_config
->FindB("APT::Get::AllowUnauthenticated",false) == true)
985 c2out
<< _("Authentication warning overridden.\n");
989 if (_config
->FindI("quiet",0) < 2
990 && _config
->FindB("APT::Get::Assume-Yes",false) == false)
992 c2out
<< _("Install these packages without verification [y/N]? ") << flush
;
993 if (!YnPrompt(false))
994 return _error
->Error(_("Some packages could not be authenticated"));
998 else if (_config
->FindB("APT::Get::Force-Yes",false) == true)
1003 return _error
->Error(_("There are problems and -y was used without --force-yes"));
1006 // InstallPackages - Actually download and install the packages /*{{{*/
1007 // ---------------------------------------------------------------------
1008 /* This displays the informative messages describing what is going to
1009 happen and then calls the download routines */
1010 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,
1013 if (_config
->FindB("APT::Get::Purge",false) == true)
1015 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1016 for (; I
.end() == false; I
++)
1018 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
1019 Cache
->MarkDelete(I
,true);
1024 bool Essential
= false;
1026 // Show all the various warning indicators
1027 ShowDel(c1out
,Cache
);
1028 ShowNew(c1out
,Cache
);
1029 if (ShwKept
== true)
1030 ShowKept(c1out
,Cache
);
1031 Fail
|= !ShowHold(c1out
,Cache
);
1032 if (_config
->FindB("APT::Get::Show-Upgraded",true) == true)
1033 ShowUpgraded(c1out
,Cache
);
1034 Fail
|= !ShowDowngraded(c1out
,Cache
);
1035 if (_config
->FindB("APT::Get::Download-Only",false) == false)
1036 Essential
= !ShowEssential(c1out
,Cache
);
1041 if (Cache
->BrokenCount() != 0)
1043 ShowBroken(c1out
,Cache
,false);
1044 return _error
->Error(_("Internal error, InstallPackages was called with broken packages!"));
1047 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
1048 Cache
->BadCount() == 0)
1052 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::Remove",true) == false)
1053 return _error
->Error(_("Packages need to be removed but remove is disabled."));
1055 // Run the simulator ..
1056 if (_config
->FindB("APT::Get::Simulate") == true)
1058 pkgSimulate
PM(Cache
);
1059 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
1060 pkgPackageManager::OrderResult Res
= PM
.DoInstall(status_fd
);
1061 if (Res
== pkgPackageManager::Failed
)
1063 if (Res
!= pkgPackageManager::Completed
)
1064 return _error
->Error(_("Internal error, Ordering didn't finish"));
1068 // Create the text record parser
1069 pkgRecords
Recs(Cache
);
1070 if (_error
->PendingError() == true)
1073 // Create the download object
1075 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1076 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
1078 // force a hashsum for compatibility reasons
1079 _config
->CndSet("Acquire::ForceHash", "md5sum");
1080 if (Fetcher
.Setup(&Stat
, "") == false)
1083 else if (Fetcher
.Setup(&Stat
, _config
->FindDir("Dir::Cache::Archives")) == false)
1086 // Read the source list
1087 if (Cache
.BuildSourceList() == false)
1089 pkgSourceList
*List
= Cache
.GetSourceList();
1091 // Create the package manager and prepare to download
1092 SPtr
<pkgPackageManager
> PM
= _system
->CreatePM(Cache
);
1093 if (PM
->GetArchives(&Fetcher
,List
,&Recs
) == false ||
1094 _error
->PendingError() == true)
1097 // Display statistics
1098 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
1099 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
1100 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
1101 if (DebBytes
!= Cache
->DebSize())
1103 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
1104 c0out
<< _("How odd.. The sizes didn't match, email apt@packages.debian.org") << endl
;
1108 if (DebBytes
!= FetchBytes
)
1109 //TRANSLATOR: The required space between number and unit is already included
1110 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
1111 ioprintf(c1out
,_("Need to get %sB/%sB of archives.\n"),
1112 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
1113 else if (DebBytes
!= 0)
1114 //TRANSLATOR: The required space between number and unit is already included
1115 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
1116 ioprintf(c1out
,_("Need to get %sB of archives.\n"),
1117 SizeToStr(DebBytes
).c_str());
1120 if (Cache
->UsrSize() >= 0)
1121 //TRANSLATOR: The required space between number and unit is already included
1122 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
1123 ioprintf(c1out
,_("After this operation, %sB of additional disk space will be used.\n"),
1124 SizeToStr(Cache
->UsrSize()).c_str());
1126 //TRANSLATOR: The required space between number and unit is already included
1127 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
1128 ioprintf(c1out
,_("After this operation, %sB disk space will be freed.\n"),
1129 SizeToStr(-1*Cache
->UsrSize()).c_str());
1131 if (_error
->PendingError() == true)
1134 /* Check for enough free space, but only if we are actually going to
1136 if (_config
->FindB("APT::Get::Print-URIs") == false &&
1137 _config
->FindB("APT::Get::Download",true) == true)
1140 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
1141 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
1142 if (errno
== EOVERFLOW
)
1143 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
1146 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
1148 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1151 if (statfs(OutputDir
.c_str(),&Stat
) != 0
1152 #if HAVE_STRUCT_STATFS_F_TYPE
1153 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
1156 return _error
->Error(_("You don't have enough free space in %s."),
1162 if (_config
->FindI("quiet",0) >= 2 ||
1163 _config
->FindB("APT::Get::Assume-Yes",false) == true)
1165 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
1166 return _error
->Error(_("There are problems and -y was used without --force-yes"));
1169 if (Essential
== true && Safety
== true)
1171 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
1172 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
1174 const char *Prompt
= _("Yes, do as I say!");
1176 _("You are about to do something potentially harmful.\n"
1177 "To continue type in the phrase '%s'\n"
1180 if (AnalPrompt(Prompt
) == false)
1182 c2out
<< _("Abort.") << endl
;
1188 // Prompt to continue
1189 if (Ask
== true || Fail
== true)
1191 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
1192 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
1194 if (_config
->FindI("quiet",0) < 2 &&
1195 _config
->FindB("APT::Get::Assume-Yes",false) == false)
1197 c2out
<< _("Do you want to continue [Y/n]? ") << flush
;
1199 if (YnPrompt() == false)
1201 c2out
<< _("Abort.") << endl
;
1208 // Just print out the uris an exit if the --print-uris flag was used
1209 if (_config
->FindB("APT::Get::Print-URIs") == true)
1211 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1212 for (; I
!= Fetcher
.UriEnd(); I
++)
1213 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1214 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
1218 if (!CheckAuth(Fetcher
))
1221 /* Unlock the dpkg lock if we are not going to be doing an install
1223 if (_config
->FindB("APT::Get::Download-Only",false) == true)
1229 bool Transient
= false;
1230 if (_config
->FindB("APT::Get::Download",true) == false)
1232 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
1234 if ((*I
)->Local
== true)
1240 // Close the item and check if it was found in cache
1242 if ((*I
)->Complete
== false)
1245 // Clear it out of the fetch list
1247 I
= Fetcher
.ItemsBegin();
1251 if (Fetcher
.Run() == pkgAcquire::Failed
)
1255 bool Failed
= false;
1256 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1258 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1259 (*I
)->Complete
== true)
1262 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
1269 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1270 (*I
)->ErrorText
.c_str());
1274 /* If we are in no download mode and missing files and there were
1275 'failures' then the user must specify -m. Furthermore, there
1276 is no such thing as a transient error in no-download mode! */
1277 if (Transient
== true &&
1278 _config
->FindB("APT::Get::Download",true) == false)
1284 if (_config
->FindB("APT::Get::Download-Only",false) == true)
1286 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
1287 return _error
->Error(_("Some files failed to download"));
1288 c1out
<< _("Download complete and in download only mode") << endl
;
1292 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
1294 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
1297 if (Transient
== true && Failed
== true)
1298 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
1300 // Try to deal with missing package files
1301 if (Failed
== true && PM
->FixMissing() == false)
1303 cerr
<< _("Unable to correct missing packages.") << endl
;
1304 return _error
->Error(_("Aborting install."));
1308 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
1309 pkgPackageManager::OrderResult Res
= PM
->DoInstall(status_fd
);
1310 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
1312 if (Res
== pkgPackageManager::Completed
)
1315 // Reload the fetcher object and loop again for media swapping
1317 if (PM
->GetArchives(&Fetcher
,List
,&Recs
) == false)
1323 std::set
<std::string
> const disappearedPkgs
= PM
->GetDisappearedPackages();
1324 if (disappearedPkgs
.empty() == true)
1328 for (std::set
<std::string
>::const_iterator d
= disappearedPkgs
.begin();
1329 d
!= disappearedPkgs
.end(); ++d
)
1330 disappear
.append(*d
).append(" ");
1332 ShowList(c1out
, P_("The following package disappeared from your system as\n"
1333 "all files have been overwritten by other packages:",
1334 "The following packages disappeared from your system as\n"
1335 "all files have been overwritten by other packages:", disappearedPkgs
.size()), disappear
, "");
1336 c0out
<< _("Note: This is done automatic and on purpose by dpkg.") << std::endl
;
1341 // TryToInstallBuildDep - Try to install a single package /*{{{*/
1342 // ---------------------------------------------------------------------
1343 /* This used to be inlined in DoInstall, but with the advent of regex package
1344 name matching it was split out.. */
1345 bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg
,pkgCacheFile
&Cache
,
1346 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
1347 bool AllowFail
= true)
1349 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0)
1351 CacheSetHelperAPTGet
helper(c1out
);
1352 helper
.showErrors(AllowFail
== false);
1353 pkgCache::VerIterator Ver
= helper
.canNotFindNewestVer(Cache
, Pkg
);
1354 if (Ver
.end() == false)
1355 Pkg
= Ver
.ParentPkg();
1356 else if (helper
.showVirtualPackageErrors(Cache
) == false)
1362 TryToRemove
RemoveAction(Cache
, Fix
);
1363 RemoveAction(Pkg
.VersionList());
1364 } else if (Cache
[Pkg
].CandidateVer
!= 0) {
1365 TryToInstall
InstallAction(Cache
, Fix
, BrokenFix
);
1366 InstallAction(Cache
[Pkg
].CandidateVerIter(Cache
));
1367 InstallAction
.doAutoInstall();
1374 // FindSrc - Find a source record /*{{{*/
1375 // ---------------------------------------------------------------------
1377 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
1378 pkgSrcRecords
&SrcRecs
,string
&Src
,
1382 string DefRel
= _config
->Find("APT::Default-Release");
1383 string TmpSrc
= Name
;
1385 // extract the version/release from the pkgname
1386 const size_t found
= TmpSrc
.find_last_of("/=");
1387 if (found
!= string::npos
) {
1388 if (TmpSrc
[found
] == '/')
1389 DefRel
= TmpSrc
.substr(found
+1);
1391 VerTag
= TmpSrc
.substr(found
+1);
1392 TmpSrc
= TmpSrc
.substr(0,found
);
1395 /* Lookup the version of the package we would install if we were to
1396 install a version and determine the source package name, then look
1397 in the archive for a source package of the same name. */
1398 bool MatchSrcOnly
= _config
->FindB("APT::Get::Only-Source");
1399 const pkgCache::PkgIterator Pkg
= Cache
.FindPkg(TmpSrc
);
1400 if (MatchSrcOnly
== false && Pkg
.end() == false)
1402 if(VerTag
.empty() == false || DefRel
.empty() == false)
1405 // we have a default release, try to locate the pkg. we do it like
1406 // this because GetCandidateVer() will not "downgrade", that means
1407 // "apt-get source -t stable apt" won't work on a unstable system
1408 for (pkgCache::VerIterator Ver
= Pkg
.VersionList();; Ver
++)
1410 // try first only exact matches, later fuzzy matches
1411 if (Ver
.end() == true)
1416 Ver
= Pkg
.VersionList();
1417 // exit right away from the Pkg.VersionList() loop if we
1418 // don't have any versions
1419 if (Ver
.end() == true)
1422 // We match against a concrete version (or a part of this version)
1423 if (VerTag
.empty() == false &&
1424 (fuzzy
== true || Cache
.VS().CmpVersion(VerTag
, Ver
.VerStr()) != 0) && // exact match
1425 (fuzzy
== false || strncmp(VerTag
.c_str(), Ver
.VerStr(), VerTag
.size()) != 0)) // fuzzy match
1428 for (pkgCache::VerFileIterator VF
= Ver
.FileList();
1429 VF
.end() == false; VF
++)
1431 /* If this is the status file, and the current version is not the
1432 version in the status file (ie it is not installed, or somesuch)
1433 then it is not a candidate for installation, ever. This weeds
1434 out bogus entries that may be due to config-file states, or
1436 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) ==
1437 pkgCache::Flag::NotSource
&& Pkg
.CurrentVer() != Ver
)
1440 // or we match against a release
1441 if(VerTag
.empty() == false ||
1442 (VF
.File().Archive() != 0 && VF
.File().Archive() == DefRel
) ||
1443 (VF
.File().Codename() != 0 && VF
.File().Codename() == DefRel
))
1445 pkgRecords::Parser
&Parse
= Recs
.Lookup(VF
);
1446 Src
= Parse
.SourcePkg();
1447 // no SourcePkg name, so it is the "binary" name
1448 if (Src
.empty() == true)
1450 // the Version we have is possibly fuzzy or includes binUploads,
1451 // so we use the Version of the SourcePkg (empty if same as package)
1452 VerTag
= Parse
.SourceVer();
1453 if (VerTag
.empty() == true)
1454 VerTag
= Ver
.VerStr();
1458 if (Src
.empty() == false)
1461 if (Src
.empty() == true)
1463 // Sources files have no codename information
1464 if (VerTag
.empty() == true && DefRel
.empty() == false)
1466 _error
->Error(_("Ignore unavailable target release '%s' of package '%s'"), DefRel
.c_str(), TmpSrc
.c_str());
1471 if (Src
.empty() == true)
1473 // if we don't have found a fitting package yet so we will
1474 // choose a good candidate and proceed with that.
1475 // Maybe we will find a source later on with the right VerTag
1476 pkgCache::VerIterator Ver
= Cache
.GetCandidateVer(Pkg
);
1477 if (Ver
.end() == false)
1479 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1480 Src
= Parse
.SourcePkg();
1481 if (VerTag
.empty() == true)
1482 VerTag
= Parse
.SourceVer();
1487 if (Src
.empty() == true)
1491 /* if we have a source pkg name, make sure to only search
1492 for srcpkg names, otherwise apt gets confused if there
1493 is a binary package "pkg1" and a source package "pkg1"
1494 with the same name but that comes from different packages */
1495 MatchSrcOnly
= true;
1498 ioprintf(c1out
, _("Picking '%s' as source package instead of '%s'\n"), Src
.c_str(), TmpSrc
.c_str());
1503 pkgSrcRecords::Parser
*Last
= 0;
1504 unsigned long Offset
= 0;
1507 /* Iterate over all of the hits, which includes the resulting
1508 binary packages in the search */
1509 pkgSrcRecords::Parser
*Parse
;
1513 while ((Parse
= SrcRecs
.Find(Src
.c_str(), MatchSrcOnly
)) != 0)
1515 const string Ver
= Parse
->Version();
1517 // Ignore all versions which doesn't fit
1518 if (VerTag
.empty() == false &&
1519 Cache
.VS().CmpVersion(VerTag
, Ver
) != 0) // exact match
1522 // Newer version or an exact match? Save the hit
1523 if (Last
== 0 || Cache
.VS().CmpVersion(Version
,Ver
) < 0) {
1525 Offset
= Parse
->Offset();
1529 // was the version check above an exact match? If so, we don't need to look further
1530 if (VerTag
.empty() == false && VerTag
.size() == Ver
.size())
1533 if (Last
!= 0 || VerTag
.empty() == true)
1535 //if (VerTag.empty() == false && Last == 0)
1536 _error
->Error(_("Ignore unavailable version '%s' of package '%s'"), VerTag
.c_str(), TmpSrc
.c_str());
1540 if (Last
== 0 || Last
->Jump(Offset
) == false)
1546 // DoUpdate - Update the package lists /*{{{*/
1547 // ---------------------------------------------------------------------
1549 bool DoUpdate(CommandLine
&CmdL
)
1551 if (CmdL
.FileSize() != 1)
1552 return _error
->Error(_("The update command takes no arguments"));
1556 // Get the source list
1557 if (Cache
.BuildSourceList() == false)
1559 pkgSourceList
*List
= Cache
.GetSourceList();
1561 // Create the progress
1562 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1564 // Just print out the uris an exit if the --print-uris flag was used
1565 if (_config
->FindB("APT::Get::Print-URIs") == true)
1567 // force a hashsum for compatibility reasons
1568 _config
->CndSet("Acquire::ForceHash", "md5sum");
1572 if (Fetcher
.Setup(&Stat
) == false)
1575 // Populate it with the source selection and get all Indexes
1577 if (List
->GetIndexes(&Fetcher
,true) == false)
1580 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1581 for (; I
!= Fetcher
.UriEnd(); I
++)
1582 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1583 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
1588 if (_config
->FindB("APT::Get::Download",true) == true)
1589 ListUpdate(Stat
, *List
);
1591 // Rebuild the cache.
1592 if (Cache
.BuildCaches() == false)
1598 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
1599 // ---------------------------------------------------------------------
1600 /* Remove unused automatic packages */
1601 bool DoAutomaticRemove(CacheFile
&Cache
)
1603 bool Debug
= _config
->FindI("Debug::pkgAutoRemove",false);
1604 bool doAutoRemove
= _config
->FindB("APT::Get::AutomaticRemove", false);
1605 bool hideAutoRemove
= _config
->FindB("APT::Get::HideAutoRemove");
1607 pkgDepCache::ActionGroup
group(*Cache
);
1609 std::cout
<< "DoAutomaticRemove()" << std::endl
;
1611 // we don't want to autoremove and we don't want to see it, so why calculating?
1612 if (doAutoRemove
== false && hideAutoRemove
== true)
1615 if (doAutoRemove
== true &&
1616 _config
->FindB("APT::Get::Remove",true) == false)
1618 c1out
<< _("We are not supposed to delete stuff, can't start "
1619 "AutoRemover") << std::endl
;
1623 bool purgePkgs
= _config
->FindB("APT::Get::Purge", false);
1624 bool smallList
= (hideAutoRemove
== false &&
1625 strcasecmp(_config
->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
1627 string autoremovelist
, autoremoveversions
;
1628 unsigned long autoRemoveCount
= 0;
1629 // look over the cache to see what can be removed
1630 for (pkgCache::PkgIterator Pkg
= Cache
->PkgBegin(); ! Pkg
.end(); ++Pkg
)
1632 if (Cache
[Pkg
].Garbage
)
1634 if(Pkg
.CurrentVer() != 0 || Cache
[Pkg
].Install())
1636 std::cout
<< "We could delete %s" << Pkg
.FullName(true).c_str() << std::endl
;
1640 if(Pkg
.CurrentVer() != 0 &&
1641 Pkg
->CurrentState
!= pkgCache::State::ConfigFiles
)
1642 Cache
->MarkDelete(Pkg
, purgePkgs
);
1644 Cache
->MarkKeep(Pkg
, false, false);
1648 // only show stuff in the list that is not yet marked for removal
1649 if(Cache
[Pkg
].Delete() == false)
1652 // we don't need to fill the strings if we don't need them
1653 if (smallList
== false)
1655 autoremovelist
+= Pkg
.FullName(true) + " ";
1656 autoremoveversions
+= string(Cache
[Pkg
].CandVersion
) + "\n";
1662 // if we don't remove them, we should show them!
1663 if (doAutoRemove
== false && (autoremovelist
.empty() == false || autoRemoveCount
!= 0))
1665 if (smallList
== false)
1666 ShowList(c1out
, P_("The following package was automatically installed and is no longer required:",
1667 "The following packages were automatically installed and are no longer required:",
1668 autoRemoveCount
), autoremovelist
, autoremoveversions
);
1670 ioprintf(c1out
, P_("%lu package was automatically installed and is no longer required.\n",
1671 "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount
), autoRemoveCount
);
1672 c1out
<< _("Use 'apt-get autoremove' to remove them.") << std::endl
;
1674 // Now see if we had destroyed anything (if we had done anything)
1675 else if (Cache
->BrokenCount() != 0)
1677 c1out
<< _("Hmm, seems like the AutoRemover destroyed something which really\n"
1678 "shouldn't happen. Please file a bug report against apt.") << endl
;
1680 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1682 ShowBroken(c1out
,Cache
,false);
1684 return _error
->Error(_("Internal Error, AutoRemover broke stuff"));
1689 // DoUpgrade - Upgrade all packages /*{{{*/
1690 // ---------------------------------------------------------------------
1691 /* Upgrade all packages without installing new packages or erasing old
1693 bool DoUpgrade(CommandLine
&CmdL
)
1696 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1700 if (pkgAllUpgrade(Cache
) == false)
1702 ShowBroken(c1out
,Cache
,false);
1703 return _error
->Error(_("Internal error, AllUpgrade broke stuff"));
1706 return InstallPackages(Cache
,true);
1709 // DoInstall - Install packages from the command line /*{{{*/
1710 // ---------------------------------------------------------------------
1711 /* Install named packages */
1712 bool DoInstall(CommandLine
&CmdL
)
1715 if (Cache
.OpenForInstall() == false ||
1716 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
1719 // Enter the special broken fixing mode if the user specified arguments
1720 bool BrokenFix
= false;
1721 if (Cache
->BrokenCount() != 0)
1724 pkgProblemResolver
Fix(Cache
);
1726 static const unsigned short MOD_REMOVE
= 1;
1727 static const unsigned short MOD_INSTALL
= 2;
1729 unsigned short fallback
= MOD_INSTALL
;
1730 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
1731 fallback
= MOD_REMOVE
;
1732 else if (strcasecmp(CmdL
.FileList
[0], "purge") == 0)
1734 _config
->Set("APT::Get::Purge", true);
1735 fallback
= MOD_REMOVE
;
1737 else if (strcasecmp(CmdL
.FileList
[0], "autoremove") == 0)
1739 _config
->Set("APT::Get::AutomaticRemove", "true");
1740 fallback
= MOD_REMOVE
;
1743 std::list
<APT::VersionSet::Modifier
> mods
;
1744 mods
.push_back(APT::VersionSet::Modifier(MOD_INSTALL
, "+",
1745 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::CANDIDATE
));
1746 mods
.push_back(APT::VersionSet::Modifier(MOD_REMOVE
, "-",
1747 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::NEWEST
));
1748 CacheSetHelperAPTGet
helper(c0out
);
1749 std::map
<unsigned short, APT::VersionSet
> verset
= APT::VersionSet::GroupedFromCommandLine(Cache
,
1750 CmdL
.FileList
+ 1, mods
, fallback
, helper
);
1752 if (_error
->PendingError() == true)
1754 helper
.showVirtualPackageErrors(Cache
);
1758 unsigned short order
[] = { 0, 0, 0 };
1759 if (fallback
== MOD_INSTALL
) {
1760 order
[0] = MOD_INSTALL
;
1761 order
[1] = MOD_REMOVE
;
1763 order
[0] = MOD_REMOVE
;
1764 order
[1] = MOD_INSTALL
;
1767 TryToInstall
InstallAction(Cache
, Fix
, BrokenFix
);
1768 TryToRemove
RemoveAction(Cache
, Fix
);
1770 // new scope for the ActionGroup
1772 pkgDepCache::ActionGroup
group(Cache
);
1774 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
1776 if (order
[i
] == MOD_INSTALL
) {
1777 InstallAction
= std::for_each(verset
[MOD_INSTALL
].begin(), verset
[MOD_INSTALL
].end(), InstallAction
);
1778 InstallAction
.doAutoInstall();
1780 else if (order
[i
] == MOD_REMOVE
)
1781 RemoveAction
= std::for_each(verset
[MOD_REMOVE
].begin(), verset
[MOD_REMOVE
].end(), RemoveAction
);
1784 if (_error
->PendingError() == true)
1787 /* If we are in the Broken fixing mode we do not attempt to fix the
1788 problems. This is if the user invoked install without -f and gave
1790 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1792 c1out
<< _("You might want to run 'apt-get -f install' to correct these:") << endl
;
1793 ShowBroken(c1out
,Cache
,false);
1795 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1798 // Call the scored problem resolver
1799 Fix
.InstallProtect();
1800 if (Fix
.Resolve(true) == false)
1803 // Now we check the state of the packages,
1804 if (Cache
->BrokenCount() != 0)
1807 _("Some packages could not be installed. This may mean that you have\n"
1808 "requested an impossible situation or if you are using the unstable\n"
1809 "distribution that some required packages have not yet been created\n"
1810 "or been moved out of Incoming.") << endl
;
1816 _("Since you only requested a single operation it is extremely likely that\n"
1817 "the package is simply not installable and a bug report against\n"
1818 "that package should be filed.") << endl;
1822 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1824 ShowBroken(c1out
,Cache
,false);
1825 return _error
->Error(_("Broken packages"));
1828 if (!DoAutomaticRemove(Cache
))
1831 /* Print out a list of packages that are going to be installed extra
1832 to what the user asked */
1833 if (Cache
->InstCount() != verset
[MOD_INSTALL
].size())
1836 string VersionsList
;
1837 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1839 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1840 if ((*Cache
)[I
].Install() == false)
1844 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1845 if (strcmp(*J
,I
.Name()) == 0)
1849 List
+= I
.FullName(true) + " ";
1850 VersionsList
+= string(Cache
[I
].CandVersion
) + "\n";
1854 ShowList(c1out
,_("The following extra packages will be installed:"),List
,VersionsList
);
1857 /* Print out a list of suggested and recommended packages */
1859 string SuggestsList
, RecommendsList
, List
;
1860 string SuggestsVersions
, RecommendsVersions
;
1861 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1863 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
1865 /* Just look at the ones we want to install */
1866 if ((*Cache
)[Pkg
].Install() == false)
1869 // get the recommends/suggests for the candidate ver
1870 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1871 for (pkgCache::DepIterator D
= CV
.DependsList(); D
.end() == false; )
1873 pkgCache::DepIterator Start
;
1874 pkgCache::DepIterator End
;
1875 D
.GlobOr(Start
,End
); // advances D
1877 // FIXME: we really should display a or-group as a or-group to the user
1878 // the problem is that ShowList is incapable of doing this
1879 string RecommendsOrList
,RecommendsOrVersions
;
1880 string SuggestsOrList
,SuggestsOrVersions
;
1881 bool foundInstalledInOrGroup
= false;
1884 /* Skip if package is installed already, or is about to be */
1885 string target
= Start
.TargetPkg().FullName(true) + " ";
1886 pkgCache::PkgIterator
const TarPkg
= Start
.TargetPkg();
1887 if (TarPkg
->SelectedState
== pkgCache::State::Install
||
1888 TarPkg
->SelectedState
== pkgCache::State::Hold
||
1889 Cache
[Start
.TargetPkg()].Install())
1891 foundInstalledInOrGroup
=true;
1895 /* Skip if we already saw it */
1896 if (int(SuggestsList
.find(target
)) != -1 || int(RecommendsList
.find(target
)) != -1)
1898 foundInstalledInOrGroup
=true;
1902 // this is a dep on a virtual pkg, check if any package that provides it
1903 // should be installed
1904 if(Start
.TargetPkg().ProvidesList() != 0)
1906 pkgCache::PrvIterator I
= Start
.TargetPkg().ProvidesList();
1907 for (; I
.end() == false; I
++)
1909 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
1910 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer() &&
1911 Pkg
.CurrentVer() != 0)
1912 foundInstalledInOrGroup
=true;
1916 if (Start
->Type
== pkgCache::Dep::Suggests
)
1918 SuggestsOrList
+= target
;
1919 SuggestsOrVersions
+= string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
1922 if (Start
->Type
== pkgCache::Dep::Recommends
)
1924 RecommendsOrList
+= target
;
1925 RecommendsOrVersions
+= string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
1933 if(foundInstalledInOrGroup
== false)
1935 RecommendsList
+= RecommendsOrList
;
1936 RecommendsVersions
+= RecommendsOrVersions
;
1937 SuggestsList
+= SuggestsOrList
;
1938 SuggestsVersions
+= SuggestsOrVersions
;
1944 ShowList(c1out
,_("Suggested packages:"),SuggestsList
,SuggestsVersions
);
1945 ShowList(c1out
,_("Recommended packages:"),RecommendsList
,RecommendsVersions
);
1949 // if nothing changed in the cache, but only the automark information
1950 // we write the StateFile here, otherwise it will be written in
1952 if (InstallAction
.AutoMarkChanged
> 0 &&
1953 Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
1954 Cache
->BadCount() == 0 &&
1955 _config
->FindB("APT::Get::Simulate",false) == false)
1956 Cache
->writeStateFile(NULL
);
1958 // See if we need to prompt
1959 // FIXME: check if really the packages in the set are going to be installed
1960 if (Cache
->InstCount() == verset
[MOD_INSTALL
].size() && Cache
->DelCount() == 0)
1961 return InstallPackages(Cache
,false,false);
1963 return InstallPackages(Cache
,false);
1966 /* mark packages as automatically/manually installed. */
1967 bool DoMarkAuto(CommandLine
&CmdL
)
1970 int AutoMarkChanged
= 0;
1971 OpTextProgress progress
;
1973 if (Cache
.Open() == false)
1976 if (strcasecmp(CmdL
.FileList
[0],"markauto") == 0)
1978 else if (strcasecmp(CmdL
.FileList
[0],"unmarkauto") == 0)
1981 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1984 // Locate the package
1985 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
1986 if (Pkg
.end() == true) {
1987 return _error
->Error(_("Couldn't find package %s"),S
);
1992 ioprintf(c1out
,_("%s set to manually installed.\n"), Pkg
.Name());
1994 ioprintf(c1out
,_("%s set to automatically installed.\n"),
1997 Cache
->MarkAuto(Pkg
,Action
);
2001 if (AutoMarkChanged
&& ! _config
->FindB("APT::Get::Simulate",false))
2002 return Cache
->writeStateFile(NULL
);
2006 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
2007 // ---------------------------------------------------------------------
2008 /* Intelligent upgrader that will install and remove packages at will */
2009 bool DoDistUpgrade(CommandLine
&CmdL
)
2012 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
2015 c0out
<< _("Calculating upgrade... ") << flush
;
2016 if (pkgDistUpgrade(*Cache
) == false)
2018 c0out
<< _("Failed") << endl
;
2019 ShowBroken(c1out
,Cache
,false);
2023 c0out
<< _("Done") << endl
;
2025 return InstallPackages(Cache
,true);
2028 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
2029 // ---------------------------------------------------------------------
2030 /* Follows dselect's selections */
2031 bool DoDSelectUpgrade(CommandLine
&CmdL
)
2034 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
2037 pkgDepCache::ActionGroup
group(Cache
);
2039 // Install everything with the install flag set
2040 pkgCache::PkgIterator I
= Cache
->PkgBegin();
2041 for (;I
.end() != true; I
++)
2043 /* Install the package only if it is a new install, the autoupgrader
2044 will deal with the rest */
2045 if (I
->SelectedState
== pkgCache::State::Install
)
2046 Cache
->MarkInstall(I
,false);
2049 /* Now install their deps too, if we do this above then order of
2050 the status file is significant for | groups */
2051 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
2053 /* Install the package only if it is a new install, the autoupgrader
2054 will deal with the rest */
2055 if (I
->SelectedState
== pkgCache::State::Install
)
2056 Cache
->MarkInstall(I
,true);
2059 // Apply erasures now, they override everything else.
2060 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
2063 if (I
->SelectedState
== pkgCache::State::DeInstall
||
2064 I
->SelectedState
== pkgCache::State::Purge
)
2065 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
2068 /* Resolve any problems that dselect created, allupgrade cannot handle
2069 such things. We do so quite agressively too.. */
2070 if (Cache
->BrokenCount() != 0)
2072 pkgProblemResolver
Fix(Cache
);
2074 // Hold back held packages.
2075 if (_config
->FindB("APT::Ignore-Hold",false) == false)
2077 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
2079 if (I
->SelectedState
== pkgCache::State::Hold
)
2087 if (Fix
.Resolve() == false)
2089 ShowBroken(c1out
,Cache
,false);
2090 return _error
->Error(_("Internal error, problem resolver broke stuff"));
2094 // Now upgrade everything
2095 if (pkgAllUpgrade(Cache
) == false)
2097 ShowBroken(c1out
,Cache
,false);
2098 return _error
->Error(_("Internal error, problem resolver broke stuff"));
2101 return InstallPackages(Cache
,false);
2104 // DoClean - Remove download archives /*{{{*/
2105 // ---------------------------------------------------------------------
2107 bool DoClean(CommandLine
&CmdL
)
2109 if (_config
->FindB("APT::Get::Simulate") == true)
2111 cout
<< "Del " << _config
->FindDir("Dir::Cache::archives") << "* " <<
2112 _config
->FindDir("Dir::Cache::archives") << "partial/*" << endl
;
2116 // Lock the archive directory
2118 if (_config
->FindB("Debug::NoLocking",false) == false)
2120 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
2121 if (_error
->PendingError() == true)
2122 return _error
->Error(_("Unable to lock the download directory"));
2126 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
2127 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
2131 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
2132 // ---------------------------------------------------------------------
2133 /* This is similar to clean but it only purges things that cannot be
2134 downloaded, that is old versions of cached packages. */
2135 class LogCleaner
: public pkgArchiveCleaner
2138 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
2140 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
2142 if (_config
->FindB("APT::Get::Simulate") == false)
2147 bool DoAutoClean(CommandLine
&CmdL
)
2149 // Lock the archive directory
2151 if (_config
->FindB("Debug::NoLocking",false) == false)
2153 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
2154 if (_error
->PendingError() == true)
2155 return _error
->Error(_("Unable to lock the download directory"));
2159 if (Cache
.Open() == false)
2164 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
2165 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
2168 // DoCheck - Perform the check operation /*{{{*/
2169 // ---------------------------------------------------------------------
2170 /* Opening automatically checks the system, this command is mostly used
2172 bool DoCheck(CommandLine
&CmdL
)
2181 // DoSource - Fetch a source archive /*{{{*/
2182 // ---------------------------------------------------------------------
2183 /* Fetch souce packages */
2191 bool DoSource(CommandLine
&CmdL
)
2194 if (Cache
.Open(false) == false)
2197 if (CmdL
.FileSize() <= 1)
2198 return _error
->Error(_("Must specify at least one package to fetch source for"));
2200 // Read the source list
2201 if (Cache
.BuildSourceList() == false)
2203 pkgSourceList
*List
= Cache
.GetSourceList();
2205 // Create the text record parsers
2206 pkgRecords
Recs(Cache
);
2207 pkgSrcRecords
SrcRecs(*List
);
2208 if (_error
->PendingError() == true)
2211 // Create the download object
2212 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
2214 if (Fetcher
.Setup(&Stat
) == false)
2217 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
2219 // insert all downloaded uris into this set to avoid downloading them
2223 // Diff only mode only fetches .diff files
2224 bool const diffOnly
= _config
->FindB("APT::Get::Diff-Only", false);
2225 // Tar only mode only fetches .tar files
2226 bool const tarOnly
= _config
->FindB("APT::Get::Tar-Only", false);
2227 // Dsc only mode only fetches .dsc files
2228 bool const dscOnly
= _config
->FindB("APT::Get::Dsc-Only", false);
2230 // Load the requestd sources into the fetcher
2232 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
2235 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
2238 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
2240 string srec
= Last
->AsStr();
2241 string::size_type pos
= srec
.find("\nVcs-");
2242 while (pos
!= string::npos
)
2244 pos
+= strlen("\nVcs-");
2245 string vcs
= srec
.substr(pos
,srec
.find(":",pos
)-pos
);
2246 if(vcs
== "Browser")
2248 pos
= srec
.find("\nVcs-", pos
);
2251 pos
+= vcs
.length()+2;
2252 string::size_type epos
= srec
.find("\n", pos
);
2253 string uri
= srec
.substr(pos
,epos
-pos
).c_str();
2254 ioprintf(c1out
, _("NOTICE: '%s' packaging is maintained in "
2255 "the '%s' version control system at:\n"
2257 Src
.c_str(), vcs
.c_str(), uri
.c_str());
2259 ioprintf(c1out
,_("Please use:\n"
2261 "to retrieve the latest (possibly unreleased) "
2262 "updates to the package.\n"),
2268 vector
<pkgSrcRecords::File
> Lst
;
2269 if (Last
->Files(Lst
) == false)
2272 // Load them into the fetcher
2273 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
2274 I
!= Lst
.end(); I
++)
2276 // Try to guess what sort of file it is we are getting.
2277 if (I
->Type
== "dsc")
2279 Dsc
[J
].Package
= Last
->Package();
2280 Dsc
[J
].Version
= Last
->Version();
2281 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
2284 // Handle the only options so that multiple can be used at once
2285 if (diffOnly
== true || tarOnly
== true || dscOnly
== true)
2287 if ((diffOnly
== true && I
->Type
== "diff") ||
2288 (tarOnly
== true && I
->Type
== "tar") ||
2289 (dscOnly
== true && I
->Type
== "dsc"))
2290 ; // Fine, we want this file downloaded
2295 // don't download the same uri twice (should this be moved to
2296 // the fetcher interface itself?)
2297 if(queued
.find(Last
->Index().ArchiveURI(I
->Path
)) != queued
.end())
2299 queued
.insert(Last
->Index().ArchiveURI(I
->Path
));
2301 // check if we have a file with that md5 sum already localy
2302 if(!I
->MD5Hash
.empty() && FileExists(flNotDir(I
->Path
)))
2304 FileFd
Fd(flNotDir(I
->Path
), FileFd::ReadOnly
);
2306 sum
.AddFD(Fd
.Fd(), Fd
.Size());
2308 if((string
)sum
.Result() == I
->MD5Hash
)
2310 ioprintf(c1out
,_("Skipping already downloaded file '%s'\n"),
2311 flNotDir(I
->Path
).c_str());
2316 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
2318 Last
->Index().SourceInfo(*Last
,*I
),Src
);
2322 // Display statistics
2323 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
2324 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
2325 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
2327 // Check for enough free space
2329 string OutputDir
= ".";
2330 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
2331 if (errno
== EOVERFLOW
)
2332 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
2335 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
2337 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
2340 if (statfs(OutputDir
.c_str(),&Stat
) != 0
2341 #if HAVE_STRUCT_STATFS_F_TYPE
2342 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
2345 return _error
->Error(_("You don't have enough free space in %s"),
2350 if (DebBytes
!= FetchBytes
)
2351 //TRANSLATOR: The required space between number and unit is already included
2352 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
2353 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
2354 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
2356 //TRANSLATOR: The required space between number and unit is already included
2357 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
2358 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
2359 SizeToStr(DebBytes
).c_str());
2361 if (_config
->FindB("APT::Get::Simulate",false) == true)
2363 for (unsigned I
= 0; I
!= J
; I
++)
2364 ioprintf(cout
,_("Fetch source %s\n"),Dsc
[I
].Package
.c_str());
2369 // Just print out the uris an exit if the --print-uris flag was used
2370 if (_config
->FindB("APT::Get::Print-URIs") == true)
2372 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
2373 for (; I
!= Fetcher
.UriEnd(); I
++)
2374 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
2375 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
2381 if (Fetcher
.Run() == pkgAcquire::Failed
)
2384 // Print error messages
2385 bool Failed
= false;
2386 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
2388 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
2389 (*I
)->Complete
== true)
2392 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
2393 (*I
)->ErrorText
.c_str());
2397 return _error
->Error(_("Failed to fetch some archives."));
2399 if (_config
->FindB("APT::Get::Download-only",false) == true)
2401 c1out
<< _("Download complete and in download only mode") << endl
;
2406 // Unpack the sources
2407 pid_t Process
= ExecFork();
2411 bool const fixBroken
= _config
->FindB("APT::Get::Fix-Broken", false);
2412 for (unsigned I
= 0; I
!= J
; I
++)
2414 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
2416 // Diff only mode only fetches .diff files
2417 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
2418 _config
->FindB("APT::Get::Tar-Only",false) == true ||
2419 Dsc
[I
].Dsc
.empty() == true)
2422 // See if the package is already unpacked
2424 if (fixBroken
== false && stat(Dir
.c_str(),&Stat
) == 0 &&
2425 S_ISDIR(Stat
.st_mode
) != 0)
2427 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
2434 snprintf(S
,sizeof(S
),"%s -x %s",
2435 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
2436 Dsc
[I
].Dsc
.c_str());
2439 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
2440 fprintf(stderr
,_("Check if the 'dpkg-dev' package is installed.\n"));
2445 // Try to compile it with dpkg-buildpackage
2446 if (_config
->FindB("APT::Get::Compile",false) == true)
2448 // Call dpkg-buildpackage
2450 snprintf(S
,sizeof(S
),"cd %s && %s %s",
2452 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
2453 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
2457 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
2467 // Wait for the subprocess
2469 while (waitpid(Process
,&Status
,0) != Process
)
2473 return _error
->Errno("waitpid","Couldn't wait for subprocess");
2476 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
2477 return _error
->Error(_("Child process failed"));
2482 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
2483 // ---------------------------------------------------------------------
2484 /* This function will look at the build depends list of the given source
2485 package and install the necessary packages to make it true, or fail. */
2486 bool DoBuildDep(CommandLine
&CmdL
)
2489 if (Cache
.Open(true) == false)
2492 if (CmdL
.FileSize() <= 1)
2493 return _error
->Error(_("Must specify at least one package to check builddeps for"));
2495 // Read the source list
2496 if (Cache
.BuildSourceList() == false)
2498 pkgSourceList
*List
= Cache
.GetSourceList();
2500 // Create the text record parsers
2501 pkgRecords
Recs(Cache
);
2502 pkgSrcRecords
SrcRecs(*List
);
2503 if (_error
->PendingError() == true)
2506 // Create the download object
2507 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
2509 if (Fetcher
.Setup(&Stat
) == false)
2513 bool const StripMultiArch
= APT::Configuration::getArchitectures().size() <= 1;
2514 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
2517 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
2519 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
2521 // Process the build-dependencies
2522 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
2523 if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only", false), StripMultiArch
) == false)
2524 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
2526 // Also ensure that build-essential packages are present
2527 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
2530 for (; Opts
; Opts
= Opts
->Next
)
2532 if (Opts
->Value
.empty() == true)
2535 pkgSrcRecords::Parser::BuildDepRec rec
;
2536 rec
.Package
= Opts
->Value
;
2537 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
2539 BuildDeps
.push_back(rec
);
2542 if (BuildDeps
.size() == 0)
2544 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
2548 // Install the requested packages
2549 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
2550 pkgProblemResolver
Fix(Cache
);
2551 bool skipAlternatives
= false; // skip remaining alternatives in an or group
2552 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); D
++)
2554 bool hasAlternatives
= (((*D
).Op
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
);
2556 if (skipAlternatives
== true)
2558 if (!hasAlternatives
)
2559 skipAlternatives
= false; // end of or group
2563 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
2564 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
2566 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
2567 // Build-conflicts on unknown packages are silently ignored
2568 if (Pkg
.end() == true)
2571 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
2574 * Remove if we have an installed version that satisfies the
2577 if (IV
.end() == false &&
2578 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2579 TryToInstallBuildDep(Pkg
,Cache
,Fix
,true,false);
2581 else // BuildDep || BuildDepIndep
2583 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
2584 if (_config
->FindB("Debug::BuildDeps",false) == true)
2585 cout
<< "Looking for " << (*D
).Package
<< "...\n";
2587 if (Pkg
.end() == true)
2589 if (_config
->FindB("Debug::BuildDeps",false) == true)
2590 cout
<< " (not found)" << (*D
).Package
<< endl
;
2592 if (hasAlternatives
)
2595 return _error
->Error(_("%s dependency for %s cannot be satisfied "
2596 "because the package %s cannot be found"),
2597 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
2598 (*D
).Package
.c_str());
2602 * if there are alternatives, we've already picked one, so skip
2605 * TODO: this means that if there's a build-dep on A|B and B is
2606 * installed, we'll still try to install A; more importantly,
2607 * if A is currently broken, we cannot go back and try B. To fix
2608 * this would require we do a Resolve cycle for each package we
2609 * add to the install list. Ugh
2613 * If this is a virtual package, we need to check the list of
2614 * packages that provide it and see if any of those are
2617 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
2618 for (; Prv
.end() != true; Prv
++)
2620 if (_config
->FindB("Debug::BuildDeps",false) == true)
2621 cout
<< " Checking provider " << Prv
.OwnerPkg().FullName() << endl
;
2623 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
2627 // Get installed version and version we are going to install
2628 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
2630 if ((*D
).Version
[0] != '\0') {
2631 // Versioned dependency
2633 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
2635 for (; CV
.end() != true; CV
++)
2637 if (Cache
->VS().CheckDep(CV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2640 if (CV
.end() == true)
2642 if (hasAlternatives
)
2648 return _error
->Error(_("%s dependency for %s cannot be satisfied "
2649 "because no available versions of package %s "
2650 "can satisfy version requirements"),
2651 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
2652 (*D
).Package
.c_str());
2658 // Only consider virtual packages if there is no versioned dependency
2659 if (Prv
.end() == false)
2661 if (_config
->FindB("Debug::BuildDeps",false) == true)
2662 cout
<< " Is provided by installed package " << Prv
.OwnerPkg().FullName() << endl
;
2663 skipAlternatives
= hasAlternatives
;
2668 if (IV
.end() == false)
2670 if (_config
->FindB("Debug::BuildDeps",false) == true)
2671 cout
<< " Is installed\n";
2673 if (Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2675 skipAlternatives
= hasAlternatives
;
2679 if (_config
->FindB("Debug::BuildDeps",false) == true)
2680 cout
<< " ...but the installed version doesn't meet the version requirement\n";
2682 if (((*D
).Op
& pkgCache::Dep::LessEq
) == pkgCache::Dep::LessEq
)
2684 return _error
->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
2685 Last
->BuildDepType((*D
).Type
),
2687 Pkg
.FullName(true).c_str());
2692 if (_config
->FindB("Debug::BuildDeps",false) == true)
2693 cout
<< " Trying to install " << (*D
).Package
<< endl
;
2695 if (TryToInstallBuildDep(Pkg
,Cache
,Fix
,false,false) == true)
2697 // We successfully installed something; skip remaining alternatives
2698 skipAlternatives
= hasAlternatives
;
2699 if(_config
->FindB("APT::Get::Build-Dep-Automatic", false) == true)
2700 Cache
->MarkAuto(Pkg
, true);
2703 else if (hasAlternatives
)
2705 if (_config
->FindB("Debug::BuildDeps",false) == true)
2706 cout
<< " Unsatisfiable, trying alternatives\n";
2711 return _error
->Error(_("Failed to satisfy %s dependency for %s: %s"),
2712 Last
->BuildDepType((*D
).Type
),
2714 (*D
).Package
.c_str());
2719 Fix
.InstallProtect();
2720 if (Fix
.Resolve(true) == false)
2723 // Now we check the state of the packages,
2724 if (Cache
->BrokenCount() != 0)
2726 ShowBroken(cout
, Cache
, false);
2727 return _error
->Error(_("Build-dependencies for %s could not be satisfied."),*I
);
2731 if (InstallPackages(Cache
, false, true) == false)
2732 return _error
->Error(_("Failed to process build dependencies"));
2736 // DownloadChangelog - Download the changelog /*{{{*/
2737 // ---------------------------------------------------------------------
2738 string
DownloadChangelog(CacheFile
&CacheFile
, pkgAcquire
&Fetcher
, pkgCache::VerIterator V
)
2747 // data structures we need
2748 pkgRecords
Recs(CacheFile
);
2749 pkgCache::PkgIterator Pkg
= V
.ParentPkg();
2750 pkgRecords::Parser
&rec
=Recs
.Lookup(V
.FileList());
2753 srcpkg
= rec
.SourcePkg().empty() ? Pkg
.Name() : rec
.SourcePkg();
2754 strprintf(descr
, _("Changelog for %s"), srcpkg
.c_str());
2755 // FIXME: we actually need the source section here
2756 src_section
= Pkg
.Section();
2757 if(src_section
.find('/')!=src_section
.npos
)
2758 src_section
=string(src_section
, 0, src_section
.find('/'));
2763 if(srcpkg
.size()>3 && srcpkg
[0]=='l' && srcpkg
[1]=='i' && srcpkg
[2]=='b')
2764 prefix
=std::string("lib")+srcpkg
[3];
2766 verstr
= V
.VerStr();
2767 if(verstr
.find(':')!=verstr
.npos
)
2768 verstr
=string(verstr
, verstr
.find(':')+1);
2770 strprintf(uri
, "http://packages.debian.org/changelogs/pool/%s/%s/%s/%s_%s/changelog", src_section
.c_str(), prefix
.c_str(), srcpkg
.c_str(), srcpkg
.c_str(), verstr
.c_str());
2772 AcqTextStatus
Stat(ScreenWidth
, _config
->FindI("quiet",0));
2773 Fetcher
.Setup(&Stat
);
2776 string targetfile
= tmpnam(strdup("apt-changelog-XXXXXX"));
2777 new pkgAcqFile(&Fetcher
, uri
, "", 0, descr
, srcpkg
, "ignore", targetfile
);
2780 int res
= Fetcher
.Run();
2781 if (FileExists(targetfile
))
2788 // DisplayFileInPager - Display File with pager /*{{{*/
2789 void DisplayFileInPager(string filename
)
2791 pid_t Process
= ExecFork();
2794 const char *Args
[3];
2795 Args
[0] = "/usr/bin/sensible-pager";
2796 Args
[1] = filename
.c_str();
2798 execvp(Args
[0],(char **)Args
);
2802 // Wait for the subprocess
2803 ExecWait(Process
, "sensible-pager", false);
2806 // DoChangelog - Get changelog from the command line /*{{{*/
2807 // ---------------------------------------------------------------------
2808 bool DoChangelog(CommandLine
&CmdL
)
2811 if (Cache
.ReadOnlyOpen() == false)
2814 APT::CacheSetHelper
helper(c0out
);
2815 APT::VersionSet verset
= APT::VersionSet::FromCommandLine(Cache
,
2816 CmdL
.FileList
+ 1, APT::VersionSet::CANDIDATE
, helper
);
2819 if (verset
.empty() == true)
2821 for (APT::VersionSet::const_iterator Ver
= verset
.begin();
2822 Ver
!= verset
.end();
2825 string changelogfile
= DownloadChangelog(Cache
, Fetcher
, Ver
);
2826 if (changelogfile
.size() > 0)
2828 DisplayFileInPager(changelogfile
);
2829 unlink(changelogfile
.c_str());
2834 // DoMoo - Never Ask, Never Tell /*{{{*/
2835 // ---------------------------------------------------------------------
2837 bool DoMoo(CommandLine
&CmdL
)
2846 "....\"Have you mooed today?\"...\n";
2851 // ShowHelp - Show a help screen /*{{{*/
2852 // ---------------------------------------------------------------------
2854 bool ShowHelp(CommandLine
&CmdL
)
2856 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,VERSION
,
2857 COMMON_ARCH
,__DATE__
,__TIME__
);
2859 if (_config
->FindB("version") == true)
2861 cout
<< _("Supported modules:") << endl
;
2863 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
2865 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
2866 if (_system
!= 0 && _system
->VS
== VS
)
2870 cout
<< "Ver: " << VS
->Label
<< endl
;
2872 /* Print out all the packaging systems that will work with
2874 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
2876 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
2881 if (Sys
->VS
->TestCompatibility(*VS
) == true)
2882 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
2886 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
2888 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
2889 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
2892 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
2894 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
2895 cout
<< " Idx: " << Type
->Label
<< endl
;
2902 _("Usage: apt-get [options] command\n"
2903 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
2904 " apt-get [options] source pkg1 [pkg2 ...]\n"
2906 "apt-get is a simple command line interface for downloading and\n"
2907 "installing packages. The most frequently used commands are update\n"
2911 " update - Retrieve new lists of packages\n"
2912 " upgrade - Perform an upgrade\n"
2913 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
2914 " remove - Remove packages\n"
2915 " autoremove - Remove automatically all unused packages\n"
2916 " purge - Remove packages and config files\n"
2917 " source - Download source archives\n"
2918 " build-dep - Configure build-dependencies for source packages\n"
2919 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
2920 " dselect-upgrade - Follow dselect selections\n"
2921 " clean - Erase downloaded archive files\n"
2922 " autoclean - Erase old downloaded archive files\n"
2923 " check - Verify that there are no broken dependencies\n"
2924 " markauto - Mark the given packages as automatically installed\n"
2925 " unmarkauto - Mark the given packages as manually installed\n"
2928 " -h This help text.\n"
2929 " -q Loggable output - no progress indicator\n"
2930 " -qq No output except for errors\n"
2931 " -d Download only - do NOT install or unpack archives\n"
2932 " -s No-act. Perform ordering simulation\n"
2933 " -y Assume Yes to all queries and do not prompt\n"
2934 " -f Attempt to correct a system with broken dependencies in place\n"
2935 " -m Attempt to continue if archives are unlocatable\n"
2936 " -u Show a list of upgraded packages as well\n"
2937 " -b Build the source package after fetching it\n"
2938 " -V Show verbose version numbers\n"
2939 " -c=? Read this configuration file\n"
2940 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
2941 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
2942 "pages for more information and options.\n"
2943 " This APT has Super Cow Powers.\n");
2947 // SigWinch - Window size change signal handler /*{{{*/
2948 // ---------------------------------------------------------------------
2952 // Riped from GNU ls
2956 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
2957 ScreenWidth
= ws
.ws_col
- 1;
2961 int main(int argc
,const char *argv
[]) /*{{{*/
2963 CommandLine::Args Args
[] = {
2964 {'h',"help","help",0},
2965 {'v',"version","version",0},
2966 {'V',"verbose-versions","APT::Get::Show-Versions",0},
2967 {'q',"quiet","quiet",CommandLine::IntLevel
},
2968 {'q',"silent","quiet",CommandLine::IntLevel
},
2969 {'d',"download-only","APT::Get::Download-Only",0},
2970 {'b',"compile","APT::Get::Compile",0},
2971 {'b',"build","APT::Get::Compile",0},
2972 {'s',"simulate","APT::Get::Simulate",0},
2973 {'s',"just-print","APT::Get::Simulate",0},
2974 {'s',"recon","APT::Get::Simulate",0},
2975 {'s',"dry-run","APT::Get::Simulate",0},
2976 {'s',"no-act","APT::Get::Simulate",0},
2977 {'y',"yes","APT::Get::Assume-Yes",0},
2978 {'y',"assume-yes","APT::Get::Assume-Yes",0},
2979 {'f',"fix-broken","APT::Get::Fix-Broken",0},
2980 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
2981 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
2982 {'t',"target-release","APT::Default-Release",CommandLine::HasArg
},
2983 {'t',"default-release","APT::Default-Release",CommandLine::HasArg
},
2984 {0,"download","APT::Get::Download",0},
2985 {0,"fix-missing","APT::Get::Fix-Missing",0},
2986 {0,"ignore-hold","APT::Ignore-Hold",0},
2987 {0,"upgrade","APT::Get::upgrade",0},
2988 {0,"only-upgrade","APT::Get::Only-Upgrade",0},
2989 {0,"force-yes","APT::Get::force-yes",0},
2990 {0,"print-uris","APT::Get::Print-URIs",0},
2991 {0,"diff-only","APT::Get::Diff-Only",0},
2992 {0,"debian-only","APT::Get::Diff-Only",0},
2993 {0,"tar-only","APT::Get::Tar-Only",0},
2994 {0,"dsc-only","APT::Get::Dsc-Only",0},
2995 {0,"purge","APT::Get::Purge",0},
2996 {0,"list-cleanup","APT::Get::List-Cleanup",0},
2997 {0,"reinstall","APT::Get::ReInstall",0},
2998 {0,"trivial-only","APT::Get::Trivial-Only",0},
2999 {0,"remove","APT::Get::Remove",0},
3000 {0,"only-source","APT::Get::Only-Source",0},
3001 {0,"arch-only","APT::Get::Arch-Only",0},
3002 {0,"auto-remove","APT::Get::AutomaticRemove",0},
3003 {0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0},
3004 {0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean
},
3005 {0,"fix-policy","APT::Get::Fix-Policy-Broken",0},
3006 {'c',"config-file",0,CommandLine::ConfigFile
},
3007 {'o',"option",0,CommandLine::ArbItem
},
3009 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
3010 {"upgrade",&DoUpgrade
},
3011 {"install",&DoInstall
},
3012 {"remove",&DoInstall
},
3013 {"purge",&DoInstall
},
3014 {"autoremove",&DoInstall
},
3015 {"markauto",&DoMarkAuto
},
3016 {"unmarkauto",&DoMarkAuto
},
3017 {"dist-upgrade",&DoDistUpgrade
},
3018 {"dselect-upgrade",&DoDSelectUpgrade
},
3019 {"build-dep",&DoBuildDep
},
3021 {"autoclean",&DoAutoClean
},
3023 {"source",&DoSource
},
3024 {"changelog",&DoChangelog
},
3029 // Set up gettext support
3030 setlocale(LC_ALL
,"");
3031 textdomain(PACKAGE
);
3033 // Parse the command line and initialize the package library
3034 CommandLine
CmdL(Args
,_config
);
3035 if (pkgInitConfig(*_config
) == false ||
3036 CmdL
.Parse(argc
,argv
) == false ||
3037 pkgInitSystem(*_config
,_system
) == false)
3039 if (_config
->FindB("version") == true)
3042 _error
->DumpErrors();
3046 // See if the help should be shown
3047 if (_config
->FindB("help") == true ||
3048 _config
->FindB("version") == true ||
3049 CmdL
.FileSize() == 0)
3055 // simulate user-friendly if apt-get has no root privileges
3056 if (getuid() != 0 && _config
->FindB("APT::Get::Simulate") == true)
3058 if (_config
->FindB("APT::Get::Show-User-Simulation-Note",true) == true)
3059 cout
<< _("NOTE: This is only a simulation!\n"
3060 " apt-get needs root privileges for real execution.\n"
3061 " Keep also in mind that locking is deactivated,\n"
3062 " so don't depend on the relevance to the real current situation!"
3064 _config
->Set("Debug::NoLocking",true);
3067 // Deal with stdout not being a tty
3068 if (!isatty(STDOUT_FILENO
) && _config
->FindI("quiet", -1) == -1)
3069 _config
->Set("quiet","1");
3071 // Setup the output streams
3072 c0out
.rdbuf(cout
.rdbuf());
3073 c1out
.rdbuf(cout
.rdbuf());
3074 c2out
.rdbuf(cout
.rdbuf());
3075 if (_config
->FindI("quiet",0) > 0)
3076 c0out
.rdbuf(devnull
.rdbuf());
3077 if (_config
->FindI("quiet",0) > 1)
3078 c1out
.rdbuf(devnull
.rdbuf());
3080 // Setup the signals
3081 signal(SIGPIPE
,SIG_IGN
);
3082 signal(SIGWINCH
,SigWinch
);
3085 // Match the operation
3086 CmdL
.DispatchArg(Cmds
);
3088 // Print any errors or warnings found during parsing
3089 bool const Errors
= _error
->PendingError();
3090 if (_config
->FindI("quiet",0) > 0)
3091 _error
->DumpErrors();
3093 _error
->DumpErrors(GlobalError::DEBUG
);
3094 return Errors
== true ? 100 : 0;