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 #include <apt-pkg/error.h>
29 #include <apt-pkg/cmndline.h>
30 #include <apt-pkg/init.h>
31 #include <apt-pkg/depcache.h>
32 #include <apt-pkg/sourcelist.h>
33 #include <apt-pkg/algorithms.h>
34 #include <apt-pkg/acquire-item.h>
35 #include <apt-pkg/strutl.h>
36 #include <apt-pkg/clean.h>
37 #include <apt-pkg/srcrecords.h>
38 #include <apt-pkg/version.h>
39 #include <apt-pkg/cachefile.h>
40 #include <apt-pkg/sptr.h>
41 #include <apt-pkg/md5.h>
42 #include <apt-pkg/versionmatch.h>
47 #include "acqprogress.h"
55 #include <sys/ioctl.h>
57 #include <sys/statfs.h>
58 #include <sys/statvfs.h>
68 #define RAMFS_MAGIC 0x858458f6
75 ofstream
devnull("/dev/null");
76 unsigned int ScreenWidth
= 80 - 1; /* - 1 for the cursor */
78 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
79 // ---------------------------------------------------------------------
81 class CacheFile
: public pkgCacheFile
83 static pkgCache
*SortCache
;
84 static int NameComp(const void *a
,const void *b
);
87 pkgCache::Package
**List
;
90 bool CheckDeps(bool AllowBroken
= false);
91 bool BuildCaches(bool WithLock
= true)
93 OpTextProgress
Prog(*_config
);
94 if (pkgCacheFile::BuildCaches(&Prog
,WithLock
) == false)
98 bool Open(bool WithLock
= true)
100 OpTextProgress
Prog(*_config
);
101 if (pkgCacheFile::Open(&Prog
,WithLock
) == false)
107 bool OpenForInstall()
109 if (_config
->FindB("APT::Get::Print-URIs") == true)
114 CacheFile() : List(0) {};
121 // YnPrompt - Yes No Prompt. /*{{{*/
122 // ---------------------------------------------------------------------
123 /* Returns true on a Yes.*/
124 bool YnPrompt(bool Default
=true)
126 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
128 c1out
<< _("Y") << endl
;
132 char response
[1024] = "";
133 cin
.getline(response
, sizeof(response
));
138 if (strlen(response
) == 0)
144 Res
= regcomp(&Pattern
, nl_langinfo(YESEXPR
),
145 REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
149 regerror(Res
,&Pattern
,Error
,sizeof(Error
));
150 return _error
->Error(_("Regex compilation error - %s"),Error
);
153 Res
= regexec(&Pattern
, response
, 0, NULL
, 0);
159 // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
160 // ---------------------------------------------------------------------
161 /* Returns true on a Yes.*/
162 bool AnalPrompt(const char *Text
)
165 cin
.getline(Buf
,sizeof(Buf
));
166 if (strcmp(Buf
,Text
) == 0)
171 // ShowList - Show a list /*{{{*/
172 // ---------------------------------------------------------------------
173 /* This prints out a string of space separated words with a title and
174 a two space indent line wraped to the current screen width. */
175 bool ShowList(ostream
&out
,string Title
,string List
,string VersionsList
)
177 if (List
.empty() == true)
179 // trim trailing space
180 int NonSpace
= List
.find_last_not_of(' ');
183 List
= List
.erase(NonSpace
+ 1);
184 if (List
.empty() == true)
188 // Acount for the leading space
189 int ScreenWidth
= ::ScreenWidth
- 3;
191 out
<< Title
<< endl
;
192 string::size_type Start
= 0;
193 string::size_type VersionsStart
= 0;
194 while (Start
< List
.size())
196 if(_config
->FindB("APT::Get::Show-Versions",false) == true &&
197 VersionsList
.size() > 0) {
198 string::size_type End
;
199 string::size_type VersionsEnd
;
201 End
= List
.find(' ',Start
);
202 VersionsEnd
= VersionsList
.find('\n', VersionsStart
);
204 out
<< " " << string(List
,Start
,End
- Start
) << " (" <<
205 string(VersionsList
,VersionsStart
,VersionsEnd
- VersionsStart
) <<
208 if (End
== string::npos
|| End
< Start
)
209 End
= Start
+ ScreenWidth
;
212 VersionsStart
= VersionsEnd
+ 1;
214 string::size_type End
;
216 if (Start
+ ScreenWidth
>= List
.size())
219 End
= List
.rfind(' ',Start
+ScreenWidth
);
221 if (End
== string::npos
|| End
< Start
)
222 End
= Start
+ ScreenWidth
;
223 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
231 // ShowBroken - Debugging aide /*{{{*/
232 // ---------------------------------------------------------------------
233 /* This prints out the names of all the packages that are broken along
234 with the name of each each broken dependency and a quite version
237 The output looks like:
238 The following packages have unmet dependencies:
239 exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed
240 Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
241 Depends: libsasl7 but it is not going to be installed
243 void ShowBroken(ostream
&out
,CacheFile
&Cache
,bool Now
)
245 out
<< _("The following packages have unmet dependencies:") << endl
;
246 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
248 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
252 if (Cache
[I
].NowBroken() == false)
257 if (Cache
[I
].InstBroken() == false)
261 // Print out each package and the failed dependencies
262 out
<< " " << I
.FullName(true) << " :";
263 unsigned const Indent
= I
.FullName(true).size() + 3;
265 pkgCache::VerIterator Ver
;
268 Ver
= I
.CurrentVer();
270 Ver
= Cache
[I
].InstVerIter(Cache
);
272 if (Ver
.end() == true)
278 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false;)
280 // Compute a single dependency element (glob or)
281 pkgCache::DepIterator Start
;
282 pkgCache::DepIterator End
;
283 D
.GlobOr(Start
,End
); // advances D
285 if (Cache
->IsImportantDep(End
) == false)
290 if ((Cache
[End
] & pkgDepCache::DepGNow
) == pkgDepCache::DepGNow
)
295 if ((Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
303 for (unsigned J
= 0; J
!= Indent
; J
++)
307 if (FirstOr
== false)
309 for (unsigned J
= 0; J
!= strlen(End
.DepType()) + 3; J
++)
313 out
<< ' ' << End
.DepType() << ": ";
316 out
<< Start
.TargetPkg().FullName(true);
318 // Show a quick summary of the version requirements
319 if (Start
.TargetVer() != 0)
320 out
<< " (" << Start
.CompType() << " " << Start
.TargetVer() << ")";
322 /* Show a summary of the target package if possible. In the case
323 of virtual packages we show nothing */
324 pkgCache::PkgIterator Targ
= Start
.TargetPkg();
325 if (Targ
->ProvidesList
== 0)
328 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
330 Ver
= Targ
.CurrentVer();
332 if (Ver
.end() == false)
335 ioprintf(out
,_("but %s is installed"),Ver
.VerStr());
337 ioprintf(out
,_("but %s is to be installed"),Ver
.VerStr());
341 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
343 if (Targ
->ProvidesList
== 0)
344 out
<< _("but it is not installable");
346 out
<< _("but it is a virtual package");
349 out
<< (Now
?_("but it is not installed"):_("but it is not going to be installed"));
365 // ShowNew - Show packages to newly install /*{{{*/
366 // ---------------------------------------------------------------------
368 void ShowNew(ostream
&out
,CacheFile
&Cache
)
370 /* Print out a list of packages that are going to be installed extra
371 to what the user asked */
374 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
376 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
377 if (Cache
[I
].NewInstall() == true) {
378 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
380 List
+= I
.FullName(true) + " ";
381 VersionsList
+= string(Cache
[I
].CandVersion
) + "\n";
385 ShowList(out
,_("The following NEW packages will be installed:"),List
,VersionsList
);
388 // ShowDel - Show packages to delete /*{{{*/
389 // ---------------------------------------------------------------------
391 void ShowDel(ostream
&out
,CacheFile
&Cache
)
393 /* Print out a list of packages that are going to be removed extra
394 to what the user asked */
397 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
399 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
400 if (Cache
[I
].Delete() == true)
402 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
404 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
405 List
+= I
.FullName(true) + "* ";
407 List
+= I
.FullName(true) + " ";
409 VersionsList
+= string(Cache
[I
].CandVersion
)+ "\n";
413 ShowList(out
,_("The following packages will be REMOVED:"),List
,VersionsList
);
416 // ShowKept - Show kept packages /*{{{*/
417 // ---------------------------------------------------------------------
419 void ShowKept(ostream
&out
,CacheFile
&Cache
)
423 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
425 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
428 if (Cache
[I
].Upgrade() == true || Cache
[I
].Upgradable() == false ||
429 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
432 List
+= I
.FullName(true) + " ";
433 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
435 ShowList(out
,_("The following packages have been kept back:"),List
,VersionsList
);
438 // ShowUpgraded - Show upgraded packages /*{{{*/
439 // ---------------------------------------------------------------------
441 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
445 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
447 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
450 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
452 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
455 List
+= I
.FullName(true) + " ";
456 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
458 ShowList(out
,_("The following packages will be upgraded:"),List
,VersionsList
);
461 // ShowDowngraded - Show downgraded packages /*{{{*/
462 // ---------------------------------------------------------------------
464 bool ShowDowngraded(ostream
&out
,CacheFile
&Cache
)
468 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
470 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
473 if (Cache
[I
].Downgrade() == false || Cache
[I
].NewInstall() == true)
475 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
478 List
+= I
.FullName(true) + " ";
479 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
481 return ShowList(out
,_("The following packages will be DOWNGRADED:"),List
,VersionsList
);
484 // ShowHold - Show held but changed packages /*{{{*/
485 // ---------------------------------------------------------------------
487 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
491 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
493 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
494 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
495 I
->SelectedState
== pkgCache::State::Hold
) {
496 List
+= I
.FullName(true) + " ";
497 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
501 return ShowList(out
,_("The following held packages will be changed:"),List
,VersionsList
);
504 // ShowEssential - Show an essential package warning /*{{{*/
505 // ---------------------------------------------------------------------
506 /* This prints out a warning message that is not to be ignored. It shows
507 all essential packages and their dependents that are to be removed.
508 It is insanely risky to remove the dependents of an essential package! */
509 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
513 bool *Added
= new bool[Cache
->Head().PackageCount
];
514 for (unsigned int I
= 0; I
!= Cache
->Head().PackageCount
; I
++)
517 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
519 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
520 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
&&
521 (I
->Flags
& pkgCache::Flag::Important
) != pkgCache::Flag::Important
)
524 // The essential package is being removed
525 if (Cache
[I
].Delete() == true)
527 if (Added
[I
->ID
] == false)
530 List
+= I
.FullName(true) + " ";
531 //VersionsList += string(Cache[I].CurVersion) + "\n"; ???
535 if (I
->CurrentVer
== 0)
538 // Print out any essential package depenendents that are to be removed
539 for (pkgCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
541 // Skip everything but depends
542 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
543 D
->Type
!= pkgCache::Dep::Depends
)
546 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
547 if (Cache
[P
].Delete() == true)
549 if (Added
[P
->ID
] == true)
554 snprintf(S
,sizeof(S
),_("%s (due to %s) "),P
.FullName(true).c_str(),I
.FullName(true).c_str());
556 //VersionsList += "\n"; ???
562 return ShowList(out
,_("WARNING: The following essential packages will be removed.\n"
563 "This should NOT be done unless you know exactly what you are doing!"),List
,VersionsList
);
567 // Stats - Show some statistics /*{{{*/
568 // ---------------------------------------------------------------------
570 void Stats(ostream
&out
,pkgDepCache
&Dep
)
572 unsigned long Upgrade
= 0;
573 unsigned long Downgrade
= 0;
574 unsigned long Install
= 0;
575 unsigned long ReInstall
= 0;
576 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
578 if (pkgCache::VerIterator(Dep
, Dep
[I
].CandidateVer
).Pseudo() == true)
581 if (Dep
[I
].NewInstall() == true)
585 if (Dep
[I
].Upgrade() == true)
588 if (Dep
[I
].Downgrade() == true)
592 if (Dep
[I
].Delete() == false && (Dep
[I
].iFlags
& pkgDepCache::ReInstall
) == pkgDepCache::ReInstall
)
596 ioprintf(out
,_("%lu upgraded, %lu newly installed, "),
600 ioprintf(out
,_("%lu reinstalled, "),ReInstall
);
602 ioprintf(out
,_("%lu downgraded, "),Downgrade
);
604 ioprintf(out
,_("%lu to remove and %lu not upgraded.\n"),
605 Dep
.DelCount(),Dep
.KeepCount());
607 if (Dep
.BadCount() != 0)
608 ioprintf(out
,_("%lu not fully installed or removed.\n"),
612 // CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/
613 class CacheSetHelperAPTGet
: public APT::CacheSetHelper
{
614 /** \brief stream message should be printed to */
616 /** \brief were things like Task or RegEx used to select packages? */
617 bool explicitlyNamed
;
619 APT::PackageSet virtualPkgs
;
622 CacheSetHelperAPTGet(std::ostream
&out
) : APT::CacheSetHelper(true), out(out
) {
623 explicitlyNamed
= true;
626 virtual void showTaskSelection(APT::PackageSet
const &pkgset
, string
const &pattern
) {
627 for (APT::PackageSet::const_iterator Pkg
= pkgset
.begin(); Pkg
!= pkgset
.end(); ++Pkg
)
628 ioprintf(out
, _("Note, selecting '%s' for task '%s'\n"),
629 Pkg
.FullName(true).c_str(), pattern
.c_str());
630 explicitlyNamed
= false;
632 virtual void showRegExSelection(APT::PackageSet
const &pkgset
, string
const &pattern
) {
633 for (APT::PackageSet::const_iterator Pkg
= pkgset
.begin(); Pkg
!= pkgset
.end(); ++Pkg
)
634 ioprintf(out
, _("Note, selecting '%s' for regex '%s'\n"),
635 Pkg
.FullName(true).c_str(), pattern
.c_str());
636 explicitlyNamed
= false;
638 virtual void showSelectedVersion(pkgCache::PkgIterator
const &Pkg
, pkgCache::VerIterator
const Ver
,
639 string
const &ver
, bool const &verIsRel
) {
640 if (ver
!= Ver
.VerStr())
641 ioprintf(out
, _("Selected version '%s' (%s) for '%s'\n"),
642 Ver
.VerStr(), Ver
.RelStr().c_str(), Pkg
.FullName(true).c_str());
645 bool showVirtualPackageErrors(pkgCacheFile
&Cache
) {
646 if (virtualPkgs
.empty() == true)
648 for (APT::PackageSet::const_iterator Pkg
= virtualPkgs
.begin();
649 Pkg
!= virtualPkgs
.end(); ++Pkg
) {
650 if (Pkg
->ProvidesList
!= 0) {
651 ioprintf(c1out
,_("Package %s is a virtual package provided by:\n"),
652 Pkg
.FullName(true).c_str());
654 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
655 unsigned short provider
= 0;
656 for (; I
.end() == false; ++I
) {
657 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
659 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer()) {
660 out
<< " " << Pkg
.FullName(true) << " " << I
.OwnerVer().VerStr();
661 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
662 out
<< _(" [Installed]");
667 // if we found no candidate which provide this package, show non-candidates
669 for (I
= Pkg
.ProvidesList(); I
.end() == false; I
++)
670 out
<< " " << I
.OwnerPkg().FullName(true) << " " << I
.OwnerVer().VerStr()
671 << _(" [Not candidate version]") << endl
;
673 out
<< _("You should explicitly select one to install.") << endl
;
676 _("Package %s is not available, but is referred to by another package.\n"
677 "This may mean that the package is missing, has been obsoleted, or\n"
678 "is only available from another source\n"),Pkg
.FullName(true).c_str());
682 SPtrArray
<bool> Seen
= new bool[Cache
.GetPkgCache()->Head().PackageCount
];
683 memset(Seen
,0,Cache
.GetPkgCache()->Head().PackageCount
*sizeof(*Seen
));
684 for (pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
685 Dep
.end() == false; Dep
++) {
686 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
688 if (Seen
[Dep
.ParentPkg()->ID
] == true)
690 Seen
[Dep
.ParentPkg()->ID
] = true;
691 List
+= Dep
.ParentPkg().FullName(true) + " ";
692 //VersionsList += string(Dep.ParentPkg().CurVersion) + "\n"; ???
694 ShowList(out
,_("However the following packages replace it:"),List
,VersionsList
);
701 virtual pkgCache::VerIterator
canNotFindCandidateVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
702 APT::VersionSet
const verset
= tryVirtualPackage(Cache
, Pkg
, APT::VersionSet::CANDIDATE
);
703 if (verset
.empty() == false)
704 return *(verset
.begin());
705 if (ShowError
== true) {
706 _error
->Error(_("Package '%s' has no installation candidate"),Pkg
.FullName(true).c_str());
707 virtualPkgs
.insert(Pkg
);
709 return pkgCache::VerIterator(Cache
, 0);
712 virtual pkgCache::VerIterator
canNotFindNewestVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
713 APT::VersionSet
const verset
= tryVirtualPackage(Cache
, Pkg
, APT::VersionSet::NEWEST
);
714 if (verset
.empty() == false)
715 return *(verset
.begin());
716 if (ShowError
== true)
717 ioprintf(out
, _("Virtual packages like '%s' can't be removed\n"), Pkg
.FullName(true).c_str());
718 return pkgCache::VerIterator(Cache
, 0);
721 APT::VersionSet
tryVirtualPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
,
722 APT::VersionSet::Version
const &select
) {
723 /* This is a pure virtual package and there is a single available
724 candidate providing it. */
725 if (unlikely(Cache
[Pkg
].CandidateVer
!= 0) || Pkg
->ProvidesList
== 0)
726 return APT::VersionSet();
728 pkgCache::PkgIterator Prov
;
729 bool found_one
= false;
730 for (pkgCache::PrvIterator P
= Pkg
.ProvidesList(); P
; ++P
) {
731 pkgCache::VerIterator
const PVer
= P
.OwnerVer();
732 pkgCache::PkgIterator
const PPkg
= PVer
.ParentPkg();
734 /* Ignore versions that are not a candidate. */
735 if (Cache
[PPkg
].CandidateVer
!= PVer
)
738 if (found_one
== false) {
741 } else if (PPkg
!= Prov
) {
742 found_one
= false; // we found at least two
747 if (found_one
== true) {
748 ioprintf(out
, _("Note, selecting '%s' instead of '%s'\n"),
749 Prov
.FullName(true).c_str(), Pkg
.FullName(true).c_str());
750 return APT::VersionSet::FromPackage(Cache
, Prov
, select
, *this);
752 return APT::VersionSet();
755 inline bool allPkgNamedExplicitly() const { return explicitlyNamed
; }
759 // TryToInstall - Mark a package for installation /*{{{*/
760 struct TryToInstall
{
762 pkgProblemResolver
* Fix
;
764 unsigned long AutoMarkChanged
;
766 TryToInstall(pkgCacheFile
&Cache
, pkgProblemResolver
&PM
, bool const &FixBroken
) : Cache(&Cache
), Fix(&PM
),
767 FixBroken(FixBroken
), AutoMarkChanged(0) {};
769 void operator() (pkgCache::VerIterator
const &Ver
) {
770 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
771 Cache
->GetDepCache()->SetCandidateVersion(Ver
);
772 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
774 // Handle the no-upgrade case
775 if (_config
->FindB("APT::Get::upgrade",true) == false && Pkg
->CurrentVer
!= 0)
776 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
777 Pkg
.FullName(true).c_str());
778 // Ignore request for install if package would be new
779 else if (_config
->FindB("APT::Get::Only-Upgrade", false) == true && Pkg
->CurrentVer
== 0)
780 ioprintf(c1out
,_("Skipping %s, it is not installed and only upgrades are requested.\n"),
781 Pkg
.FullName(true).c_str());
785 Cache
->GetDepCache()->MarkInstall(Pkg
,false);
787 if (State
.Install() == false) {
788 if (_config
->FindB("APT::Get::ReInstall",false) == true) {
789 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
790 ioprintf(c1out
,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
791 Pkg
.FullName(true).c_str());
793 Cache
->GetDepCache()->SetReInstall(Pkg
, true);
795 ioprintf(c1out
,_("%s is already the newest version.\n"),
796 Pkg
.FullName(true).c_str());
799 // Install it with autoinstalling enabled (if we not respect the minial
800 // required deps or the policy)
801 if ((State
.InstBroken() == true || State
.InstPolicyBroken() == true) && FixBroken
== false)
802 Cache
->GetDepCache()->MarkInstall(Pkg
,true);
805 // see if we need to fix the auto-mark flag
806 // e.g. apt-get install foo
807 // where foo is marked automatic
808 if (State
.Install() == false &&
809 (State
.Flags
& pkgCache::Flag::Auto
) &&
810 _config
->FindB("APT::Get::ReInstall",false) == false &&
811 _config
->FindB("APT::Get::Only-Upgrade",false) == false &&
812 _config
->FindB("APT::Get::Download-Only",false) == false)
814 ioprintf(c1out
,_("%s set to manually installed.\n"),
815 Pkg
.FullName(true).c_str());
816 Cache
->GetDepCache()->MarkAuto(Pkg
,false);
822 // TryToRemove - Mark a package for removal /*{{{*/
825 pkgProblemResolver
* Fix
;
827 unsigned long AutoMarkChanged
;
829 TryToRemove(pkgCacheFile
&Cache
, pkgProblemResolver
&PM
) : Cache(&Cache
), Fix(&PM
) {};
831 void operator() (pkgCache::VerIterator
const &Ver
)
833 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
839 if (Pkg
->CurrentVer
== 0)
840 ioprintf(c1out
,_("Package %s is not installed, so not removed\n"),Pkg
.FullName(true).c_str());
842 Cache
->GetDepCache()->MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
846 // CacheFile::NameComp - QSort compare by name /*{{{*/
847 // ---------------------------------------------------------------------
849 pkgCache
*CacheFile::SortCache
= 0;
850 int CacheFile::NameComp(const void *a
,const void *b
)
852 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
853 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
855 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
856 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
858 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
861 // CacheFile::Sort - Sort by name /*{{{*/
862 // ---------------------------------------------------------------------
864 void CacheFile::Sort()
867 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
868 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
869 pkgCache::PkgIterator I
= Cache
->PkgBegin();
870 for (;I
.end() != true; I
++)
874 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
877 // CacheFile::CheckDeps - Open the cache file /*{{{*/
878 // ---------------------------------------------------------------------
879 /* This routine generates the caches and then opens the dependency cache
880 and verifies that the system is OK. */
881 bool CacheFile::CheckDeps(bool AllowBroken
)
883 bool FixBroken
= _config
->FindB("APT::Get::Fix-Broken",false);
885 if (_error
->PendingError() == true)
888 // Check that the system is OK
889 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
890 return _error
->Error("Internal error, non-zero counts");
892 // Apply corrections for half-installed packages
893 if (pkgApplyStatus(*DCache
) == false)
896 if (_config
->FindB("APT::Get::Fix-Policy-Broken",false) == true)
899 if ((DCache
->PolicyBrokenCount() > 0))
901 // upgrade all policy-broken packages with ForceImportantDeps=True
902 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); !I
.end(); I
++)
903 if ((*DCache
)[I
].NowPolicyBroken() == true)
904 DCache
->MarkInstall(I
,true,0, false, true);
909 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
912 // Attempt to fix broken things
913 if (FixBroken
== true)
915 c1out
<< _("Correcting dependencies...") << flush
;
916 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
918 c1out
<< _(" failed.") << endl
;
919 ShowBroken(c1out
,*this,true);
921 return _error
->Error(_("Unable to correct dependencies"));
923 if (pkgMinimizeUpgrade(*DCache
) == false)
924 return _error
->Error(_("Unable to minimize the upgrade set"));
926 c1out
<< _(" Done") << endl
;
930 c1out
<< _("You might want to run 'apt-get -f install' to correct these.") << endl
;
931 ShowBroken(c1out
,*this,true);
933 return _error
->Error(_("Unmet dependencies. Try using -f."));
939 // CheckAuth - check if each download comes form a trusted source /*{{{*/
940 // ---------------------------------------------------------------------
942 static bool CheckAuth(pkgAcquire
& Fetcher
)
944 string UntrustedList
;
945 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd(); ++I
)
947 if (!(*I
)->IsTrusted())
949 UntrustedList
+= string((*I
)->ShortDesc()) + " ";
953 if (UntrustedList
== "")
958 ShowList(c2out
,_("WARNING: The following packages cannot be authenticated!"),UntrustedList
,"");
960 if (_config
->FindB("APT::Get::AllowUnauthenticated",false) == true)
962 c2out
<< _("Authentication warning overridden.\n");
966 if (_config
->FindI("quiet",0) < 2
967 && _config
->FindB("APT::Get::Assume-Yes",false) == false)
969 c2out
<< _("Install these packages without verification [y/N]? ") << flush
;
970 if (!YnPrompt(false))
971 return _error
->Error(_("Some packages could not be authenticated"));
975 else if (_config
->FindB("APT::Get::Force-Yes",false) == true)
980 return _error
->Error(_("There are problems and -y was used without --force-yes"));
983 // InstallPackages - Actually download and install the packages /*{{{*/
984 // ---------------------------------------------------------------------
985 /* This displays the informative messages describing what is going to
986 happen and then calls the download routines */
987 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,
990 if (_config
->FindB("APT::Get::Purge",false) == true)
992 pkgCache::PkgIterator I
= Cache
->PkgBegin();
993 for (; I
.end() == false; I
++)
995 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
996 Cache
->MarkDelete(I
,true);
1001 bool Essential
= false;
1003 // Show all the various warning indicators
1004 ShowDel(c1out
,Cache
);
1005 ShowNew(c1out
,Cache
);
1006 if (ShwKept
== true)
1007 ShowKept(c1out
,Cache
);
1008 Fail
|= !ShowHold(c1out
,Cache
);
1009 if (_config
->FindB("APT::Get::Show-Upgraded",true) == true)
1010 ShowUpgraded(c1out
,Cache
);
1011 Fail
|= !ShowDowngraded(c1out
,Cache
);
1012 if (_config
->FindB("APT::Get::Download-Only",false) == false)
1013 Essential
= !ShowEssential(c1out
,Cache
);
1018 if (Cache
->BrokenCount() != 0)
1020 ShowBroken(c1out
,Cache
,false);
1021 return _error
->Error(_("Internal error, InstallPackages was called with broken packages!"));
1024 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
1025 Cache
->BadCount() == 0)
1029 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::Remove",true) == false)
1030 return _error
->Error(_("Packages need to be removed but remove is disabled."));
1032 // Run the simulator ..
1033 if (_config
->FindB("APT::Get::Simulate") == true)
1035 pkgSimulate
PM(Cache
);
1036 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
1037 pkgPackageManager::OrderResult Res
= PM
.DoInstall(status_fd
);
1038 if (Res
== pkgPackageManager::Failed
)
1040 if (Res
!= pkgPackageManager::Completed
)
1041 return _error
->Error(_("Internal error, Ordering didn't finish"));
1045 // Create the text record parser
1046 pkgRecords
Recs(Cache
);
1047 if (_error
->PendingError() == true)
1050 // Create the download object
1052 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1053 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
1055 // force a hashsum for compatibility reasons
1056 _config
->CndSet("Acquire::ForceHash", "md5sum");
1057 if (Fetcher
.Setup(&Stat
, "") == false)
1060 else if (Fetcher
.Setup(&Stat
, _config
->FindDir("Dir::Cache::Archives")) == false)
1063 // Read the source list
1065 if (List
.ReadMainList() == false)
1066 return _error
->Error(_("The list of sources could not be read."));
1068 // Create the package manager and prepare to download
1069 SPtr
<pkgPackageManager
> PM
= _system
->CreatePM(Cache
);
1070 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false ||
1071 _error
->PendingError() == true)
1074 // Display statistics
1075 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
1076 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
1077 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
1078 if (DebBytes
!= Cache
->DebSize())
1080 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
1081 c0out
<< _("How odd.. The sizes didn't match, email apt@packages.debian.org") << endl
;
1085 if (DebBytes
!= FetchBytes
)
1086 ioprintf(c1out
,_("Need to get %sB/%sB of archives.\n"),
1087 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
1088 else if (DebBytes
!= 0)
1089 ioprintf(c1out
,_("Need to get %sB of archives.\n"),
1090 SizeToStr(DebBytes
).c_str());
1093 if (Cache
->UsrSize() >= 0)
1094 ioprintf(c1out
,_("After this operation, %sB of additional disk space will be used.\n"),
1095 SizeToStr(Cache
->UsrSize()).c_str());
1097 ioprintf(c1out
,_("After this operation, %sB disk space will be freed.\n"),
1098 SizeToStr(-1*Cache
->UsrSize()).c_str());
1100 if (_error
->PendingError() == true)
1103 /* Check for enough free space, but only if we are actually going to
1105 if (_config
->FindB("APT::Get::Print-URIs") == false &&
1106 _config
->FindB("APT::Get::Download",true) == true)
1109 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
1110 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
1111 if (errno
== EOVERFLOW
)
1112 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
1115 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
1117 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1120 if (statfs(OutputDir
.c_str(),&Stat
) != 0
1121 #if HAVE_STRUCT_STATFS_F_TYPE
1122 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
1125 return _error
->Error(_("You don't have enough free space in %s."),
1131 if (_config
->FindI("quiet",0) >= 2 ||
1132 _config
->FindB("APT::Get::Assume-Yes",false) == true)
1134 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
1135 return _error
->Error(_("There are problems and -y was used without --force-yes"));
1138 if (Essential
== true && Safety
== true)
1140 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
1141 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
1143 const char *Prompt
= _("Yes, do as I say!");
1145 _("You are about to do something potentially harmful.\n"
1146 "To continue type in the phrase '%s'\n"
1149 if (AnalPrompt(Prompt
) == false)
1151 c2out
<< _("Abort.") << endl
;
1157 // Prompt to continue
1158 if (Ask
== true || Fail
== true)
1160 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
1161 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
1163 if (_config
->FindI("quiet",0) < 2 &&
1164 _config
->FindB("APT::Get::Assume-Yes",false) == false)
1166 c2out
<< _("Do you want to continue [Y/n]? ") << flush
;
1168 if (YnPrompt() == false)
1170 c2out
<< _("Abort.") << endl
;
1177 // Just print out the uris an exit if the --print-uris flag was used
1178 if (_config
->FindB("APT::Get::Print-URIs") == true)
1180 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1181 for (; I
!= Fetcher
.UriEnd(); I
++)
1182 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1183 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
1187 if (!CheckAuth(Fetcher
))
1190 /* Unlock the dpkg lock if we are not going to be doing an install
1192 if (_config
->FindB("APT::Get::Download-Only",false) == true)
1198 bool Transient
= false;
1199 if (_config
->FindB("APT::Get::Download",true) == false)
1201 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
1203 if ((*I
)->Local
== true)
1209 // Close the item and check if it was found in cache
1211 if ((*I
)->Complete
== false)
1214 // Clear it out of the fetch list
1216 I
= Fetcher
.ItemsBegin();
1220 if (Fetcher
.Run() == pkgAcquire::Failed
)
1224 bool Failed
= false;
1225 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1227 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1228 (*I
)->Complete
== true)
1231 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
1238 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1239 (*I
)->ErrorText
.c_str());
1243 /* If we are in no download mode and missing files and there were
1244 'failures' then the user must specify -m. Furthermore, there
1245 is no such thing as a transient error in no-download mode! */
1246 if (Transient
== true &&
1247 _config
->FindB("APT::Get::Download",true) == false)
1253 if (_config
->FindB("APT::Get::Download-Only",false) == true)
1255 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
1256 return _error
->Error(_("Some files failed to download"));
1257 c1out
<< _("Download complete and in download only mode") << endl
;
1261 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
1263 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
1266 if (Transient
== true && Failed
== true)
1267 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
1269 // Try to deal with missing package files
1270 if (Failed
== true && PM
->FixMissing() == false)
1272 cerr
<< _("Unable to correct missing packages.") << endl
;
1273 return _error
->Error(_("Aborting install."));
1277 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
1278 pkgPackageManager::OrderResult Res
= PM
->DoInstall(status_fd
);
1279 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
1281 if (Res
== pkgPackageManager::Completed
)
1284 // Reload the fetcher object and loop again for media swapping
1286 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false)
1292 std::set
<std::string
> const disappearedPkgs
= PM
->GetDisappearedPackages();
1293 if (disappearedPkgs
.empty() == true)
1297 for (std::set
<std::string
>::const_iterator d
= disappearedPkgs
.begin();
1298 d
!= disappearedPkgs
.end(); ++d
)
1299 disappear
.append(*d
).append(" ");
1301 ShowList(c1out
, P_("The following package disappeared from your system as\n"
1302 "all files have been overwritten by other packages:",
1303 "The following packages disappeared from your system as\n"
1304 "all files have been overwritten by other packages:", disappearedPkgs
.size()), disappear
, "");
1305 c0out
<< _("Note: This is done automatic and on purpose by dpkg.") << std::endl
;
1310 // TryToInstallBuildDep - Try to install a single package /*{{{*/
1311 // ---------------------------------------------------------------------
1312 /* This used to be inlined in DoInstall, but with the advent of regex package
1313 name matching it was split out.. */
1314 bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg
,pkgCacheFile
&Cache
,
1315 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
1316 bool AllowFail
= true)
1318 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0)
1320 CacheSetHelperAPTGet
helper(c1out
);
1321 helper
.showErrors(AllowFail
== false);
1322 pkgCache::VerIterator Ver
= helper
.canNotFindNewestVer(Cache
, Pkg
);
1323 if (Ver
.end() == false)
1324 Pkg
= Ver
.ParentPkg();
1325 else if (helper
.showVirtualPackageErrors(Cache
) == false)
1331 TryToRemove
RemoveAction(Cache
, Fix
);
1332 RemoveAction(Pkg
.VersionList());
1333 } else if (Cache
[Pkg
].CandidateVer
!= 0) {
1334 TryToInstall
InstallAction(Cache
, Fix
, BrokenFix
);
1335 InstallAction(Cache
[Pkg
].CandidateVerIter(Cache
));
1342 // FindSrc - Find a source record /*{{{*/
1343 // ---------------------------------------------------------------------
1345 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
1346 pkgSrcRecords
&SrcRecs
,string
&Src
,
1350 string DefRel
= _config
->Find("APT::Default-Release");
1351 string TmpSrc
= Name
;
1353 // extract the version/release from the pkgname
1354 const size_t found
= TmpSrc
.find_last_of("/=");
1355 if (found
!= string::npos
) {
1356 if (TmpSrc
[found
] == '/')
1357 DefRel
= TmpSrc
.substr(found
+1);
1359 VerTag
= TmpSrc
.substr(found
+1);
1360 TmpSrc
= TmpSrc
.substr(0,found
);
1363 /* Lookup the version of the package we would install if we were to
1364 install a version and determine the source package name, then look
1365 in the archive for a source package of the same name. */
1366 bool MatchSrcOnly
= _config
->FindB("APT::Get::Only-Source");
1367 const pkgCache::PkgIterator Pkg
= Cache
.FindPkg(TmpSrc
);
1368 if (MatchSrcOnly
== false && Pkg
.end() == false)
1370 if(VerTag
.empty() == false || DefRel
.empty() == false)
1373 // we have a default release, try to locate the pkg. we do it like
1374 // this because GetCandidateVer() will not "downgrade", that means
1375 // "apt-get source -t stable apt" won't work on a unstable system
1376 for (pkgCache::VerIterator Ver
= Pkg
.VersionList();; Ver
++)
1378 // try first only exact matches, later fuzzy matches
1379 if (Ver
.end() == true)
1384 Ver
= Pkg
.VersionList();
1385 // exit right away from the Pkg.VersionList() loop if we
1386 // don't have any versions
1387 if (Ver
.end() == true)
1390 // We match against a concrete version (or a part of this version)
1391 if (VerTag
.empty() == false &&
1392 (fuzzy
== true || Cache
.VS().CmpVersion(VerTag
, Ver
.VerStr()) != 0) && // exact match
1393 (fuzzy
== false || strncmp(VerTag
.c_str(), Ver
.VerStr(), VerTag
.size()) != 0)) // fuzzy match
1396 for (pkgCache::VerFileIterator VF
= Ver
.FileList();
1397 VF
.end() == false; VF
++)
1399 /* If this is the status file, and the current version is not the
1400 version in the status file (ie it is not installed, or somesuch)
1401 then it is not a candidate for installation, ever. This weeds
1402 out bogus entries that may be due to config-file states, or
1404 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) ==
1405 pkgCache::Flag::NotSource
&& Pkg
.CurrentVer() != Ver
)
1408 // or we match against a release
1409 if(VerTag
.empty() == false ||
1410 (VF
.File().Archive() != 0 && VF
.File().Archive() == DefRel
) ||
1411 (VF
.File().Codename() != 0 && VF
.File().Codename() == DefRel
))
1413 pkgRecords::Parser
&Parse
= Recs
.Lookup(VF
);
1414 Src
= Parse
.SourcePkg();
1415 // no SourcePkg name, so it is the "binary" name
1416 if (Src
.empty() == true)
1418 // the Version we have is possibly fuzzy or includes binUploads,
1419 // so we use the Version of the SourcePkg (empty if same as package)
1420 VerTag
= Parse
.SourceVer();
1421 if (VerTag
.empty() == true)
1422 VerTag
= Ver
.VerStr();
1426 if (Src
.empty() == false)
1429 if (Src
.empty() == true)
1431 // Sources files have no codename information
1432 if (VerTag
.empty() == true && DefRel
.empty() == false)
1434 _error
->Error(_("Ignore unavailable target release '%s' of package '%s'"), DefRel
.c_str(), TmpSrc
.c_str());
1439 if (Src
.empty() == true)
1441 // if we don't have found a fitting package yet so we will
1442 // choose a good candidate and proceed with that.
1443 // Maybe we will find a source later on with the right VerTag
1444 pkgCache::VerIterator Ver
= Cache
.GetCandidateVer(Pkg
);
1445 if (Ver
.end() == false)
1447 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1448 Src
= Parse
.SourcePkg();
1449 if (VerTag
.empty() == true)
1450 VerTag
= Parse
.SourceVer();
1455 if (Src
.empty() == true)
1459 /* if we have a source pkg name, make sure to only search
1460 for srcpkg names, otherwise apt gets confused if there
1461 is a binary package "pkg1" and a source package "pkg1"
1462 with the same name but that comes from different packages */
1463 MatchSrcOnly
= true;
1466 ioprintf(c1out
, _("Picking '%s' as source package instead of '%s'\n"), Src
.c_str(), TmpSrc
.c_str());
1471 pkgSrcRecords::Parser
*Last
= 0;
1472 unsigned long Offset
= 0;
1475 /* Iterate over all of the hits, which includes the resulting
1476 binary packages in the search */
1477 pkgSrcRecords::Parser
*Parse
;
1481 while ((Parse
= SrcRecs
.Find(Src
.c_str(), MatchSrcOnly
)) != 0)
1483 const string Ver
= Parse
->Version();
1485 // Ignore all versions which doesn't fit
1486 if (VerTag
.empty() == false &&
1487 Cache
.VS().CmpVersion(VerTag
, Ver
) != 0) // exact match
1490 // Newer version or an exact match? Save the hit
1491 if (Last
== 0 || Cache
.VS().CmpVersion(Version
,Ver
) < 0) {
1493 Offset
= Parse
->Offset();
1497 // was the version check above an exact match? If so, we don't need to look further
1498 if (VerTag
.empty() == false && VerTag
.size() == Ver
.size())
1501 if (Last
!= 0 || VerTag
.empty() == true)
1503 //if (VerTag.empty() == false && Last == 0)
1504 _error
->Error(_("Ignore unavailable version '%s' of package '%s'"), VerTag
.c_str(), TmpSrc
.c_str());
1508 if (Last
== 0 || Last
->Jump(Offset
) == false)
1514 // DoUpdate - Update the package lists /*{{{*/
1515 // ---------------------------------------------------------------------
1517 bool DoUpdate(CommandLine
&CmdL
)
1519 if (CmdL
.FileSize() != 1)
1520 return _error
->Error(_("The update command takes no arguments"));
1522 // Get the source list
1524 if (List
.ReadMainList() == false)
1527 // Create the progress
1528 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1530 // Just print out the uris an exit if the --print-uris flag was used
1531 if (_config
->FindB("APT::Get::Print-URIs") == true)
1533 // force a hashsum for compatibility reasons
1534 _config
->CndSet("Acquire::ForceHash", "md5sum");
1538 if (Fetcher
.Setup(&Stat
) == false)
1541 // Populate it with the source selection and get all Indexes
1543 if (List
.GetIndexes(&Fetcher
,true) == false)
1546 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1547 for (; I
!= Fetcher
.UriEnd(); I
++)
1548 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1549 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
1555 if (_config
->FindB("APT::Get::Download",true) == true)
1556 ListUpdate(Stat
, List
);
1558 // Rebuild the cache.
1559 if (Cache
.BuildCaches() == false)
1565 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
1566 // ---------------------------------------------------------------------
1567 /* Remove unused automatic packages */
1568 bool DoAutomaticRemove(CacheFile
&Cache
)
1570 bool Debug
= _config
->FindI("Debug::pkgAutoRemove",false);
1571 bool doAutoRemove
= _config
->FindB("APT::Get::AutomaticRemove", false);
1572 bool hideAutoRemove
= _config
->FindB("APT::Get::HideAutoRemove");
1574 pkgDepCache::ActionGroup
group(*Cache
);
1576 std::cout
<< "DoAutomaticRemove()" << std::endl
;
1578 // we don't want to autoremove and we don't want to see it, so why calculating?
1579 if (doAutoRemove
== false && hideAutoRemove
== true)
1582 if (doAutoRemove
== true &&
1583 _config
->FindB("APT::Get::Remove",true) == false)
1585 c1out
<< _("We are not supposed to delete stuff, can't start "
1586 "AutoRemover") << std::endl
;
1590 bool purgePkgs
= _config
->FindB("APT::Get::Purge", false);
1591 bool smallList
= (hideAutoRemove
== false &&
1592 strcasecmp(_config
->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
1594 string autoremovelist
, autoremoveversions
;
1595 unsigned long autoRemoveCount
= 0;
1596 // look over the cache to see what can be removed
1597 for (pkgCache::PkgIterator Pkg
= Cache
->PkgBegin(); ! Pkg
.end(); ++Pkg
)
1599 if (Cache
[Pkg
].Garbage
)
1601 if(Pkg
.CurrentVer() != 0 || Cache
[Pkg
].Install())
1603 std::cout
<< "We could delete %s" << Pkg
.FullName(true).c_str() << std::endl
;
1607 if(Pkg
.CurrentVer() != 0 &&
1608 Pkg
->CurrentState
!= pkgCache::State::ConfigFiles
)
1609 Cache
->MarkDelete(Pkg
, purgePkgs
);
1611 Cache
->MarkKeep(Pkg
, false, false);
1615 // only show stuff in the list that is not yet marked for removal
1616 if(Cache
[Pkg
].Delete() == false)
1619 // we don't need to fill the strings if we don't need them
1620 if (smallList
== false)
1622 autoremovelist
+= Pkg
.FullName(true) + " ";
1623 autoremoveversions
+= string(Cache
[Pkg
].CandVersion
) + "\n";
1629 // if we don't remove them, we should show them!
1630 if (doAutoRemove
== false && (autoremovelist
.empty() == false || autoRemoveCount
!= 0))
1632 if (smallList
== false)
1633 ShowList(c1out
, P_("The following package is automatically installed and is no longer required:",
1634 "The following packages were automatically installed and are no longer required:",
1635 autoRemoveCount
), autoremovelist
, autoremoveversions
);
1637 ioprintf(c1out
, P_("%lu package was automatically installed and is no longer required.\n",
1638 "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount
), autoRemoveCount
);
1639 c1out
<< _("Use 'apt-get autoremove' to remove them.") << std::endl
;
1641 // Now see if we had destroyed anything (if we had done anything)
1642 else if (Cache
->BrokenCount() != 0)
1644 c1out
<< _("Hmm, seems like the AutoRemover destroyed something which really\n"
1645 "shouldn't happen. Please file a bug report against apt.") << endl
;
1647 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1649 ShowBroken(c1out
,Cache
,false);
1651 return _error
->Error(_("Internal Error, AutoRemover broke stuff"));
1656 // DoUpgrade - Upgrade all packages /*{{{*/
1657 // ---------------------------------------------------------------------
1658 /* Upgrade all packages without installing new packages or erasing old
1660 bool DoUpgrade(CommandLine
&CmdL
)
1663 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1667 if (pkgAllUpgrade(Cache
) == false)
1669 ShowBroken(c1out
,Cache
,false);
1670 return _error
->Error(_("Internal error, AllUpgrade broke stuff"));
1673 return InstallPackages(Cache
,true);
1676 // DoInstall - Install packages from the command line /*{{{*/
1677 // ---------------------------------------------------------------------
1678 /* Install named packages */
1679 bool DoInstall(CommandLine
&CmdL
)
1682 if (Cache
.OpenForInstall() == false ||
1683 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
1686 // Enter the special broken fixing mode if the user specified arguments
1687 bool BrokenFix
= false;
1688 if (Cache
->BrokenCount() != 0)
1691 pkgProblemResolver
Fix(Cache
);
1693 static const unsigned short MOD_REMOVE
= 1;
1694 static const unsigned short MOD_INSTALL
= 2;
1696 unsigned short fallback
= MOD_INSTALL
;
1697 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
1698 fallback
= MOD_REMOVE
;
1699 else if (strcasecmp(CmdL
.FileList
[0], "purge") == 0)
1701 _config
->Set("APT::Get::Purge", true);
1702 fallback
= MOD_REMOVE
;
1704 else if (strcasecmp(CmdL
.FileList
[0], "autoremove") == 0)
1706 _config
->Set("APT::Get::AutomaticRemove", "true");
1707 fallback
= MOD_REMOVE
;
1710 std::list
<APT::VersionSet::Modifier
> mods
;
1711 mods
.push_back(APT::VersionSet::Modifier(MOD_INSTALL
, "+",
1712 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::CANDIDATE
));
1713 mods
.push_back(APT::VersionSet::Modifier(MOD_REMOVE
, "-",
1714 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::NEWEST
));
1715 CacheSetHelperAPTGet
helper(c0out
);
1716 std::map
<unsigned short, APT::VersionSet
> verset
= APT::VersionSet::GroupedFromCommandLine(Cache
,
1717 CmdL
.FileList
+ 1, mods
, fallback
, helper
);
1719 if (_error
->PendingError() == true)
1721 helper
.showVirtualPackageErrors(Cache
);
1725 unsigned short order
[] = { 0, 0, 0 };
1726 if (fallback
== MOD_INSTALL
) {
1727 order
[0] = MOD_INSTALL
;
1728 order
[1] = MOD_REMOVE
;
1730 order
[0] = MOD_REMOVE
;
1731 order
[1] = MOD_INSTALL
;
1734 TryToInstall
InstallAction(Cache
, Fix
, BrokenFix
);
1735 TryToRemove
RemoveAction(Cache
, Fix
);
1737 // new scope for the ActionGroup
1739 pkgDepCache::ActionGroup
group(Cache
);
1741 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
1743 if (order
[i
] == MOD_INSTALL
)
1744 InstallAction
= std::for_each(verset
[MOD_INSTALL
].begin(), verset
[MOD_INSTALL
].end(), InstallAction
);
1745 else if (order
[i
] == MOD_REMOVE
)
1746 RemoveAction
= std::for_each(verset
[MOD_REMOVE
].begin(), verset
[MOD_REMOVE
].end(), RemoveAction
);
1749 if (_error
->PendingError() == true)
1752 /* If we are in the Broken fixing mode we do not attempt to fix the
1753 problems. This is if the user invoked install without -f and gave
1755 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1757 c1out
<< _("You might want to run 'apt-get -f install' to correct these:") << endl
;
1758 ShowBroken(c1out
,Cache
,false);
1760 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1763 // Call the scored problem resolver
1764 Fix
.InstallProtect();
1765 if (Fix
.Resolve(true) == false)
1768 // Now we check the state of the packages,
1769 if (Cache
->BrokenCount() != 0)
1772 _("Some packages could not be installed. This may mean that you have\n"
1773 "requested an impossible situation or if you are using the unstable\n"
1774 "distribution that some required packages have not yet been created\n"
1775 "or been moved out of Incoming.") << endl
;
1781 _("Since you only requested a single operation it is extremely likely that\n"
1782 "the package is simply not installable and a bug report against\n"
1783 "that package should be filed.") << endl;
1787 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1789 ShowBroken(c1out
,Cache
,false);
1790 return _error
->Error(_("Broken packages"));
1793 if (!DoAutomaticRemove(Cache
))
1796 /* Print out a list of packages that are going to be installed extra
1797 to what the user asked */
1798 if (Cache
->InstCount() != verset
[MOD_INSTALL
].size())
1801 string VersionsList
;
1802 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1804 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1805 if ((*Cache
)[I
].Install() == false)
1809 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1810 if (strcmp(*J
,I
.Name()) == 0)
1814 List
+= I
.FullName(true) + " ";
1815 VersionsList
+= string(Cache
[I
].CandVersion
) + "\n";
1819 ShowList(c1out
,_("The following extra packages will be installed:"),List
,VersionsList
);
1822 /* Print out a list of suggested and recommended packages */
1824 string SuggestsList
, RecommendsList
, List
;
1825 string SuggestsVersions
, RecommendsVersions
;
1826 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1828 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
1830 /* Just look at the ones we want to install */
1831 if ((*Cache
)[Pkg
].Install() == false)
1834 // get the recommends/suggests for the candidate ver
1835 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1836 for (pkgCache::DepIterator D
= CV
.DependsList(); D
.end() == false; )
1838 pkgCache::DepIterator Start
;
1839 pkgCache::DepIterator End
;
1840 D
.GlobOr(Start
,End
); // advances D
1842 // FIXME: we really should display a or-group as a or-group to the user
1843 // the problem is that ShowList is incapable of doing this
1844 string RecommendsOrList
,RecommendsOrVersions
;
1845 string SuggestsOrList
,SuggestsOrVersions
;
1846 bool foundInstalledInOrGroup
= false;
1849 /* Skip if package is installed already, or is about to be */
1850 string target
= Start
.TargetPkg().FullName(true) + " ";
1851 pkgCache::PkgIterator
const TarPkg
= Start
.TargetPkg();
1852 if (TarPkg
->SelectedState
== pkgCache::State::Install
||
1853 TarPkg
->SelectedState
== pkgCache::State::Hold
||
1854 Cache
[Start
.TargetPkg()].Install())
1856 foundInstalledInOrGroup
=true;
1860 /* Skip if we already saw it */
1861 if (int(SuggestsList
.find(target
)) != -1 || int(RecommendsList
.find(target
)) != -1)
1863 foundInstalledInOrGroup
=true;
1867 // this is a dep on a virtual pkg, check if any package that provides it
1868 // should be installed
1869 if(Start
.TargetPkg().ProvidesList() != 0)
1871 pkgCache::PrvIterator I
= Start
.TargetPkg().ProvidesList();
1872 for (; I
.end() == false; I
++)
1874 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
1875 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer() &&
1876 Pkg
.CurrentVer() != 0)
1877 foundInstalledInOrGroup
=true;
1881 if (Start
->Type
== pkgCache::Dep::Suggests
)
1883 SuggestsOrList
+= target
;
1884 SuggestsOrVersions
+= string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
1887 if (Start
->Type
== pkgCache::Dep::Recommends
)
1889 RecommendsOrList
+= target
;
1890 RecommendsOrVersions
+= string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
1898 if(foundInstalledInOrGroup
== false)
1900 RecommendsList
+= RecommendsOrList
;
1901 RecommendsVersions
+= RecommendsOrVersions
;
1902 SuggestsList
+= SuggestsOrList
;
1903 SuggestsVersions
+= SuggestsOrVersions
;
1909 ShowList(c1out
,_("Suggested packages:"),SuggestsList
,SuggestsVersions
);
1910 ShowList(c1out
,_("Recommended packages:"),RecommendsList
,RecommendsVersions
);
1914 // if nothing changed in the cache, but only the automark information
1915 // we write the StateFile here, otherwise it will be written in
1917 if (InstallAction
.AutoMarkChanged
> 0 &&
1918 Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
1919 Cache
->BadCount() == 0 &&
1920 _config
->FindB("APT::Get::Simulate",false) == false)
1921 Cache
->writeStateFile(NULL
);
1923 // See if we need to prompt
1924 // FIXME: check if really the packages in the set are going to be installed
1925 if (Cache
->InstCount() == verset
[MOD_INSTALL
].size() && Cache
->DelCount() == 0)
1926 return InstallPackages(Cache
,false,false);
1928 return InstallPackages(Cache
,false);
1931 /* mark packages as automatically/manually installed. */
1932 bool DoMarkAuto(CommandLine
&CmdL
)
1935 int AutoMarkChanged
= 0;
1936 OpTextProgress progress
;
1938 if (Cache
.Open() == false)
1941 if (strcasecmp(CmdL
.FileList
[0],"markauto") == 0)
1943 else if (strcasecmp(CmdL
.FileList
[0],"unmarkauto") == 0)
1946 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1949 // Locate the package
1950 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
1951 if (Pkg
.end() == true) {
1952 return _error
->Error(_("Couldn't find package %s"),S
);
1957 ioprintf(c1out
,_("%s set to manually installed.\n"), Pkg
.Name());
1959 ioprintf(c1out
,_("%s set to automatically installed.\n"),
1962 Cache
->MarkAuto(Pkg
,Action
);
1966 if (AutoMarkChanged
&& ! _config
->FindB("APT::Get::Simulate",false))
1967 return Cache
->writeStateFile(NULL
);
1971 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1972 // ---------------------------------------------------------------------
1973 /* Intelligent upgrader that will install and remove packages at will */
1974 bool DoDistUpgrade(CommandLine
&CmdL
)
1977 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1980 c0out
<< _("Calculating upgrade... ") << flush
;
1981 if (pkgDistUpgrade(*Cache
) == false)
1983 c0out
<< _("Failed") << endl
;
1984 ShowBroken(c1out
,Cache
,false);
1988 c0out
<< _("Done") << endl
;
1990 return InstallPackages(Cache
,true);
1993 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1994 // ---------------------------------------------------------------------
1995 /* Follows dselect's selections */
1996 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1999 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
2002 pkgDepCache::ActionGroup
group(Cache
);
2004 // Install everything with the install flag set
2005 pkgCache::PkgIterator I
= Cache
->PkgBegin();
2006 for (;I
.end() != true; I
++)
2008 /* Install the package only if it is a new install, the autoupgrader
2009 will deal with the rest */
2010 if (I
->SelectedState
== pkgCache::State::Install
)
2011 Cache
->MarkInstall(I
,false);
2014 /* Now install their deps too, if we do this above then order of
2015 the status file is significant for | groups */
2016 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
2018 /* Install the package only if it is a new install, the autoupgrader
2019 will deal with the rest */
2020 if (I
->SelectedState
== pkgCache::State::Install
)
2021 Cache
->MarkInstall(I
,true);
2024 // Apply erasures now, they override everything else.
2025 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
2028 if (I
->SelectedState
== pkgCache::State::DeInstall
||
2029 I
->SelectedState
== pkgCache::State::Purge
)
2030 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
2033 /* Resolve any problems that dselect created, allupgrade cannot handle
2034 such things. We do so quite agressively too.. */
2035 if (Cache
->BrokenCount() != 0)
2037 pkgProblemResolver
Fix(Cache
);
2039 // Hold back held packages.
2040 if (_config
->FindB("APT::Ignore-Hold",false) == false)
2042 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
2044 if (I
->SelectedState
== pkgCache::State::Hold
)
2052 if (Fix
.Resolve() == false)
2054 ShowBroken(c1out
,Cache
,false);
2055 return _error
->Error(_("Internal error, problem resolver broke stuff"));
2059 // Now upgrade everything
2060 if (pkgAllUpgrade(Cache
) == false)
2062 ShowBroken(c1out
,Cache
,false);
2063 return _error
->Error(_("Internal error, problem resolver broke stuff"));
2066 return InstallPackages(Cache
,false);
2069 // DoClean - Remove download archives /*{{{*/
2070 // ---------------------------------------------------------------------
2072 bool DoClean(CommandLine
&CmdL
)
2074 if (_config
->FindB("APT::Get::Simulate") == true)
2076 cout
<< "Del " << _config
->FindDir("Dir::Cache::archives") << "* " <<
2077 _config
->FindDir("Dir::Cache::archives") << "partial/*" << endl
;
2081 // Lock the archive directory
2083 if (_config
->FindB("Debug::NoLocking",false) == false)
2085 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
2086 if (_error
->PendingError() == true)
2087 return _error
->Error(_("Unable to lock the download directory"));
2091 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
2092 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
2096 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
2097 // ---------------------------------------------------------------------
2098 /* This is similar to clean but it only purges things that cannot be
2099 downloaded, that is old versions of cached packages. */
2100 class LogCleaner
: public pkgArchiveCleaner
2103 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
2105 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
2107 if (_config
->FindB("APT::Get::Simulate") == false)
2112 bool DoAutoClean(CommandLine
&CmdL
)
2114 // Lock the archive directory
2116 if (_config
->FindB("Debug::NoLocking",false) == false)
2118 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
2119 if (_error
->PendingError() == true)
2120 return _error
->Error(_("Unable to lock the download directory"));
2124 if (Cache
.Open() == false)
2129 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
2130 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
2133 // DoCheck - Perform the check operation /*{{{*/
2134 // ---------------------------------------------------------------------
2135 /* Opening automatically checks the system, this command is mostly used
2137 bool DoCheck(CommandLine
&CmdL
)
2146 // DoSource - Fetch a source archive /*{{{*/
2147 // ---------------------------------------------------------------------
2148 /* Fetch souce packages */
2156 bool DoSource(CommandLine
&CmdL
)
2159 if (Cache
.Open(false) == false)
2162 if (CmdL
.FileSize() <= 1)
2163 return _error
->Error(_("Must specify at least one package to fetch source for"));
2165 // Read the source list
2167 if (List
.ReadMainList() == false)
2168 return _error
->Error(_("The list of sources could not be read."));
2170 // Create the text record parsers
2171 pkgRecords
Recs(Cache
);
2172 pkgSrcRecords
SrcRecs(List
);
2173 if (_error
->PendingError() == true)
2176 // Create the download object
2177 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
2179 if (Fetcher
.Setup(&Stat
) == false)
2182 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
2184 // insert all downloaded uris into this set to avoid downloading them
2188 // Diff only mode only fetches .diff files
2189 bool const diffOnly
= _config
->FindB("APT::Get::Diff-Only", false);
2190 // Tar only mode only fetches .tar files
2191 bool const tarOnly
= _config
->FindB("APT::Get::Tar-Only", false);
2192 // Dsc only mode only fetches .dsc files
2193 bool const dscOnly
= _config
->FindB("APT::Get::Dsc-Only", false);
2195 // Load the requestd sources into the fetcher
2197 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
2200 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
2203 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
2205 string srec
= Last
->AsStr();
2206 string::size_type pos
= srec
.find("\nVcs-");
2207 while (pos
!= string::npos
)
2209 pos
+= strlen("\nVcs-");
2210 string vcs
= srec
.substr(pos
,srec
.find(":",pos
)-pos
);
2211 if(vcs
== "Browser")
2213 pos
= srec
.find("\nVcs-", pos
);
2216 pos
+= vcs
.length()+2;
2217 string::size_type epos
= srec
.find("\n", pos
);
2218 string uri
= srec
.substr(pos
,epos
-pos
).c_str();
2219 ioprintf(c1out
, _("NOTICE: '%s' packaging is maintained in "
2220 "the '%s' version control system at:\n"
2222 Src
.c_str(), vcs
.c_str(), uri
.c_str());
2224 ioprintf(c1out
,_("Please use:\n"
2226 "to retrieve the latest (possibly unreleased) "
2227 "updates to the package.\n"),
2233 vector
<pkgSrcRecords::File
> Lst
;
2234 if (Last
->Files(Lst
) == false)
2237 // Load them into the fetcher
2238 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
2239 I
!= Lst
.end(); I
++)
2241 // Try to guess what sort of file it is we are getting.
2242 if (I
->Type
== "dsc")
2244 Dsc
[J
].Package
= Last
->Package();
2245 Dsc
[J
].Version
= Last
->Version();
2246 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
2249 // Handle the only options so that multiple can be used at once
2250 if (diffOnly
== true || tarOnly
== true || dscOnly
== true)
2252 if ((diffOnly
== true && I
->Type
== "diff") ||
2253 (tarOnly
== true && I
->Type
== "tar") ||
2254 (dscOnly
== true && I
->Type
== "dsc"))
2255 ; // Fine, we want this file downloaded
2260 // don't download the same uri twice (should this be moved to
2261 // the fetcher interface itself?)
2262 if(queued
.find(Last
->Index().ArchiveURI(I
->Path
)) != queued
.end())
2264 queued
.insert(Last
->Index().ArchiveURI(I
->Path
));
2266 // check if we have a file with that md5 sum already localy
2267 if(!I
->MD5Hash
.empty() && FileExists(flNotDir(I
->Path
)))
2269 FileFd
Fd(flNotDir(I
->Path
), FileFd::ReadOnly
);
2271 sum
.AddFD(Fd
.Fd(), Fd
.Size());
2273 if((string
)sum
.Result() == I
->MD5Hash
)
2275 ioprintf(c1out
,_("Skipping already downloaded file '%s'\n"),
2276 flNotDir(I
->Path
).c_str());
2281 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
2283 Last
->Index().SourceInfo(*Last
,*I
),Src
);
2287 // Display statistics
2288 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
2289 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
2290 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
2292 // Check for enough free space
2294 string OutputDir
= ".";
2295 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
2296 if (errno
== EOVERFLOW
)
2297 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
2300 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
2302 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
2305 if (statfs(OutputDir
.c_str(),&Stat
) != 0
2306 #if HAVE_STRUCT_STATFS_F_TYPE
2307 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
2310 return _error
->Error(_("You don't have enough free space in %s"),
2315 if (DebBytes
!= FetchBytes
)
2316 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
2317 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
2319 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
2320 SizeToStr(DebBytes
).c_str());
2322 if (_config
->FindB("APT::Get::Simulate",false) == true)
2324 for (unsigned I
= 0; I
!= J
; I
++)
2325 ioprintf(cout
,_("Fetch source %s\n"),Dsc
[I
].Package
.c_str());
2330 // Just print out the uris an exit if the --print-uris flag was used
2331 if (_config
->FindB("APT::Get::Print-URIs") == true)
2333 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
2334 for (; I
!= Fetcher
.UriEnd(); I
++)
2335 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
2336 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
2342 if (Fetcher
.Run() == pkgAcquire::Failed
)
2345 // Print error messages
2346 bool Failed
= false;
2347 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
2349 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
2350 (*I
)->Complete
== true)
2353 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
2354 (*I
)->ErrorText
.c_str());
2358 return _error
->Error(_("Failed to fetch some archives."));
2360 if (_config
->FindB("APT::Get::Download-only",false) == true)
2362 c1out
<< _("Download complete and in download only mode") << endl
;
2367 // Unpack the sources
2368 pid_t Process
= ExecFork();
2372 bool const fixBroken
= _config
->FindB("APT::Get::Fix-Broken", false);
2373 for (unsigned I
= 0; I
!= J
; I
++)
2375 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
2377 // Diff only mode only fetches .diff files
2378 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
2379 _config
->FindB("APT::Get::Tar-Only",false) == true ||
2380 Dsc
[I
].Dsc
.empty() == true)
2383 // See if the package is already unpacked
2385 if (fixBroken
== false && stat(Dir
.c_str(),&Stat
) == 0 &&
2386 S_ISDIR(Stat
.st_mode
) != 0)
2388 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
2395 snprintf(S
,sizeof(S
),"%s -x %s",
2396 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
2397 Dsc
[I
].Dsc
.c_str());
2400 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
2401 fprintf(stderr
,_("Check if the 'dpkg-dev' package is installed.\n"));
2406 // Try to compile it with dpkg-buildpackage
2407 if (_config
->FindB("APT::Get::Compile",false) == true)
2409 // Call dpkg-buildpackage
2411 snprintf(S
,sizeof(S
),"cd %s && %s %s",
2413 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
2414 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
2418 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
2428 // Wait for the subprocess
2430 while (waitpid(Process
,&Status
,0) != Process
)
2434 return _error
->Errno("waitpid","Couldn't wait for subprocess");
2437 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
2438 return _error
->Error(_("Child process failed"));
2443 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
2444 // ---------------------------------------------------------------------
2445 /* This function will look at the build depends list of the given source
2446 package and install the necessary packages to make it true, or fail. */
2447 bool DoBuildDep(CommandLine
&CmdL
)
2450 if (Cache
.Open(true) == false)
2453 if (CmdL
.FileSize() <= 1)
2454 return _error
->Error(_("Must specify at least one package to check builddeps for"));
2456 // Read the source list
2458 if (List
.ReadMainList() == false)
2459 return _error
->Error(_("The list of sources could not be read."));
2461 // Create the text record parsers
2462 pkgRecords
Recs(Cache
);
2463 pkgSrcRecords
SrcRecs(List
);
2464 if (_error
->PendingError() == true)
2467 // Create the download object
2468 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
2470 if (Fetcher
.Setup(&Stat
) == false)
2474 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
2477 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
2479 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
2481 // Process the build-dependencies
2482 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
2483 if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only",true)) == false)
2484 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
2486 // Also ensure that build-essential packages are present
2487 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
2490 for (; Opts
; Opts
= Opts
->Next
)
2492 if (Opts
->Value
.empty() == true)
2495 pkgSrcRecords::Parser::BuildDepRec rec
;
2496 rec
.Package
= Opts
->Value
;
2497 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
2499 BuildDeps
.push_back(rec
);
2502 if (BuildDeps
.size() == 0)
2504 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
2508 // Install the requested packages
2509 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
2510 pkgProblemResolver
Fix(Cache
);
2511 bool skipAlternatives
= false; // skip remaining alternatives in an or group
2512 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); D
++)
2514 bool hasAlternatives
= (((*D
).Op
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
);
2516 if (skipAlternatives
== true)
2518 if (!hasAlternatives
)
2519 skipAlternatives
= false; // end of or group
2523 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
2524 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
2526 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
2527 // Build-conflicts on unknown packages are silently ignored
2528 if (Pkg
.end() == true)
2531 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
2534 * Remove if we have an installed version that satisfies the
2537 if (IV
.end() == false &&
2538 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2539 TryToInstallBuildDep(Pkg
,Cache
,Fix
,true,false);
2541 else // BuildDep || BuildDepIndep
2543 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
2544 if (_config
->FindB("Debug::BuildDeps",false) == true)
2545 cout
<< "Looking for " << (*D
).Package
<< "...\n";
2547 if (Pkg
.end() == true)
2549 if (_config
->FindB("Debug::BuildDeps",false) == true)
2550 cout
<< " (not found)" << (*D
).Package
<< endl
;
2552 if (hasAlternatives
)
2555 return _error
->Error(_("%s dependency for %s cannot be satisfied "
2556 "because the package %s cannot be found"),
2557 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
2558 (*D
).Package
.c_str());
2562 * if there are alternatives, we've already picked one, so skip
2565 * TODO: this means that if there's a build-dep on A|B and B is
2566 * installed, we'll still try to install A; more importantly,
2567 * if A is currently broken, we cannot go back and try B. To fix
2568 * this would require we do a Resolve cycle for each package we
2569 * add to the install list. Ugh
2573 * If this is a virtual package, we need to check the list of
2574 * packages that provide it and see if any of those are
2577 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
2578 for (; Prv
.end() != true; Prv
++)
2580 if (_config
->FindB("Debug::BuildDeps",false) == true)
2581 cout
<< " Checking provider " << Prv
.OwnerPkg().FullName() << endl
;
2583 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
2587 // Get installed version and version we are going to install
2588 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
2590 if ((*D
).Version
[0] != '\0') {
2591 // Versioned dependency
2593 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
2595 for (; CV
.end() != true; CV
++)
2597 if (Cache
->VS().CheckDep(CV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2600 if (CV
.end() == true)
2602 if (hasAlternatives
)
2608 return _error
->Error(_("%s dependency for %s cannot be satisfied "
2609 "because no available versions of package %s "
2610 "can satisfy version requirements"),
2611 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
2612 (*D
).Package
.c_str());
2618 // Only consider virtual packages if there is no versioned dependency
2619 if (Prv
.end() == false)
2621 if (_config
->FindB("Debug::BuildDeps",false) == true)
2622 cout
<< " Is provided by installed package " << Prv
.OwnerPkg().FullName() << endl
;
2623 skipAlternatives
= hasAlternatives
;
2628 if (IV
.end() == false)
2630 if (_config
->FindB("Debug::BuildDeps",false) == true)
2631 cout
<< " Is installed\n";
2633 if (Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2635 skipAlternatives
= hasAlternatives
;
2639 if (_config
->FindB("Debug::BuildDeps",false) == true)
2640 cout
<< " ...but the installed version doesn't meet the version requirement\n";
2642 if (((*D
).Op
& pkgCache::Dep::LessEq
) == pkgCache::Dep::LessEq
)
2644 return _error
->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
2645 Last
->BuildDepType((*D
).Type
),
2647 Pkg
.FullName(true).c_str());
2652 if (_config
->FindB("Debug::BuildDeps",false) == true)
2653 cout
<< " Trying to install " << (*D
).Package
<< endl
;
2655 if (TryToInstallBuildDep(Pkg
,Cache
,Fix
,false,false) == true)
2657 // We successfully installed something; skip remaining alternatives
2658 skipAlternatives
= hasAlternatives
;
2659 if(_config
->FindB("APT::Get::Build-Dep-Automatic", false) == true)
2660 Cache
->MarkAuto(Pkg
, true);
2663 else if (hasAlternatives
)
2665 if (_config
->FindB("Debug::BuildDeps",false) == true)
2666 cout
<< " Unsatisfiable, trying alternatives\n";
2671 return _error
->Error(_("Failed to satisfy %s dependency for %s: %s"),
2672 Last
->BuildDepType((*D
).Type
),
2674 (*D
).Package
.c_str());
2679 Fix
.InstallProtect();
2680 if (Fix
.Resolve(true) == false)
2683 // Now we check the state of the packages,
2684 if (Cache
->BrokenCount() != 0)
2686 ShowBroken(cout
, Cache
, false);
2687 return _error
->Error(_("Build-dependencies for %s could not be satisfied."),*I
);
2691 if (InstallPackages(Cache
, false, true) == false)
2692 return _error
->Error(_("Failed to process build dependencies"));
2696 // DoMoo - Never Ask, Never Tell /*{{{*/
2697 // ---------------------------------------------------------------------
2699 bool DoMoo(CommandLine
&CmdL
)
2708 "....\"Have you mooed today?\"...\n";
2713 // ShowHelp - Show a help screen /*{{{*/
2714 // ---------------------------------------------------------------------
2716 bool ShowHelp(CommandLine
&CmdL
)
2718 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,VERSION
,
2719 COMMON_ARCH
,__DATE__
,__TIME__
);
2721 if (_config
->FindB("version") == true)
2723 cout
<< _("Supported modules:") << endl
;
2725 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
2727 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
2728 if (_system
!= 0 && _system
->VS
== VS
)
2732 cout
<< "Ver: " << VS
->Label
<< endl
;
2734 /* Print out all the packaging systems that will work with
2736 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
2738 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
2743 if (Sys
->VS
->TestCompatibility(*VS
) == true)
2744 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
2748 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
2750 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
2751 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
2754 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
2756 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
2757 cout
<< " Idx: " << Type
->Label
<< endl
;
2764 _("Usage: apt-get [options] command\n"
2765 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
2766 " apt-get [options] source pkg1 [pkg2 ...]\n"
2768 "apt-get is a simple command line interface for downloading and\n"
2769 "installing packages. The most frequently used commands are update\n"
2773 " update - Retrieve new lists of packages\n"
2774 " upgrade - Perform an upgrade\n"
2775 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
2776 " remove - Remove packages\n"
2777 " autoremove - Remove automatically all unused packages\n"
2778 " purge - Remove packages and config files\n"
2779 " source - Download source archives\n"
2780 " build-dep - Configure build-dependencies for source packages\n"
2781 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
2782 " dselect-upgrade - Follow dselect selections\n"
2783 " clean - Erase downloaded archive files\n"
2784 " autoclean - Erase old downloaded archive files\n"
2785 " check - Verify that there are no broken dependencies\n"
2786 " markauto - Mark the given packages as automatically installed\n"
2787 " unmarkauto - Mark the given packages as manually installed\n"
2790 " -h This help text.\n"
2791 " -q Loggable output - no progress indicator\n"
2792 " -qq No output except for errors\n"
2793 " -d Download only - do NOT install or unpack archives\n"
2794 " -s No-act. Perform ordering simulation\n"
2795 " -y Assume Yes to all queries and do not prompt\n"
2796 " -f Attempt to correct a system with broken dependencies in place\n"
2797 " -m Attempt to continue if archives are unlocatable\n"
2798 " -u Show a list of upgraded packages as well\n"
2799 " -b Build the source package after fetching it\n"
2800 " -V Show verbose version numbers\n"
2801 " -c=? Read this configuration file\n"
2802 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
2803 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
2804 "pages for more information and options.\n"
2805 " This APT has Super Cow Powers.\n");
2809 // GetInitialize - Initialize things for apt-get /*{{{*/
2810 // ---------------------------------------------------------------------
2812 void GetInitialize()
2814 _config
->Set("quiet",0);
2815 _config
->Set("help",false);
2816 _config
->Set("APT::Get::Download-Only",false);
2817 _config
->Set("APT::Get::Simulate",false);
2818 _config
->Set("APT::Get::Assume-Yes",false);
2819 _config
->Set("APT::Get::Fix-Broken",false);
2820 _config
->Set("APT::Get::Force-Yes",false);
2821 _config
->Set("APT::Get::List-Cleanup",true);
2822 _config
->Set("APT::Get::AutomaticRemove",false);
2825 // SigWinch - Window size change signal handler /*{{{*/
2826 // ---------------------------------------------------------------------
2830 // Riped from GNU ls
2834 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
2835 ScreenWidth
= ws
.ws_col
- 1;
2839 int main(int argc
,const char *argv
[]) /*{{{*/
2841 CommandLine::Args Args
[] = {
2842 {'h',"help","help",0},
2843 {'v',"version","version",0},
2844 {'V',"verbose-versions","APT::Get::Show-Versions",0},
2845 {'q',"quiet","quiet",CommandLine::IntLevel
},
2846 {'q',"silent","quiet",CommandLine::IntLevel
},
2847 {'d',"download-only","APT::Get::Download-Only",0},
2848 {'b',"compile","APT::Get::Compile",0},
2849 {'b',"build","APT::Get::Compile",0},
2850 {'s',"simulate","APT::Get::Simulate",0},
2851 {'s',"just-print","APT::Get::Simulate",0},
2852 {'s',"recon","APT::Get::Simulate",0},
2853 {'s',"dry-run","APT::Get::Simulate",0},
2854 {'s',"no-act","APT::Get::Simulate",0},
2855 {'y',"yes","APT::Get::Assume-Yes",0},
2856 {'y',"assume-yes","APT::Get::Assume-Yes",0},
2857 {'f',"fix-broken","APT::Get::Fix-Broken",0},
2858 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
2859 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
2860 {'t',"target-release","APT::Default-Release",CommandLine::HasArg
},
2861 {'t',"default-release","APT::Default-Release",CommandLine::HasArg
},
2862 {0,"download","APT::Get::Download",0},
2863 {0,"fix-missing","APT::Get::Fix-Missing",0},
2864 {0,"ignore-hold","APT::Ignore-Hold",0},
2865 {0,"upgrade","APT::Get::upgrade",0},
2866 {0,"only-upgrade","APT::Get::Only-Upgrade",0},
2867 {0,"force-yes","APT::Get::force-yes",0},
2868 {0,"print-uris","APT::Get::Print-URIs",0},
2869 {0,"diff-only","APT::Get::Diff-Only",0},
2870 {0,"debian-only","APT::Get::Diff-Only",0},
2871 {0,"tar-only","APT::Get::Tar-Only",0},
2872 {0,"dsc-only","APT::Get::Dsc-Only",0},
2873 {0,"purge","APT::Get::Purge",0},
2874 {0,"list-cleanup","APT::Get::List-Cleanup",0},
2875 {0,"reinstall","APT::Get::ReInstall",0},
2876 {0,"trivial-only","APT::Get::Trivial-Only",0},
2877 {0,"remove","APT::Get::Remove",0},
2878 {0,"only-source","APT::Get::Only-Source",0},
2879 {0,"arch-only","APT::Get::Arch-Only",0},
2880 {0,"auto-remove","APT::Get::AutomaticRemove",0},
2881 {0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0},
2882 {0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean
},
2883 {0,"fix-policy","APT::Get::Fix-Policy-Broken",0},
2884 {'c',"config-file",0,CommandLine::ConfigFile
},
2885 {'o',"option",0,CommandLine::ArbItem
},
2887 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
2888 {"upgrade",&DoUpgrade
},
2889 {"install",&DoInstall
},
2890 {"remove",&DoInstall
},
2891 {"purge",&DoInstall
},
2892 {"autoremove",&DoInstall
},
2893 {"markauto",&DoMarkAuto
},
2894 {"unmarkauto",&DoMarkAuto
},
2895 {"dist-upgrade",&DoDistUpgrade
},
2896 {"dselect-upgrade",&DoDSelectUpgrade
},
2897 {"build-dep",&DoBuildDep
},
2899 {"autoclean",&DoAutoClean
},
2901 {"source",&DoSource
},
2906 // Set up gettext support
2907 setlocale(LC_ALL
,"");
2908 textdomain(PACKAGE
);
2910 // Parse the command line and initialize the package library
2911 CommandLine
CmdL(Args
,_config
);
2912 if (pkgInitConfig(*_config
) == false ||
2913 CmdL
.Parse(argc
,argv
) == false ||
2914 pkgInitSystem(*_config
,_system
) == false)
2916 if (_config
->FindB("version") == true)
2919 _error
->DumpErrors();
2923 // See if the help should be shown
2924 if (_config
->FindB("help") == true ||
2925 _config
->FindB("version") == true ||
2926 CmdL
.FileSize() == 0)
2932 // simulate user-friendly if apt-get has no root privileges
2933 if (getuid() != 0 && _config
->FindB("APT::Get::Simulate") == true)
2935 if (_config
->FindB("APT::Get::Show-User-Simulation-Note",true) == true)
2936 cout
<< _("NOTE: This is only a simulation!\n"
2937 " apt-get needs root privileges for real execution.\n"
2938 " Keep also in mind that locking is deactivated,\n"
2939 " so don't depend on the relevance to the real current situation!"
2941 _config
->Set("Debug::NoLocking",true);
2944 // Deal with stdout not being a tty
2945 if (!isatty(STDOUT_FILENO
) && _config
->FindI("quiet", -1) == -1)
2946 _config
->Set("quiet","1");
2948 // Setup the output streams
2949 c0out
.rdbuf(cout
.rdbuf());
2950 c1out
.rdbuf(cout
.rdbuf());
2951 c2out
.rdbuf(cout
.rdbuf());
2952 if (_config
->FindI("quiet",0) > 0)
2953 c0out
.rdbuf(devnull
.rdbuf());
2954 if (_config
->FindI("quiet",0) > 1)
2955 c1out
.rdbuf(devnull
.rdbuf());
2957 // Setup the signals
2958 signal(SIGPIPE
,SIG_IGN
);
2959 signal(SIGWINCH
,SigWinch
);
2962 // Match the operation
2963 CmdL
.DispatchArg(Cmds
);
2965 // Print any errors or warnings found during parsing
2966 bool const Errors
= _error
->PendingError();
2967 if (_config
->FindI("quiet",0) > 0)
2968 _error
->DumpErrors();
2970 _error
->DumpErrors(GlobalError::DEBUG
);
2971 return Errors
== true ? 100 : 0;