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/error.h>
32 #include <apt-pkg/cmndline.h>
33 #include <apt-pkg/init.h>
34 #include <apt-pkg/depcache.h>
35 #include <apt-pkg/sourcelist.h>
36 #include <apt-pkg/algorithms.h>
37 #include <apt-pkg/acquire-item.h>
38 #include <apt-pkg/strutl.h>
39 #include <apt-pkg/clean.h>
40 #include <apt-pkg/srcrecords.h>
41 #include <apt-pkg/version.h>
42 #include <apt-pkg/cachefile.h>
43 #include <apt-pkg/cacheset.h>
44 #include <apt-pkg/sptr.h>
45 #include <apt-pkg/md5.h>
46 #include <apt-pkg/versionmatch.h>
51 #include "acqprogress.h"
58 #include <sys/ioctl.h>
60 #include <sys/statfs.h>
61 #include <sys/statvfs.h>
70 #define statfs statfs64
71 #define statvfs statvfs64
74 #define RAMFS_MAGIC 0x858458f6
81 ofstream
devnull("/dev/null");
82 unsigned int ScreenWidth
= 80 - 1; /* - 1 for the cursor */
84 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
85 // ---------------------------------------------------------------------
87 class CacheFile
: public pkgCacheFile
89 static pkgCache
*SortCache
;
90 static int NameComp(const void *a
,const void *b
);
93 pkgCache::Package
**List
;
96 bool CheckDeps(bool AllowBroken
= false);
97 bool BuildCaches(bool WithLock
= true)
99 OpTextProgress
Prog(*_config
);
100 if (pkgCacheFile::BuildCaches(&Prog
,WithLock
) == false)
104 bool Open(bool WithLock
= true)
106 OpTextProgress
Prog(*_config
);
107 if (pkgCacheFile::Open(&Prog
,WithLock
) == false)
113 bool OpenForInstall()
115 if (_config
->FindB("APT::Get::Print-URIs") == true)
120 CacheFile() : List(0) {};
127 // YnPrompt - Yes No Prompt. /*{{{*/
128 // ---------------------------------------------------------------------
129 /* Returns true on a Yes.*/
130 bool YnPrompt(bool Default
=true)
132 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
134 c1out
<< _("Y") << endl
;
138 char response
[1024] = "";
139 cin
.getline(response
, sizeof(response
));
144 if (strlen(response
) == 0)
150 Res
= regcomp(&Pattern
, nl_langinfo(YESEXPR
),
151 REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
155 regerror(Res
,&Pattern
,Error
,sizeof(Error
));
156 return _error
->Error(_("Regex compilation error - %s"),Error
);
159 Res
= regexec(&Pattern
, response
, 0, NULL
, 0);
165 // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
166 // ---------------------------------------------------------------------
167 /* Returns true on a Yes.*/
168 bool AnalPrompt(const char *Text
)
171 cin
.getline(Buf
,sizeof(Buf
));
172 if (strcmp(Buf
,Text
) == 0)
177 // ShowList - Show a list /*{{{*/
178 // ---------------------------------------------------------------------
179 /* This prints out a string of space separated words with a title and
180 a two space indent line wraped to the current screen width. */
181 bool ShowList(ostream
&out
,string Title
,string List
,string VersionsList
)
183 if (List
.empty() == true)
185 // trim trailing space
186 int NonSpace
= List
.find_last_not_of(' ');
189 List
= List
.erase(NonSpace
+ 1);
190 if (List
.empty() == true)
194 // Acount for the leading space
195 int ScreenWidth
= ::ScreenWidth
- 3;
197 out
<< Title
<< endl
;
198 string::size_type Start
= 0;
199 string::size_type VersionsStart
= 0;
200 while (Start
< List
.size())
202 if(_config
->FindB("APT::Get::Show-Versions",false) == true &&
203 VersionsList
.size() > 0) {
204 string::size_type End
;
205 string::size_type VersionsEnd
;
207 End
= List
.find(' ',Start
);
208 VersionsEnd
= VersionsList
.find('\n', VersionsStart
);
210 out
<< " " << string(List
,Start
,End
- Start
) << " (" <<
211 string(VersionsList
,VersionsStart
,VersionsEnd
- VersionsStart
) <<
214 if (End
== string::npos
|| End
< Start
)
215 End
= Start
+ ScreenWidth
;
218 VersionsStart
= VersionsEnd
+ 1;
220 string::size_type End
;
222 if (Start
+ ScreenWidth
>= List
.size())
225 End
= List
.rfind(' ',Start
+ScreenWidth
);
227 if (End
== string::npos
|| End
< Start
)
228 End
= Start
+ ScreenWidth
;
229 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
237 // ShowBroken - Debugging aide /*{{{*/
238 // ---------------------------------------------------------------------
239 /* This prints out the names of all the packages that are broken along
240 with the name of each each broken dependency and a quite version
243 The output looks like:
244 The following packages have unmet dependencies:
245 exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed
246 Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
247 Depends: libsasl7 but it is not going to be installed
249 void ShowBroken(ostream
&out
,CacheFile
&Cache
,bool Now
)
251 out
<< _("The following packages have unmet dependencies:") << endl
;
252 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
254 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
258 if (Cache
[I
].NowBroken() == false)
263 if (Cache
[I
].InstBroken() == false)
267 // Print out each package and the failed dependencies
268 out
<< " " << I
.FullName(true) << " :";
269 unsigned const Indent
= I
.FullName(true).size() + 3;
271 pkgCache::VerIterator Ver
;
274 Ver
= I
.CurrentVer();
276 Ver
= Cache
[I
].InstVerIter(Cache
);
278 if (Ver
.end() == true)
284 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false;)
286 // Compute a single dependency element (glob or)
287 pkgCache::DepIterator Start
;
288 pkgCache::DepIterator End
;
289 D
.GlobOr(Start
,End
); // advances D
291 if (Cache
->IsImportantDep(End
) == false)
296 if ((Cache
[End
] & pkgDepCache::DepGNow
) == pkgDepCache::DepGNow
)
301 if ((Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
309 for (unsigned J
= 0; J
!= Indent
; J
++)
313 if (FirstOr
== false)
315 for (unsigned J
= 0; J
!= strlen(End
.DepType()) + 3; J
++)
319 out
<< ' ' << End
.DepType() << ": ";
322 out
<< Start
.TargetPkg().FullName(true);
324 // Show a quick summary of the version requirements
325 if (Start
.TargetVer() != 0)
326 out
<< " (" << Start
.CompType() << " " << Start
.TargetVer() << ")";
328 /* Show a summary of the target package if possible. In the case
329 of virtual packages we show nothing */
330 pkgCache::PkgIterator Targ
= Start
.TargetPkg();
331 if (Targ
->ProvidesList
== 0)
334 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
336 Ver
= Targ
.CurrentVer();
338 if (Ver
.end() == false)
341 ioprintf(out
,_("but %s is installed"),Ver
.VerStr());
343 ioprintf(out
,_("but %s is to be installed"),Ver
.VerStr());
347 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
349 if (Targ
->ProvidesList
== 0)
350 out
<< _("but it is not installable");
352 out
<< _("but it is a virtual package");
355 out
<< (Now
?_("but it is not installed"):_("but it is not going to be installed"));
371 // ShowNew - Show packages to newly install /*{{{*/
372 // ---------------------------------------------------------------------
374 void ShowNew(ostream
&out
,CacheFile
&Cache
)
376 /* Print out a list of packages that are going to be installed extra
377 to what the user asked */
380 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
382 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
383 if (Cache
[I
].NewInstall() == true) {
384 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
386 List
+= I
.FullName(true) + " ";
387 VersionsList
+= string(Cache
[I
].CandVersion
) + "\n";
391 ShowList(out
,_("The following NEW packages will be installed:"),List
,VersionsList
);
394 // ShowDel - Show packages to delete /*{{{*/
395 // ---------------------------------------------------------------------
397 void ShowDel(ostream
&out
,CacheFile
&Cache
)
399 /* Print out a list of packages that are going to be removed extra
400 to what the user asked */
403 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
405 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
406 if (Cache
[I
].Delete() == true)
408 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
410 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
411 List
+= I
.FullName(true) + "* ";
413 List
+= I
.FullName(true) + " ";
415 VersionsList
+= string(Cache
[I
].CandVersion
)+ "\n";
419 ShowList(out
,_("The following packages will be REMOVED:"),List
,VersionsList
);
422 // ShowKept - Show kept packages /*{{{*/
423 // ---------------------------------------------------------------------
425 void ShowKept(ostream
&out
,CacheFile
&Cache
)
429 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
431 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
434 if (Cache
[I
].Upgrade() == true || Cache
[I
].Upgradable() == false ||
435 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
438 List
+= I
.FullName(true) + " ";
439 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
441 ShowList(out
,_("The following packages have been kept back:"),List
,VersionsList
);
444 // ShowUpgraded - Show upgraded packages /*{{{*/
445 // ---------------------------------------------------------------------
447 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
451 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
453 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
456 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
458 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
461 List
+= I
.FullName(true) + " ";
462 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
464 ShowList(out
,_("The following packages will be upgraded:"),List
,VersionsList
);
467 // ShowDowngraded - Show downgraded packages /*{{{*/
468 // ---------------------------------------------------------------------
470 bool ShowDowngraded(ostream
&out
,CacheFile
&Cache
)
474 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
476 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
479 if (Cache
[I
].Downgrade() == false || Cache
[I
].NewInstall() == true)
481 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
484 List
+= I
.FullName(true) + " ";
485 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
487 return ShowList(out
,_("The following packages will be DOWNGRADED:"),List
,VersionsList
);
490 // ShowHold - Show held but changed packages /*{{{*/
491 // ---------------------------------------------------------------------
493 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
497 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
499 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
500 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
501 I
->SelectedState
== pkgCache::State::Hold
) {
502 List
+= I
.FullName(true) + " ";
503 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
507 return ShowList(out
,_("The following held packages will be changed:"),List
,VersionsList
);
510 // ShowEssential - Show an essential package warning /*{{{*/
511 // ---------------------------------------------------------------------
512 /* This prints out a warning message that is not to be ignored. It shows
513 all essential packages and their dependents that are to be removed.
514 It is insanely risky to remove the dependents of an essential package! */
515 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
519 bool *Added
= new bool[Cache
->Head().PackageCount
];
520 for (unsigned int I
= 0; I
!= Cache
->Head().PackageCount
; I
++)
523 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
525 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
526 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
&&
527 (I
->Flags
& pkgCache::Flag::Important
) != pkgCache::Flag::Important
)
530 // The essential package is being removed
531 if (Cache
[I
].Delete() == true)
533 if (Added
[I
->ID
] == false)
536 List
+= I
.FullName(true) + " ";
537 //VersionsList += string(Cache[I].CurVersion) + "\n"; ???
541 if (I
->CurrentVer
== 0)
544 // Print out any essential package depenendents that are to be removed
545 for (pkgCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
547 // Skip everything but depends
548 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
549 D
->Type
!= pkgCache::Dep::Depends
)
552 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
553 if (Cache
[P
].Delete() == true)
555 if (Added
[P
->ID
] == true)
560 snprintf(S
,sizeof(S
),_("%s (due to %s) "),P
.FullName(true).c_str(),I
.FullName(true).c_str());
562 //VersionsList += "\n"; ???
568 return ShowList(out
,_("WARNING: The following essential packages will be removed.\n"
569 "This should NOT be done unless you know exactly what you are doing!"),List
,VersionsList
);
573 // Stats - Show some statistics /*{{{*/
574 // ---------------------------------------------------------------------
576 void Stats(ostream
&out
,pkgDepCache
&Dep
)
578 unsigned long Upgrade
= 0;
579 unsigned long Downgrade
= 0;
580 unsigned long Install
= 0;
581 unsigned long ReInstall
= 0;
582 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
584 if (pkgCache::VerIterator(Dep
, Dep
[I
].CandidateVer
).Pseudo() == true)
587 if (Dep
[I
].NewInstall() == true)
591 if (Dep
[I
].Upgrade() == true)
594 if (Dep
[I
].Downgrade() == true)
598 if (Dep
[I
].Delete() == false && (Dep
[I
].iFlags
& pkgDepCache::ReInstall
) == pkgDepCache::ReInstall
)
602 ioprintf(out
,_("%lu upgraded, %lu newly installed, "),
606 ioprintf(out
,_("%lu reinstalled, "),ReInstall
);
608 ioprintf(out
,_("%lu downgraded, "),Downgrade
);
610 ioprintf(out
,_("%lu to remove and %lu not upgraded.\n"),
611 Dep
.DelCount(),Dep
.KeepCount());
613 if (Dep
.BadCount() != 0)
614 ioprintf(out
,_("%lu not fully installed or removed.\n"),
618 // CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/
619 class CacheSetHelperAPTGet
: public APT::CacheSetHelper
{
620 /** \brief stream message should be printed to */
622 /** \brief were things like Task or RegEx used to select packages? */
623 bool explicitlyNamed
;
625 APT::PackageSet virtualPkgs
;
628 CacheSetHelperAPTGet(std::ostream
&out
) : APT::CacheSetHelper(true), out(out
) {
629 explicitlyNamed
= true;
632 virtual void showTaskSelection(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 task '%s'\n"),
635 Pkg
.FullName(true).c_str(), pattern
.c_str());
636 explicitlyNamed
= false;
638 virtual void showRegExSelection(APT::PackageSet
const &pkgset
, string
const &pattern
) {
639 for (APT::PackageSet::const_iterator Pkg
= pkgset
.begin(); Pkg
!= pkgset
.end(); ++Pkg
)
640 ioprintf(out
, _("Note, selecting '%s' for regex '%s'\n"),
641 Pkg
.FullName(true).c_str(), pattern
.c_str());
642 explicitlyNamed
= false;
644 virtual void showSelectedVersion(pkgCache::PkgIterator
const &Pkg
, pkgCache::VerIterator
const Ver
,
645 string
const &ver
, bool const &verIsRel
) {
646 if (ver
!= Ver
.VerStr())
647 ioprintf(out
, _("Selected version '%s' (%s) for '%s'\n"),
648 Ver
.VerStr(), Ver
.RelStr().c_str(), Pkg
.FullName(true).c_str());
651 bool showVirtualPackageErrors(pkgCacheFile
&Cache
) {
652 if (virtualPkgs
.empty() == true)
654 for (APT::PackageSet::const_iterator Pkg
= virtualPkgs
.begin();
655 Pkg
!= virtualPkgs
.end(); ++Pkg
) {
656 if (Pkg
->ProvidesList
!= 0) {
657 ioprintf(c1out
,_("Package %s is a virtual package provided by:\n"),
658 Pkg
.FullName(true).c_str());
660 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
661 unsigned short provider
= 0;
662 for (; I
.end() == false; ++I
) {
663 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
665 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer()) {
666 out
<< " " << Pkg
.FullName(true) << " " << I
.OwnerVer().VerStr();
667 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
668 out
<< _(" [Installed]");
673 // if we found no candidate which provide this package, show non-candidates
675 for (I
= Pkg
.ProvidesList(); I
.end() == false; I
++)
676 out
<< " " << I
.OwnerPkg().FullName(true) << " " << I
.OwnerVer().VerStr()
677 << _(" [Not candidate version]") << endl
;
679 out
<< _("You should explicitly select one to install.") << endl
;
682 _("Package %s is not available, but is referred to by another package.\n"
683 "This may mean that the package is missing, has been obsoleted, or\n"
684 "is only available from another source\n"),Pkg
.FullName(true).c_str());
688 SPtrArray
<bool> Seen
= new bool[Cache
.GetPkgCache()->Head().PackageCount
];
689 memset(Seen
,0,Cache
.GetPkgCache()->Head().PackageCount
*sizeof(*Seen
));
690 for (pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
691 Dep
.end() == false; Dep
++) {
692 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
694 if (Seen
[Dep
.ParentPkg()->ID
] == true)
696 Seen
[Dep
.ParentPkg()->ID
] = true;
697 List
+= Dep
.ParentPkg().FullName(true) + " ";
698 //VersionsList += string(Dep.ParentPkg().CurVersion) + "\n"; ???
700 ShowList(out
,_("However the following packages replace it:"),List
,VersionsList
);
707 virtual pkgCache::VerIterator
canNotFindCandidateVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
708 APT::VersionSet
const verset
= tryVirtualPackage(Cache
, Pkg
, APT::VersionSet::CANDIDATE
);
709 if (verset
.empty() == false)
710 return *(verset
.begin());
711 if (ShowError
== true) {
712 _error
->Error(_("Package '%s' has no installation candidate"),Pkg
.FullName(true).c_str());
713 virtualPkgs
.insert(Pkg
);
715 return pkgCache::VerIterator(Cache
, 0);
718 virtual pkgCache::VerIterator
canNotFindNewestVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
719 APT::VersionSet
const verset
= tryVirtualPackage(Cache
, Pkg
, APT::VersionSet::NEWEST
);
720 if (verset
.empty() == false)
721 return *(verset
.begin());
722 if (ShowError
== true)
723 ioprintf(out
, _("Virtual packages like '%s' can't be removed\n"), Pkg
.FullName(true).c_str());
724 return pkgCache::VerIterator(Cache
, 0);
727 APT::VersionSet
tryVirtualPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
,
728 APT::VersionSet::Version
const &select
) {
729 /* This is a pure virtual package and there is a single available
730 candidate providing it. */
731 if (unlikely(Cache
[Pkg
].CandidateVer
!= 0) || Pkg
->ProvidesList
== 0)
732 return APT::VersionSet();
734 pkgCache::PkgIterator Prov
;
735 bool found_one
= false;
736 for (pkgCache::PrvIterator P
= Pkg
.ProvidesList(); P
; ++P
) {
737 pkgCache::VerIterator
const PVer
= P
.OwnerVer();
738 pkgCache::PkgIterator
const PPkg
= PVer
.ParentPkg();
740 /* Ignore versions that are not a candidate. */
741 if (Cache
[PPkg
].CandidateVer
!= PVer
)
744 if (found_one
== false) {
747 } else if (PPkg
!= Prov
) {
748 found_one
= false; // we found at least two
753 if (found_one
== true) {
754 ioprintf(out
, _("Note, selecting '%s' instead of '%s'\n"),
755 Prov
.FullName(true).c_str(), Pkg
.FullName(true).c_str());
756 return APT::VersionSet::FromPackage(Cache
, Prov
, select
, *this);
758 return APT::VersionSet();
761 inline bool allPkgNamedExplicitly() const { return explicitlyNamed
; }
765 // TryToInstall - Mark a package for installation /*{{{*/
766 struct TryToInstall
{
768 pkgProblemResolver
* Fix
;
770 unsigned long AutoMarkChanged
;
771 APT::PackageSet doAutoInstallLater
;
773 TryToInstall(pkgCacheFile
&Cache
, pkgProblemResolver
&PM
, bool const &FixBroken
) : Cache(&Cache
), Fix(&PM
),
774 FixBroken(FixBroken
), AutoMarkChanged(0) {};
776 void operator() (pkgCache::VerIterator
const &Ver
) {
777 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
779 Cache
->GetDepCache()->SetCandidateVersion(Ver
);
780 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
782 // Handle the no-upgrade case
783 if (_config
->FindB("APT::Get::upgrade",true) == false && Pkg
->CurrentVer
!= 0)
784 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
785 Pkg
.FullName(true).c_str());
786 // Ignore request for install if package would be new
787 else if (_config
->FindB("APT::Get::Only-Upgrade", false) == true && Pkg
->CurrentVer
== 0)
788 ioprintf(c1out
,_("Skipping %s, it is not installed and only upgrades are requested.\n"),
789 Pkg
.FullName(true).c_str());
793 Cache
->GetDepCache()->MarkInstall(Pkg
,false);
795 if (State
.Install() == false) {
796 if (_config
->FindB("APT::Get::ReInstall",false) == true) {
797 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
798 ioprintf(c1out
,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
799 Pkg
.FullName(true).c_str());
801 Cache
->GetDepCache()->SetReInstall(Pkg
, true);
803 ioprintf(c1out
,_("%s is already the newest version.\n"),
804 Pkg
.FullName(true).c_str());
807 // Install it with autoinstalling enabled (if we not respect the minial
808 // required deps or the policy)
809 if (FixBroken
== false)
810 doAutoInstallLater
.insert(Pkg
);
813 // see if we need to fix the auto-mark flag
814 // e.g. apt-get install foo
815 // where foo is marked automatic
816 if (State
.Install() == false &&
817 (State
.Flags
& pkgCache::Flag::Auto
) &&
818 _config
->FindB("APT::Get::ReInstall",false) == false &&
819 _config
->FindB("APT::Get::Only-Upgrade",false) == false &&
820 _config
->FindB("APT::Get::Download-Only",false) == false)
822 ioprintf(c1out
,_("%s set to manually installed.\n"),
823 Pkg
.FullName(true).c_str());
824 Cache
->GetDepCache()->MarkAuto(Pkg
,false);
829 void doAutoInstall() {
830 for (APT::PackageSet::const_iterator P
= doAutoInstallLater
.begin();
831 P
!= doAutoInstallLater
.end(); ++P
) {
832 pkgDepCache::StateCache
&State
= (*Cache
)[P
];
833 if (State
.InstBroken() == false && State
.InstPolicyBroken() == false)
835 Cache
->GetDepCache()->MarkInstall(P
, true);
837 doAutoInstallLater
.clear();
841 // TryToRemove - Mark a package for removal /*{{{*/
844 pkgProblemResolver
* Fix
;
846 unsigned long AutoMarkChanged
;
848 TryToRemove(pkgCacheFile
&Cache
, pkgProblemResolver
&PM
) : Cache(&Cache
), Fix(&PM
) {};
850 void operator() (pkgCache::VerIterator
const &Ver
)
852 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
858 if (Pkg
->CurrentVer
== 0)
859 ioprintf(c1out
,_("Package %s is not installed, so not removed\n"),Pkg
.FullName(true).c_str());
861 Cache
->GetDepCache()->MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
865 // CacheFile::NameComp - QSort compare by name /*{{{*/
866 // ---------------------------------------------------------------------
868 pkgCache
*CacheFile::SortCache
= 0;
869 int CacheFile::NameComp(const void *a
,const void *b
)
871 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
872 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
874 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
875 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
877 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
880 // CacheFile::Sort - Sort by name /*{{{*/
881 // ---------------------------------------------------------------------
883 void CacheFile::Sort()
886 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
887 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
888 pkgCache::PkgIterator I
= Cache
->PkgBegin();
889 for (;I
.end() != true; I
++)
893 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
896 // CacheFile::CheckDeps - Open the cache file /*{{{*/
897 // ---------------------------------------------------------------------
898 /* This routine generates the caches and then opens the dependency cache
899 and verifies that the system is OK. */
900 bool CacheFile::CheckDeps(bool AllowBroken
)
902 bool FixBroken
= _config
->FindB("APT::Get::Fix-Broken",false);
904 if (_error
->PendingError() == true)
907 // Check that the system is OK
908 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
909 return _error
->Error("Internal error, non-zero counts");
911 // Apply corrections for half-installed packages
912 if (pkgApplyStatus(*DCache
) == false)
915 if (_config
->FindB("APT::Get::Fix-Policy-Broken",false) == true)
918 if ((DCache
->PolicyBrokenCount() > 0))
920 // upgrade all policy-broken packages with ForceImportantDeps=True
921 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); !I
.end(); I
++)
922 if ((*DCache
)[I
].NowPolicyBroken() == true)
923 DCache
->MarkInstall(I
,true,0, false, true);
928 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
931 // Attempt to fix broken things
932 if (FixBroken
== true)
934 c1out
<< _("Correcting dependencies...") << flush
;
935 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
937 c1out
<< _(" failed.") << endl
;
938 ShowBroken(c1out
,*this,true);
940 return _error
->Error(_("Unable to correct dependencies"));
942 if (pkgMinimizeUpgrade(*DCache
) == false)
943 return _error
->Error(_("Unable to minimize the upgrade set"));
945 c1out
<< _(" Done") << endl
;
949 c1out
<< _("You might want to run 'apt-get -f install' to correct these.") << endl
;
950 ShowBroken(c1out
,*this,true);
952 return _error
->Error(_("Unmet dependencies. Try using -f."));
958 // CheckAuth - check if each download comes form a trusted source /*{{{*/
959 // ---------------------------------------------------------------------
961 static bool CheckAuth(pkgAcquire
& Fetcher
)
963 string UntrustedList
;
964 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd(); ++I
)
966 if (!(*I
)->IsTrusted())
968 UntrustedList
+= string((*I
)->ShortDesc()) + " ";
972 if (UntrustedList
== "")
977 ShowList(c2out
,_("WARNING: The following packages cannot be authenticated!"),UntrustedList
,"");
979 if (_config
->FindB("APT::Get::AllowUnauthenticated",false) == true)
981 c2out
<< _("Authentication warning overridden.\n");
985 if (_config
->FindI("quiet",0) < 2
986 && _config
->FindB("APT::Get::Assume-Yes",false) == false)
988 c2out
<< _("Install these packages without verification [y/N]? ") << flush
;
989 if (!YnPrompt(false))
990 return _error
->Error(_("Some packages could not be authenticated"));
994 else if (_config
->FindB("APT::Get::Force-Yes",false) == true)
999 return _error
->Error(_("There are problems and -y was used without --force-yes"));
1002 // InstallPackages - Actually download and install the packages /*{{{*/
1003 // ---------------------------------------------------------------------
1004 /* This displays the informative messages describing what is going to
1005 happen and then calls the download routines */
1006 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,
1009 if (_config
->FindB("APT::Get::Purge",false) == true)
1011 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1012 for (; I
.end() == false; I
++)
1014 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
1015 Cache
->MarkDelete(I
,true);
1020 bool Essential
= false;
1022 // Show all the various warning indicators
1023 ShowDel(c1out
,Cache
);
1024 ShowNew(c1out
,Cache
);
1025 if (ShwKept
== true)
1026 ShowKept(c1out
,Cache
);
1027 Fail
|= !ShowHold(c1out
,Cache
);
1028 if (_config
->FindB("APT::Get::Show-Upgraded",true) == true)
1029 ShowUpgraded(c1out
,Cache
);
1030 Fail
|= !ShowDowngraded(c1out
,Cache
);
1031 if (_config
->FindB("APT::Get::Download-Only",false) == false)
1032 Essential
= !ShowEssential(c1out
,Cache
);
1037 if (Cache
->BrokenCount() != 0)
1039 ShowBroken(c1out
,Cache
,false);
1040 return _error
->Error(_("Internal error, InstallPackages was called with broken packages!"));
1043 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
1044 Cache
->BadCount() == 0)
1048 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::Remove",true) == false)
1049 return _error
->Error(_("Packages need to be removed but remove is disabled."));
1051 // Run the simulator ..
1052 if (_config
->FindB("APT::Get::Simulate") == true)
1054 pkgSimulate
PM(Cache
);
1055 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
1056 pkgPackageManager::OrderResult Res
= PM
.DoInstall(status_fd
);
1057 if (Res
== pkgPackageManager::Failed
)
1059 if (Res
!= pkgPackageManager::Completed
)
1060 return _error
->Error(_("Internal error, Ordering didn't finish"));
1064 // Create the text record parser
1065 pkgRecords
Recs(Cache
);
1066 if (_error
->PendingError() == true)
1069 // Create the download object
1071 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1072 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
1074 // force a hashsum for compatibility reasons
1075 _config
->CndSet("Acquire::ForceHash", "md5sum");
1076 if (Fetcher
.Setup(&Stat
, "") == false)
1079 else if (Fetcher
.Setup(&Stat
, _config
->FindDir("Dir::Cache::Archives")) == false)
1082 // Read the source list
1084 if (List
.ReadMainList() == false)
1085 return _error
->Error(_("The list of sources could not be read."));
1087 // Create the package manager and prepare to download
1088 SPtr
<pkgPackageManager
> PM
= _system
->CreatePM(Cache
);
1089 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false ||
1090 _error
->PendingError() == true)
1093 // Display statistics
1094 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
1095 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
1096 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
1097 if (DebBytes
!= Cache
->DebSize())
1099 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
1100 c0out
<< _("How odd.. The sizes didn't match, email apt@packages.debian.org") << endl
;
1104 if (DebBytes
!= FetchBytes
)
1105 ioprintf(c1out
,_("Need to get %sB/%sB of archives.\n"),
1106 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
1107 else if (DebBytes
!= 0)
1108 ioprintf(c1out
,_("Need to get %sB of archives.\n"),
1109 SizeToStr(DebBytes
).c_str());
1112 if (Cache
->UsrSize() >= 0)
1113 ioprintf(c1out
,_("After this operation, %sB of additional disk space will be used.\n"),
1114 SizeToStr(Cache
->UsrSize()).c_str());
1116 ioprintf(c1out
,_("After this operation, %sB disk space will be freed.\n"),
1117 SizeToStr(-1*Cache
->UsrSize()).c_str());
1119 if (_error
->PendingError() == true)
1122 /* Check for enough free space, but only if we are actually going to
1124 if (_config
->FindB("APT::Get::Print-URIs") == false &&
1125 _config
->FindB("APT::Get::Download",true) == true)
1128 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
1129 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
1130 if (errno
== EOVERFLOW
)
1131 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
1134 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
1136 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1139 if (statfs(OutputDir
.c_str(),&Stat
) != 0
1140 #if HAVE_STRUCT_STATFS_F_TYPE
1141 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
1144 return _error
->Error(_("You don't have enough free space in %s."),
1150 if (_config
->FindI("quiet",0) >= 2 ||
1151 _config
->FindB("APT::Get::Assume-Yes",false) == true)
1153 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
1154 return _error
->Error(_("There are problems and -y was used without --force-yes"));
1157 if (Essential
== true && Safety
== true)
1159 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
1160 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
1162 const char *Prompt
= _("Yes, do as I say!");
1164 _("You are about to do something potentially harmful.\n"
1165 "To continue type in the phrase '%s'\n"
1168 if (AnalPrompt(Prompt
) == false)
1170 c2out
<< _("Abort.") << endl
;
1176 // Prompt to continue
1177 if (Ask
== true || Fail
== true)
1179 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
1180 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
1182 if (_config
->FindI("quiet",0) < 2 &&
1183 _config
->FindB("APT::Get::Assume-Yes",false) == false)
1185 c2out
<< _("Do you want to continue [Y/n]? ") << flush
;
1187 if (YnPrompt() == false)
1189 c2out
<< _("Abort.") << endl
;
1196 // Just print out the uris an exit if the --print-uris flag was used
1197 if (_config
->FindB("APT::Get::Print-URIs") == true)
1199 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1200 for (; I
!= Fetcher
.UriEnd(); I
++)
1201 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1202 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
1206 if (!CheckAuth(Fetcher
))
1209 /* Unlock the dpkg lock if we are not going to be doing an install
1211 if (_config
->FindB("APT::Get::Download-Only",false) == true)
1217 bool Transient
= false;
1218 if (_config
->FindB("APT::Get::Download",true) == false)
1220 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
1222 if ((*I
)->Local
== true)
1228 // Close the item and check if it was found in cache
1230 if ((*I
)->Complete
== false)
1233 // Clear it out of the fetch list
1235 I
= Fetcher
.ItemsBegin();
1239 if (Fetcher
.Run() == pkgAcquire::Failed
)
1243 bool Failed
= false;
1244 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1246 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1247 (*I
)->Complete
== true)
1250 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
1257 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1258 (*I
)->ErrorText
.c_str());
1262 /* If we are in no download mode and missing files and there were
1263 'failures' then the user must specify -m. Furthermore, there
1264 is no such thing as a transient error in no-download mode! */
1265 if (Transient
== true &&
1266 _config
->FindB("APT::Get::Download",true) == false)
1272 if (_config
->FindB("APT::Get::Download-Only",false) == true)
1274 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
1275 return _error
->Error(_("Some files failed to download"));
1276 c1out
<< _("Download complete and in download only mode") << endl
;
1280 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
1282 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
1285 if (Transient
== true && Failed
== true)
1286 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
1288 // Try to deal with missing package files
1289 if (Failed
== true && PM
->FixMissing() == false)
1291 cerr
<< _("Unable to correct missing packages.") << endl
;
1292 return _error
->Error(_("Aborting install."));
1296 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
1297 pkgPackageManager::OrderResult Res
= PM
->DoInstall(status_fd
);
1298 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
1300 if (Res
== pkgPackageManager::Completed
)
1303 // Reload the fetcher object and loop again for media swapping
1305 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false)
1311 std::set
<std::string
> const disappearedPkgs
= PM
->GetDisappearedPackages();
1312 if (disappearedPkgs
.empty() == true)
1316 for (std::set
<std::string
>::const_iterator d
= disappearedPkgs
.begin();
1317 d
!= disappearedPkgs
.end(); ++d
)
1318 disappear
.append(*d
).append(" ");
1320 ShowList(c1out
, P_("The following package disappeared from your system as\n"
1321 "all files have been overwritten by other packages:",
1322 "The following packages disappeared from your system as\n"
1323 "all files have been overwritten by other packages:", disappearedPkgs
.size()), disappear
, "");
1324 c0out
<< _("Note: This is done automatic and on purpose by dpkg.") << std::endl
;
1329 // TryToInstallBuildDep - Try to install a single package /*{{{*/
1330 // ---------------------------------------------------------------------
1331 /* This used to be inlined in DoInstall, but with the advent of regex package
1332 name matching it was split out.. */
1333 bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg
,pkgCacheFile
&Cache
,
1334 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
1335 bool AllowFail
= true)
1337 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0)
1339 CacheSetHelperAPTGet
helper(c1out
);
1340 helper
.showErrors(AllowFail
== false);
1341 pkgCache::VerIterator Ver
= helper
.canNotFindNewestVer(Cache
, Pkg
);
1342 if (Ver
.end() == false)
1343 Pkg
= Ver
.ParentPkg();
1344 else if (helper
.showVirtualPackageErrors(Cache
) == false)
1350 TryToRemove
RemoveAction(Cache
, Fix
);
1351 RemoveAction(Pkg
.VersionList());
1352 } else if (Cache
[Pkg
].CandidateVer
!= 0) {
1353 TryToInstall
InstallAction(Cache
, Fix
, BrokenFix
);
1354 InstallAction(Cache
[Pkg
].CandidateVerIter(Cache
));
1355 InstallAction
.doAutoInstall();
1362 // FindSrc - Find a source record /*{{{*/
1363 // ---------------------------------------------------------------------
1365 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
1366 pkgSrcRecords
&SrcRecs
,string
&Src
,
1370 string DefRel
= _config
->Find("APT::Default-Release");
1371 string TmpSrc
= Name
;
1373 // extract the version/release from the pkgname
1374 const size_t found
= TmpSrc
.find_last_of("/=");
1375 if (found
!= string::npos
) {
1376 if (TmpSrc
[found
] == '/')
1377 DefRel
= TmpSrc
.substr(found
+1);
1379 VerTag
= TmpSrc
.substr(found
+1);
1380 TmpSrc
= TmpSrc
.substr(0,found
);
1383 /* Lookup the version of the package we would install if we were to
1384 install a version and determine the source package name, then look
1385 in the archive for a source package of the same name. */
1386 bool MatchSrcOnly
= _config
->FindB("APT::Get::Only-Source");
1387 const pkgCache::PkgIterator Pkg
= Cache
.FindPkg(TmpSrc
);
1388 if (MatchSrcOnly
== false && Pkg
.end() == false)
1390 if(VerTag
.empty() == false || DefRel
.empty() == false)
1393 // we have a default release, try to locate the pkg. we do it like
1394 // this because GetCandidateVer() will not "downgrade", that means
1395 // "apt-get source -t stable apt" won't work on a unstable system
1396 for (pkgCache::VerIterator Ver
= Pkg
.VersionList();; Ver
++)
1398 // try first only exact matches, later fuzzy matches
1399 if (Ver
.end() == true)
1404 Ver
= Pkg
.VersionList();
1405 // exit right away from the Pkg.VersionList() loop if we
1406 // don't have any versions
1407 if (Ver
.end() == true)
1410 // We match against a concrete version (or a part of this version)
1411 if (VerTag
.empty() == false &&
1412 (fuzzy
== true || Cache
.VS().CmpVersion(VerTag
, Ver
.VerStr()) != 0) && // exact match
1413 (fuzzy
== false || strncmp(VerTag
.c_str(), Ver
.VerStr(), VerTag
.size()) != 0)) // fuzzy match
1416 for (pkgCache::VerFileIterator VF
= Ver
.FileList();
1417 VF
.end() == false; VF
++)
1419 /* If this is the status file, and the current version is not the
1420 version in the status file (ie it is not installed, or somesuch)
1421 then it is not a candidate for installation, ever. This weeds
1422 out bogus entries that may be due to config-file states, or
1424 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) ==
1425 pkgCache::Flag::NotSource
&& Pkg
.CurrentVer() != Ver
)
1428 // or we match against a release
1429 if(VerTag
.empty() == false ||
1430 (VF
.File().Archive() != 0 && VF
.File().Archive() == DefRel
) ||
1431 (VF
.File().Codename() != 0 && VF
.File().Codename() == DefRel
))
1433 pkgRecords::Parser
&Parse
= Recs
.Lookup(VF
);
1434 Src
= Parse
.SourcePkg();
1435 // no SourcePkg name, so it is the "binary" name
1436 if (Src
.empty() == true)
1438 // the Version we have is possibly fuzzy or includes binUploads,
1439 // so we use the Version of the SourcePkg (empty if same as package)
1440 VerTag
= Parse
.SourceVer();
1441 if (VerTag
.empty() == true)
1442 VerTag
= Ver
.VerStr();
1446 if (Src
.empty() == false)
1449 if (Src
.empty() == true)
1451 // Sources files have no codename information
1452 if (VerTag
.empty() == true && DefRel
.empty() == false)
1454 _error
->Error(_("Ignore unavailable target release '%s' of package '%s'"), DefRel
.c_str(), TmpSrc
.c_str());
1459 if (Src
.empty() == true)
1461 // if we don't have found a fitting package yet so we will
1462 // choose a good candidate and proceed with that.
1463 // Maybe we will find a source later on with the right VerTag
1464 pkgCache::VerIterator Ver
= Cache
.GetCandidateVer(Pkg
);
1465 if (Ver
.end() == false)
1467 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1468 Src
= Parse
.SourcePkg();
1469 if (VerTag
.empty() == true)
1470 VerTag
= Parse
.SourceVer();
1475 if (Src
.empty() == true)
1479 /* if we have a source pkg name, make sure to only search
1480 for srcpkg names, otherwise apt gets confused if there
1481 is a binary package "pkg1" and a source package "pkg1"
1482 with the same name but that comes from different packages */
1483 MatchSrcOnly
= true;
1486 ioprintf(c1out
, _("Picking '%s' as source package instead of '%s'\n"), Src
.c_str(), TmpSrc
.c_str());
1491 pkgSrcRecords::Parser
*Last
= 0;
1492 unsigned long Offset
= 0;
1495 /* Iterate over all of the hits, which includes the resulting
1496 binary packages in the search */
1497 pkgSrcRecords::Parser
*Parse
;
1501 while ((Parse
= SrcRecs
.Find(Src
.c_str(), MatchSrcOnly
)) != 0)
1503 const string Ver
= Parse
->Version();
1505 // Ignore all versions which doesn't fit
1506 if (VerTag
.empty() == false &&
1507 Cache
.VS().CmpVersion(VerTag
, Ver
) != 0) // exact match
1510 // Newer version or an exact match? Save the hit
1511 if (Last
== 0 || Cache
.VS().CmpVersion(Version
,Ver
) < 0) {
1513 Offset
= Parse
->Offset();
1517 // was the version check above an exact match? If so, we don't need to look further
1518 if (VerTag
.empty() == false && VerTag
.size() == Ver
.size())
1521 if (Last
!= 0 || VerTag
.empty() == true)
1523 //if (VerTag.empty() == false && Last == 0)
1524 _error
->Error(_("Ignore unavailable version '%s' of package '%s'"), VerTag
.c_str(), TmpSrc
.c_str());
1528 if (Last
== 0 || Last
->Jump(Offset
) == false)
1534 // DoUpdate - Update the package lists /*{{{*/
1535 // ---------------------------------------------------------------------
1537 bool DoUpdate(CommandLine
&CmdL
)
1539 if (CmdL
.FileSize() != 1)
1540 return _error
->Error(_("The update command takes no arguments"));
1542 // Get the source list
1544 if (List
.ReadMainList() == false)
1547 // Create the progress
1548 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1550 // Just print out the uris an exit if the --print-uris flag was used
1551 if (_config
->FindB("APT::Get::Print-URIs") == true)
1553 // force a hashsum for compatibility reasons
1554 _config
->CndSet("Acquire::ForceHash", "md5sum");
1558 if (Fetcher
.Setup(&Stat
) == false)
1561 // Populate it with the source selection and get all Indexes
1563 if (List
.GetIndexes(&Fetcher
,true) == false)
1566 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1567 for (; I
!= Fetcher
.UriEnd(); I
++)
1568 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1569 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
1575 if (_config
->FindB("APT::Get::Download",true) == true)
1576 ListUpdate(Stat
, List
);
1578 // Rebuild the cache.
1579 if (Cache
.BuildCaches() == false)
1585 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
1586 // ---------------------------------------------------------------------
1587 /* Remove unused automatic packages */
1588 bool DoAutomaticRemove(CacheFile
&Cache
)
1590 bool Debug
= _config
->FindI("Debug::pkgAutoRemove",false);
1591 bool doAutoRemove
= _config
->FindB("APT::Get::AutomaticRemove", false);
1592 bool hideAutoRemove
= _config
->FindB("APT::Get::HideAutoRemove");
1594 pkgDepCache::ActionGroup
group(*Cache
);
1596 std::cout
<< "DoAutomaticRemove()" << std::endl
;
1598 // we don't want to autoremove and we don't want to see it, so why calculating?
1599 if (doAutoRemove
== false && hideAutoRemove
== true)
1602 if (doAutoRemove
== true &&
1603 _config
->FindB("APT::Get::Remove",true) == false)
1605 c1out
<< _("We are not supposed to delete stuff, can't start "
1606 "AutoRemover") << std::endl
;
1610 bool purgePkgs
= _config
->FindB("APT::Get::Purge", false);
1611 bool smallList
= (hideAutoRemove
== false &&
1612 strcasecmp(_config
->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
1614 string autoremovelist
, autoremoveversions
;
1615 unsigned long autoRemoveCount
= 0;
1616 // look over the cache to see what can be removed
1617 for (pkgCache::PkgIterator Pkg
= Cache
->PkgBegin(); ! Pkg
.end(); ++Pkg
)
1619 if (Cache
[Pkg
].Garbage
)
1621 if(Pkg
.CurrentVer() != 0 || Cache
[Pkg
].Install())
1623 std::cout
<< "We could delete %s" << Pkg
.FullName(true).c_str() << std::endl
;
1627 if(Pkg
.CurrentVer() != 0 &&
1628 Pkg
->CurrentState
!= pkgCache::State::ConfigFiles
)
1629 Cache
->MarkDelete(Pkg
, purgePkgs
);
1631 Cache
->MarkKeep(Pkg
, false, false);
1635 // only show stuff in the list that is not yet marked for removal
1636 if(Cache
[Pkg
].Delete() == false)
1639 // we don't need to fill the strings if we don't need them
1640 if (smallList
== false)
1642 autoremovelist
+= Pkg
.FullName(true) + " ";
1643 autoremoveversions
+= string(Cache
[Pkg
].CandVersion
) + "\n";
1649 // if we don't remove them, we should show them!
1650 if (doAutoRemove
== false && (autoremovelist
.empty() == false || autoRemoveCount
!= 0))
1652 if (smallList
== false)
1653 ShowList(c1out
, P_("The following package is automatically installed and is no longer required:",
1654 "The following packages were automatically installed and are no longer required:",
1655 autoRemoveCount
), autoremovelist
, autoremoveversions
);
1657 ioprintf(c1out
, P_("%lu package was automatically installed and is no longer required.\n",
1658 "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount
), autoRemoveCount
);
1659 c1out
<< _("Use 'apt-get autoremove' to remove them.") << std::endl
;
1661 // Now see if we had destroyed anything (if we had done anything)
1662 else if (Cache
->BrokenCount() != 0)
1664 c1out
<< _("Hmm, seems like the AutoRemover destroyed something which really\n"
1665 "shouldn't happen. Please file a bug report against apt.") << endl
;
1667 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1669 ShowBroken(c1out
,Cache
,false);
1671 return _error
->Error(_("Internal Error, AutoRemover broke stuff"));
1676 // DoUpgrade - Upgrade all packages /*{{{*/
1677 // ---------------------------------------------------------------------
1678 /* Upgrade all packages without installing new packages or erasing old
1680 bool DoUpgrade(CommandLine
&CmdL
)
1683 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1687 if (pkgAllUpgrade(Cache
) == false)
1689 ShowBroken(c1out
,Cache
,false);
1690 return _error
->Error(_("Internal error, AllUpgrade broke stuff"));
1693 return InstallPackages(Cache
,true);
1696 // DoInstall - Install packages from the command line /*{{{*/
1697 // ---------------------------------------------------------------------
1698 /* Install named packages */
1699 bool DoInstall(CommandLine
&CmdL
)
1702 if (Cache
.OpenForInstall() == false ||
1703 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
1706 // Enter the special broken fixing mode if the user specified arguments
1707 bool BrokenFix
= false;
1708 if (Cache
->BrokenCount() != 0)
1711 pkgProblemResolver
Fix(Cache
);
1713 static const unsigned short MOD_REMOVE
= 1;
1714 static const unsigned short MOD_INSTALL
= 2;
1716 unsigned short fallback
= MOD_INSTALL
;
1717 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
1718 fallback
= MOD_REMOVE
;
1719 else if (strcasecmp(CmdL
.FileList
[0], "purge") == 0)
1721 _config
->Set("APT::Get::Purge", true);
1722 fallback
= MOD_REMOVE
;
1724 else if (strcasecmp(CmdL
.FileList
[0], "autoremove") == 0)
1726 _config
->Set("APT::Get::AutomaticRemove", "true");
1727 fallback
= MOD_REMOVE
;
1730 std::list
<APT::VersionSet::Modifier
> mods
;
1731 mods
.push_back(APT::VersionSet::Modifier(MOD_INSTALL
, "+",
1732 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::CANDIDATE
));
1733 mods
.push_back(APT::VersionSet::Modifier(MOD_REMOVE
, "-",
1734 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::NEWEST
));
1735 CacheSetHelperAPTGet
helper(c0out
);
1736 std::map
<unsigned short, APT::VersionSet
> verset
= APT::VersionSet::GroupedFromCommandLine(Cache
,
1737 CmdL
.FileList
+ 1, mods
, fallback
, helper
);
1739 if (_error
->PendingError() == true)
1741 helper
.showVirtualPackageErrors(Cache
);
1745 unsigned short order
[] = { 0, 0, 0 };
1746 if (fallback
== MOD_INSTALL
) {
1747 order
[0] = MOD_INSTALL
;
1748 order
[1] = MOD_REMOVE
;
1750 order
[0] = MOD_REMOVE
;
1751 order
[1] = MOD_INSTALL
;
1754 TryToInstall
InstallAction(Cache
, Fix
, BrokenFix
);
1755 TryToRemove
RemoveAction(Cache
, Fix
);
1757 // new scope for the ActionGroup
1759 pkgDepCache::ActionGroup
group(Cache
);
1761 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
1763 if (order
[i
] == MOD_INSTALL
) {
1764 InstallAction
= std::for_each(verset
[MOD_INSTALL
].begin(), verset
[MOD_INSTALL
].end(), InstallAction
);
1765 InstallAction
.doAutoInstall();
1767 else if (order
[i
] == MOD_REMOVE
)
1768 RemoveAction
= std::for_each(verset
[MOD_REMOVE
].begin(), verset
[MOD_REMOVE
].end(), RemoveAction
);
1771 if (_error
->PendingError() == true)
1774 /* If we are in the Broken fixing mode we do not attempt to fix the
1775 problems. This is if the user invoked install without -f and gave
1777 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1779 c1out
<< _("You might want to run 'apt-get -f install' to correct these:") << endl
;
1780 ShowBroken(c1out
,Cache
,false);
1782 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1785 // Call the scored problem resolver
1786 Fix
.InstallProtect();
1787 if (Fix
.Resolve(true) == false)
1790 // Now we check the state of the packages,
1791 if (Cache
->BrokenCount() != 0)
1794 _("Some packages could not be installed. This may mean that you have\n"
1795 "requested an impossible situation or if you are using the unstable\n"
1796 "distribution that some required packages have not yet been created\n"
1797 "or been moved out of Incoming.") << endl
;
1803 _("Since you only requested a single operation it is extremely likely that\n"
1804 "the package is simply not installable and a bug report against\n"
1805 "that package should be filed.") << endl;
1809 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1811 ShowBroken(c1out
,Cache
,false);
1812 return _error
->Error(_("Broken packages"));
1815 if (!DoAutomaticRemove(Cache
))
1818 /* Print out a list of packages that are going to be installed extra
1819 to what the user asked */
1820 if (Cache
->InstCount() != verset
[MOD_INSTALL
].size())
1823 string VersionsList
;
1824 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1826 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1827 if ((*Cache
)[I
].Install() == false)
1831 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1832 if (strcmp(*J
,I
.Name()) == 0)
1836 List
+= I
.FullName(true) + " ";
1837 VersionsList
+= string(Cache
[I
].CandVersion
) + "\n";
1841 ShowList(c1out
,_("The following extra packages will be installed:"),List
,VersionsList
);
1844 /* Print out a list of suggested and recommended packages */
1846 string SuggestsList
, RecommendsList
, List
;
1847 string SuggestsVersions
, RecommendsVersions
;
1848 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1850 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
1852 /* Just look at the ones we want to install */
1853 if ((*Cache
)[Pkg
].Install() == false)
1856 // get the recommends/suggests for the candidate ver
1857 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1858 for (pkgCache::DepIterator D
= CV
.DependsList(); D
.end() == false; )
1860 pkgCache::DepIterator Start
;
1861 pkgCache::DepIterator End
;
1862 D
.GlobOr(Start
,End
); // advances D
1864 // FIXME: we really should display a or-group as a or-group to the user
1865 // the problem is that ShowList is incapable of doing this
1866 string RecommendsOrList
,RecommendsOrVersions
;
1867 string SuggestsOrList
,SuggestsOrVersions
;
1868 bool foundInstalledInOrGroup
= false;
1871 /* Skip if package is installed already, or is about to be */
1872 string target
= Start
.TargetPkg().FullName(true) + " ";
1873 pkgCache::PkgIterator
const TarPkg
= Start
.TargetPkg();
1874 if (TarPkg
->SelectedState
== pkgCache::State::Install
||
1875 TarPkg
->SelectedState
== pkgCache::State::Hold
||
1876 Cache
[Start
.TargetPkg()].Install())
1878 foundInstalledInOrGroup
=true;
1882 /* Skip if we already saw it */
1883 if (int(SuggestsList
.find(target
)) != -1 || int(RecommendsList
.find(target
)) != -1)
1885 foundInstalledInOrGroup
=true;
1889 // this is a dep on a virtual pkg, check if any package that provides it
1890 // should be installed
1891 if(Start
.TargetPkg().ProvidesList() != 0)
1893 pkgCache::PrvIterator I
= Start
.TargetPkg().ProvidesList();
1894 for (; I
.end() == false; I
++)
1896 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
1897 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer() &&
1898 Pkg
.CurrentVer() != 0)
1899 foundInstalledInOrGroup
=true;
1903 if (Start
->Type
== pkgCache::Dep::Suggests
)
1905 SuggestsOrList
+= target
;
1906 SuggestsOrVersions
+= string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
1909 if (Start
->Type
== pkgCache::Dep::Recommends
)
1911 RecommendsOrList
+= target
;
1912 RecommendsOrVersions
+= string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
1920 if(foundInstalledInOrGroup
== false)
1922 RecommendsList
+= RecommendsOrList
;
1923 RecommendsVersions
+= RecommendsOrVersions
;
1924 SuggestsList
+= SuggestsOrList
;
1925 SuggestsVersions
+= SuggestsOrVersions
;
1931 ShowList(c1out
,_("Suggested packages:"),SuggestsList
,SuggestsVersions
);
1932 ShowList(c1out
,_("Recommended packages:"),RecommendsList
,RecommendsVersions
);
1936 // if nothing changed in the cache, but only the automark information
1937 // we write the StateFile here, otherwise it will be written in
1939 if (InstallAction
.AutoMarkChanged
> 0 &&
1940 Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
1941 Cache
->BadCount() == 0 &&
1942 _config
->FindB("APT::Get::Simulate",false) == false)
1943 Cache
->writeStateFile(NULL
);
1945 // See if we need to prompt
1946 // FIXME: check if really the packages in the set are going to be installed
1947 if (Cache
->InstCount() == verset
[MOD_INSTALL
].size() && Cache
->DelCount() == 0)
1948 return InstallPackages(Cache
,false,false);
1950 return InstallPackages(Cache
,false);
1953 /* mark packages as automatically/manually installed. */
1954 bool DoMarkAuto(CommandLine
&CmdL
)
1957 int AutoMarkChanged
= 0;
1958 OpTextProgress progress
;
1960 if (Cache
.Open() == false)
1963 if (strcasecmp(CmdL
.FileList
[0],"markauto") == 0)
1965 else if (strcasecmp(CmdL
.FileList
[0],"unmarkauto") == 0)
1968 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1971 // Locate the package
1972 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
1973 if (Pkg
.end() == true) {
1974 return _error
->Error(_("Couldn't find package %s"),S
);
1979 ioprintf(c1out
,_("%s set to manually installed.\n"), Pkg
.Name());
1981 ioprintf(c1out
,_("%s set to automatically installed.\n"),
1984 Cache
->MarkAuto(Pkg
,Action
);
1988 if (AutoMarkChanged
&& ! _config
->FindB("APT::Get::Simulate",false))
1989 return Cache
->writeStateFile(NULL
);
1993 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1994 // ---------------------------------------------------------------------
1995 /* Intelligent upgrader that will install and remove packages at will */
1996 bool DoDistUpgrade(CommandLine
&CmdL
)
1999 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
2002 c0out
<< _("Calculating upgrade... ") << flush
;
2003 if (pkgDistUpgrade(*Cache
) == false)
2005 c0out
<< _("Failed") << endl
;
2006 ShowBroken(c1out
,Cache
,false);
2010 c0out
<< _("Done") << endl
;
2012 return InstallPackages(Cache
,true);
2015 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
2016 // ---------------------------------------------------------------------
2017 /* Follows dselect's selections */
2018 bool DoDSelectUpgrade(CommandLine
&CmdL
)
2021 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
2024 pkgDepCache::ActionGroup
group(Cache
);
2026 // Install everything with the install flag set
2027 pkgCache::PkgIterator I
= Cache
->PkgBegin();
2028 for (;I
.end() != true; I
++)
2030 /* Install the package only if it is a new install, the autoupgrader
2031 will deal with the rest */
2032 if (I
->SelectedState
== pkgCache::State::Install
)
2033 Cache
->MarkInstall(I
,false);
2036 /* Now install their deps too, if we do this above then order of
2037 the status file is significant for | groups */
2038 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
2040 /* Install the package only if it is a new install, the autoupgrader
2041 will deal with the rest */
2042 if (I
->SelectedState
== pkgCache::State::Install
)
2043 Cache
->MarkInstall(I
,true);
2046 // Apply erasures now, they override everything else.
2047 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
2050 if (I
->SelectedState
== pkgCache::State::DeInstall
||
2051 I
->SelectedState
== pkgCache::State::Purge
)
2052 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
2055 /* Resolve any problems that dselect created, allupgrade cannot handle
2056 such things. We do so quite agressively too.. */
2057 if (Cache
->BrokenCount() != 0)
2059 pkgProblemResolver
Fix(Cache
);
2061 // Hold back held packages.
2062 if (_config
->FindB("APT::Ignore-Hold",false) == false)
2064 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
2066 if (I
->SelectedState
== pkgCache::State::Hold
)
2074 if (Fix
.Resolve() == false)
2076 ShowBroken(c1out
,Cache
,false);
2077 return _error
->Error(_("Internal error, problem resolver broke stuff"));
2081 // Now upgrade everything
2082 if (pkgAllUpgrade(Cache
) == false)
2084 ShowBroken(c1out
,Cache
,false);
2085 return _error
->Error(_("Internal error, problem resolver broke stuff"));
2088 return InstallPackages(Cache
,false);
2091 // DoClean - Remove download archives /*{{{*/
2092 // ---------------------------------------------------------------------
2094 bool DoClean(CommandLine
&CmdL
)
2096 if (_config
->FindB("APT::Get::Simulate") == true)
2098 cout
<< "Del " << _config
->FindDir("Dir::Cache::archives") << "* " <<
2099 _config
->FindDir("Dir::Cache::archives") << "partial/*" << endl
;
2103 // Lock the archive directory
2105 if (_config
->FindB("Debug::NoLocking",false) == false)
2107 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
2108 if (_error
->PendingError() == true)
2109 return _error
->Error(_("Unable to lock the download directory"));
2113 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
2114 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
2118 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
2119 // ---------------------------------------------------------------------
2120 /* This is similar to clean but it only purges things that cannot be
2121 downloaded, that is old versions of cached packages. */
2122 class LogCleaner
: public pkgArchiveCleaner
2125 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
2127 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
2129 if (_config
->FindB("APT::Get::Simulate") == false)
2134 bool DoAutoClean(CommandLine
&CmdL
)
2136 // Lock the archive directory
2138 if (_config
->FindB("Debug::NoLocking",false) == false)
2140 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
2141 if (_error
->PendingError() == true)
2142 return _error
->Error(_("Unable to lock the download directory"));
2146 if (Cache
.Open() == false)
2151 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
2152 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
2155 // DoCheck - Perform the check operation /*{{{*/
2156 // ---------------------------------------------------------------------
2157 /* Opening automatically checks the system, this command is mostly used
2159 bool DoCheck(CommandLine
&CmdL
)
2168 // DoSource - Fetch a source archive /*{{{*/
2169 // ---------------------------------------------------------------------
2170 /* Fetch souce packages */
2178 bool DoSource(CommandLine
&CmdL
)
2181 if (Cache
.Open(false) == false)
2184 if (CmdL
.FileSize() <= 1)
2185 return _error
->Error(_("Must specify at least one package to fetch source for"));
2187 // Read the source list
2189 if (List
.ReadMainList() == false)
2190 return _error
->Error(_("The list of sources could not be read."));
2192 // Create the text record parsers
2193 pkgRecords
Recs(Cache
);
2194 pkgSrcRecords
SrcRecs(List
);
2195 if (_error
->PendingError() == true)
2198 // Create the download object
2199 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
2201 if (Fetcher
.Setup(&Stat
) == false)
2204 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
2206 // insert all downloaded uris into this set to avoid downloading them
2210 // Diff only mode only fetches .diff files
2211 bool const diffOnly
= _config
->FindB("APT::Get::Diff-Only", false);
2212 // Tar only mode only fetches .tar files
2213 bool const tarOnly
= _config
->FindB("APT::Get::Tar-Only", false);
2214 // Dsc only mode only fetches .dsc files
2215 bool const dscOnly
= _config
->FindB("APT::Get::Dsc-Only", false);
2217 // Load the requestd sources into the fetcher
2219 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
2222 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
2225 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
2227 string srec
= Last
->AsStr();
2228 string::size_type pos
= srec
.find("\nVcs-");
2229 while (pos
!= string::npos
)
2231 pos
+= strlen("\nVcs-");
2232 string vcs
= srec
.substr(pos
,srec
.find(":",pos
)-pos
);
2233 if(vcs
== "Browser")
2235 pos
= srec
.find("\nVcs-", pos
);
2238 pos
+= vcs
.length()+2;
2239 string::size_type epos
= srec
.find("\n", pos
);
2240 string uri
= srec
.substr(pos
,epos
-pos
).c_str();
2241 ioprintf(c1out
, _("NOTICE: '%s' packaging is maintained in "
2242 "the '%s' version control system at:\n"
2244 Src
.c_str(), vcs
.c_str(), uri
.c_str());
2246 ioprintf(c1out
,_("Please use:\n"
2248 "to retrieve the latest (possibly unreleased) "
2249 "updates to the package.\n"),
2255 vector
<pkgSrcRecords::File
> Lst
;
2256 if (Last
->Files(Lst
) == false)
2259 // Load them into the fetcher
2260 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
2261 I
!= Lst
.end(); I
++)
2263 // Try to guess what sort of file it is we are getting.
2264 if (I
->Type
== "dsc")
2266 Dsc
[J
].Package
= Last
->Package();
2267 Dsc
[J
].Version
= Last
->Version();
2268 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
2271 // Handle the only options so that multiple can be used at once
2272 if (diffOnly
== true || tarOnly
== true || dscOnly
== true)
2274 if ((diffOnly
== true && I
->Type
== "diff") ||
2275 (tarOnly
== true && I
->Type
== "tar") ||
2276 (dscOnly
== true && I
->Type
== "dsc"))
2277 ; // Fine, we want this file downloaded
2282 // don't download the same uri twice (should this be moved to
2283 // the fetcher interface itself?)
2284 if(queued
.find(Last
->Index().ArchiveURI(I
->Path
)) != queued
.end())
2286 queued
.insert(Last
->Index().ArchiveURI(I
->Path
));
2288 // check if we have a file with that md5 sum already localy
2289 if(!I
->MD5Hash
.empty() && FileExists(flNotDir(I
->Path
)))
2291 FileFd
Fd(flNotDir(I
->Path
), FileFd::ReadOnly
);
2293 sum
.AddFD(Fd
.Fd(), Fd
.Size());
2295 if((string
)sum
.Result() == I
->MD5Hash
)
2297 ioprintf(c1out
,_("Skipping already downloaded file '%s'\n"),
2298 flNotDir(I
->Path
).c_str());
2303 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
2305 Last
->Index().SourceInfo(*Last
,*I
),Src
);
2309 // Display statistics
2310 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
2311 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
2312 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
2314 // Check for enough free space
2316 string OutputDir
= ".";
2317 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
2318 if (errno
== EOVERFLOW
)
2319 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
2322 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
2324 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
2327 if (statfs(OutputDir
.c_str(),&Stat
) != 0
2328 #if HAVE_STRUCT_STATFS_F_TYPE
2329 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
2332 return _error
->Error(_("You don't have enough free space in %s"),
2337 if (DebBytes
!= FetchBytes
)
2338 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
2339 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
2341 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
2342 SizeToStr(DebBytes
).c_str());
2344 if (_config
->FindB("APT::Get::Simulate",false) == true)
2346 for (unsigned I
= 0; I
!= J
; I
++)
2347 ioprintf(cout
,_("Fetch source %s\n"),Dsc
[I
].Package
.c_str());
2352 // Just print out the uris an exit if the --print-uris flag was used
2353 if (_config
->FindB("APT::Get::Print-URIs") == true)
2355 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
2356 for (; I
!= Fetcher
.UriEnd(); I
++)
2357 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
2358 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
2364 if (Fetcher
.Run() == pkgAcquire::Failed
)
2367 // Print error messages
2368 bool Failed
= false;
2369 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
2371 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
2372 (*I
)->Complete
== true)
2375 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
2376 (*I
)->ErrorText
.c_str());
2380 return _error
->Error(_("Failed to fetch some archives."));
2382 if (_config
->FindB("APT::Get::Download-only",false) == true)
2384 c1out
<< _("Download complete and in download only mode") << endl
;
2389 // Unpack the sources
2390 pid_t Process
= ExecFork();
2394 bool const fixBroken
= _config
->FindB("APT::Get::Fix-Broken", false);
2395 for (unsigned I
= 0; I
!= J
; I
++)
2397 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
2399 // Diff only mode only fetches .diff files
2400 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
2401 _config
->FindB("APT::Get::Tar-Only",false) == true ||
2402 Dsc
[I
].Dsc
.empty() == true)
2405 // See if the package is already unpacked
2407 if (fixBroken
== false && stat(Dir
.c_str(),&Stat
) == 0 &&
2408 S_ISDIR(Stat
.st_mode
) != 0)
2410 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
2417 snprintf(S
,sizeof(S
),"%s -x %s",
2418 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
2419 Dsc
[I
].Dsc
.c_str());
2422 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
2423 fprintf(stderr
,_("Check if the 'dpkg-dev' package is installed.\n"));
2428 // Try to compile it with dpkg-buildpackage
2429 if (_config
->FindB("APT::Get::Compile",false) == true)
2431 // Call dpkg-buildpackage
2433 snprintf(S
,sizeof(S
),"cd %s && %s %s",
2435 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
2436 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
2440 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
2450 // Wait for the subprocess
2452 while (waitpid(Process
,&Status
,0) != Process
)
2456 return _error
->Errno("waitpid","Couldn't wait for subprocess");
2459 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
2460 return _error
->Error(_("Child process failed"));
2465 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
2466 // ---------------------------------------------------------------------
2467 /* This function will look at the build depends list of the given source
2468 package and install the necessary packages to make it true, or fail. */
2469 bool DoBuildDep(CommandLine
&CmdL
)
2472 if (Cache
.Open(true) == false)
2475 if (CmdL
.FileSize() <= 1)
2476 return _error
->Error(_("Must specify at least one package to check builddeps for"));
2478 // Read the source list
2480 if (List
.ReadMainList() == false)
2481 return _error
->Error(_("The list of sources could not be read."));
2483 // Create the text record parsers
2484 pkgRecords
Recs(Cache
);
2485 pkgSrcRecords
SrcRecs(List
);
2486 if (_error
->PendingError() == true)
2489 // Create the download object
2490 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
2492 if (Fetcher
.Setup(&Stat
) == false)
2496 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
2499 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
2501 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
2503 // Process the build-dependencies
2504 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
2505 if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only",true)) == false)
2506 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
2508 // Also ensure that build-essential packages are present
2509 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
2512 for (; Opts
; Opts
= Opts
->Next
)
2514 if (Opts
->Value
.empty() == true)
2517 pkgSrcRecords::Parser::BuildDepRec rec
;
2518 rec
.Package
= Opts
->Value
;
2519 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
2521 BuildDeps
.push_back(rec
);
2524 if (BuildDeps
.size() == 0)
2526 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
2530 // Install the requested packages
2531 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
2532 pkgProblemResolver
Fix(Cache
);
2533 bool skipAlternatives
= false; // skip remaining alternatives in an or group
2534 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); D
++)
2536 bool hasAlternatives
= (((*D
).Op
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
);
2538 if (skipAlternatives
== true)
2540 if (!hasAlternatives
)
2541 skipAlternatives
= false; // end of or group
2545 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
2546 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
2548 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
2549 // Build-conflicts on unknown packages are silently ignored
2550 if (Pkg
.end() == true)
2553 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
2556 * Remove if we have an installed version that satisfies the
2559 if (IV
.end() == false &&
2560 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2561 TryToInstallBuildDep(Pkg
,Cache
,Fix
,true,false);
2563 else // BuildDep || BuildDepIndep
2565 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
2566 if (_config
->FindB("Debug::BuildDeps",false) == true)
2567 cout
<< "Looking for " << (*D
).Package
<< "...\n";
2569 if (Pkg
.end() == true)
2571 if (_config
->FindB("Debug::BuildDeps",false) == true)
2572 cout
<< " (not found)" << (*D
).Package
<< endl
;
2574 if (hasAlternatives
)
2577 return _error
->Error(_("%s dependency for %s cannot be satisfied "
2578 "because the package %s cannot be found"),
2579 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
2580 (*D
).Package
.c_str());
2584 * if there are alternatives, we've already picked one, so skip
2587 * TODO: this means that if there's a build-dep on A|B and B is
2588 * installed, we'll still try to install A; more importantly,
2589 * if A is currently broken, we cannot go back and try B. To fix
2590 * this would require we do a Resolve cycle for each package we
2591 * add to the install list. Ugh
2595 * If this is a virtual package, we need to check the list of
2596 * packages that provide it and see if any of those are
2599 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
2600 for (; Prv
.end() != true; Prv
++)
2602 if (_config
->FindB("Debug::BuildDeps",false) == true)
2603 cout
<< " Checking provider " << Prv
.OwnerPkg().FullName() << endl
;
2605 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
2609 // Get installed version and version we are going to install
2610 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
2612 if ((*D
).Version
[0] != '\0') {
2613 // Versioned dependency
2615 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
2617 for (; CV
.end() != true; CV
++)
2619 if (Cache
->VS().CheckDep(CV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2622 if (CV
.end() == true)
2624 if (hasAlternatives
)
2630 return _error
->Error(_("%s dependency for %s cannot be satisfied "
2631 "because no available versions of package %s "
2632 "can satisfy version requirements"),
2633 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
2634 (*D
).Package
.c_str());
2640 // Only consider virtual packages if there is no versioned dependency
2641 if (Prv
.end() == false)
2643 if (_config
->FindB("Debug::BuildDeps",false) == true)
2644 cout
<< " Is provided by installed package " << Prv
.OwnerPkg().FullName() << endl
;
2645 skipAlternatives
= hasAlternatives
;
2650 if (IV
.end() == false)
2652 if (_config
->FindB("Debug::BuildDeps",false) == true)
2653 cout
<< " Is installed\n";
2655 if (Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2657 skipAlternatives
= hasAlternatives
;
2661 if (_config
->FindB("Debug::BuildDeps",false) == true)
2662 cout
<< " ...but the installed version doesn't meet the version requirement\n";
2664 if (((*D
).Op
& pkgCache::Dep::LessEq
) == pkgCache::Dep::LessEq
)
2666 return _error
->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
2667 Last
->BuildDepType((*D
).Type
),
2669 Pkg
.FullName(true).c_str());
2674 if (_config
->FindB("Debug::BuildDeps",false) == true)
2675 cout
<< " Trying to install " << (*D
).Package
<< endl
;
2677 if (TryToInstallBuildDep(Pkg
,Cache
,Fix
,false,false) == true)
2679 // We successfully installed something; skip remaining alternatives
2680 skipAlternatives
= hasAlternatives
;
2681 if(_config
->FindB("APT::Get::Build-Dep-Automatic", false) == true)
2682 Cache
->MarkAuto(Pkg
, true);
2685 else if (hasAlternatives
)
2687 if (_config
->FindB("Debug::BuildDeps",false) == true)
2688 cout
<< " Unsatisfiable, trying alternatives\n";
2693 return _error
->Error(_("Failed to satisfy %s dependency for %s: %s"),
2694 Last
->BuildDepType((*D
).Type
),
2696 (*D
).Package
.c_str());
2701 Fix
.InstallProtect();
2702 if (Fix
.Resolve(true) == false)
2705 // Now we check the state of the packages,
2706 if (Cache
->BrokenCount() != 0)
2708 ShowBroken(cout
, Cache
, false);
2709 return _error
->Error(_("Build-dependencies for %s could not be satisfied."),*I
);
2713 if (InstallPackages(Cache
, false, true) == false)
2714 return _error
->Error(_("Failed to process build dependencies"));
2718 // DoMoo - Never Ask, Never Tell /*{{{*/
2719 // ---------------------------------------------------------------------
2721 bool DoMoo(CommandLine
&CmdL
)
2730 "....\"Have you mooed today?\"...\n";
2735 // ShowHelp - Show a help screen /*{{{*/
2736 // ---------------------------------------------------------------------
2738 bool ShowHelp(CommandLine
&CmdL
)
2740 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,VERSION
,
2741 COMMON_ARCH
,__DATE__
,__TIME__
);
2743 if (_config
->FindB("version") == true)
2745 cout
<< _("Supported modules:") << endl
;
2747 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
2749 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
2750 if (_system
!= 0 && _system
->VS
== VS
)
2754 cout
<< "Ver: " << VS
->Label
<< endl
;
2756 /* Print out all the packaging systems that will work with
2758 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
2760 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
2765 if (Sys
->VS
->TestCompatibility(*VS
) == true)
2766 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
2770 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
2772 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
2773 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
2776 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
2778 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
2779 cout
<< " Idx: " << Type
->Label
<< endl
;
2786 _("Usage: apt-get [options] command\n"
2787 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
2788 " apt-get [options] source pkg1 [pkg2 ...]\n"
2790 "apt-get is a simple command line interface for downloading and\n"
2791 "installing packages. The most frequently used commands are update\n"
2795 " update - Retrieve new lists of packages\n"
2796 " upgrade - Perform an upgrade\n"
2797 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
2798 " remove - Remove packages\n"
2799 " autoremove - Remove automatically all unused packages\n"
2800 " purge - Remove packages and config files\n"
2801 " source - Download source archives\n"
2802 " build-dep - Configure build-dependencies for source packages\n"
2803 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
2804 " dselect-upgrade - Follow dselect selections\n"
2805 " clean - Erase downloaded archive files\n"
2806 " autoclean - Erase old downloaded archive files\n"
2807 " check - Verify that there are no broken dependencies\n"
2808 " markauto - Mark the given packages as automatically installed\n"
2809 " unmarkauto - Mark the given packages as manually installed\n"
2812 " -h This help text.\n"
2813 " -q Loggable output - no progress indicator\n"
2814 " -qq No output except for errors\n"
2815 " -d Download only - do NOT install or unpack archives\n"
2816 " -s No-act. Perform ordering simulation\n"
2817 " -y Assume Yes to all queries and do not prompt\n"
2818 " -f Attempt to correct a system with broken dependencies in place\n"
2819 " -m Attempt to continue if archives are unlocatable\n"
2820 " -u Show a list of upgraded packages as well\n"
2821 " -b Build the source package after fetching it\n"
2822 " -V Show verbose version numbers\n"
2823 " -c=? Read this configuration file\n"
2824 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
2825 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
2826 "pages for more information and options.\n"
2827 " This APT has Super Cow Powers.\n");
2831 // GetInitialize - Initialize things for apt-get /*{{{*/
2832 // ---------------------------------------------------------------------
2834 void GetInitialize()
2836 _config
->Set("quiet",0);
2837 _config
->Set("help",false);
2838 _config
->Set("APT::Get::Download-Only",false);
2839 _config
->Set("APT::Get::Simulate",false);
2840 _config
->Set("APT::Get::Assume-Yes",false);
2841 _config
->Set("APT::Get::Fix-Broken",false);
2842 _config
->Set("APT::Get::Force-Yes",false);
2843 _config
->Set("APT::Get::List-Cleanup",true);
2844 _config
->Set("APT::Get::AutomaticRemove",false);
2847 // SigWinch - Window size change signal handler /*{{{*/
2848 // ---------------------------------------------------------------------
2852 // Riped from GNU ls
2856 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
2857 ScreenWidth
= ws
.ws_col
- 1;
2861 int main(int argc
,const char *argv
[]) /*{{{*/
2863 CommandLine::Args Args
[] = {
2864 {'h',"help","help",0},
2865 {'v',"version","version",0},
2866 {'V',"verbose-versions","APT::Get::Show-Versions",0},
2867 {'q',"quiet","quiet",CommandLine::IntLevel
},
2868 {'q',"silent","quiet",CommandLine::IntLevel
},
2869 {'d',"download-only","APT::Get::Download-Only",0},
2870 {'b',"compile","APT::Get::Compile",0},
2871 {'b',"build","APT::Get::Compile",0},
2872 {'s',"simulate","APT::Get::Simulate",0},
2873 {'s',"just-print","APT::Get::Simulate",0},
2874 {'s',"recon","APT::Get::Simulate",0},
2875 {'s',"dry-run","APT::Get::Simulate",0},
2876 {'s',"no-act","APT::Get::Simulate",0},
2877 {'y',"yes","APT::Get::Assume-Yes",0},
2878 {'y',"assume-yes","APT::Get::Assume-Yes",0},
2879 {'f',"fix-broken","APT::Get::Fix-Broken",0},
2880 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
2881 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
2882 {'t',"target-release","APT::Default-Release",CommandLine::HasArg
},
2883 {'t',"default-release","APT::Default-Release",CommandLine::HasArg
},
2884 {0,"download","APT::Get::Download",0},
2885 {0,"fix-missing","APT::Get::Fix-Missing",0},
2886 {0,"ignore-hold","APT::Ignore-Hold",0},
2887 {0,"upgrade","APT::Get::upgrade",0},
2888 {0,"only-upgrade","APT::Get::Only-Upgrade",0},
2889 {0,"force-yes","APT::Get::force-yes",0},
2890 {0,"print-uris","APT::Get::Print-URIs",0},
2891 {0,"diff-only","APT::Get::Diff-Only",0},
2892 {0,"debian-only","APT::Get::Diff-Only",0},
2893 {0,"tar-only","APT::Get::Tar-Only",0},
2894 {0,"dsc-only","APT::Get::Dsc-Only",0},
2895 {0,"purge","APT::Get::Purge",0},
2896 {0,"list-cleanup","APT::Get::List-Cleanup",0},
2897 {0,"reinstall","APT::Get::ReInstall",0},
2898 {0,"trivial-only","APT::Get::Trivial-Only",0},
2899 {0,"remove","APT::Get::Remove",0},
2900 {0,"only-source","APT::Get::Only-Source",0},
2901 {0,"arch-only","APT::Get::Arch-Only",0},
2902 {0,"auto-remove","APT::Get::AutomaticRemove",0},
2903 {0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0},
2904 {0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean
},
2905 {0,"fix-policy","APT::Get::Fix-Policy-Broken",0},
2906 {'c',"config-file",0,CommandLine::ConfigFile
},
2907 {'o',"option",0,CommandLine::ArbItem
},
2909 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
2910 {"upgrade",&DoUpgrade
},
2911 {"install",&DoInstall
},
2912 {"remove",&DoInstall
},
2913 {"purge",&DoInstall
},
2914 {"autoremove",&DoInstall
},
2915 {"markauto",&DoMarkAuto
},
2916 {"unmarkauto",&DoMarkAuto
},
2917 {"dist-upgrade",&DoDistUpgrade
},
2918 {"dselect-upgrade",&DoDSelectUpgrade
},
2919 {"build-dep",&DoBuildDep
},
2921 {"autoclean",&DoAutoClean
},
2923 {"source",&DoSource
},
2928 // Set up gettext support
2929 setlocale(LC_ALL
,"");
2930 textdomain(PACKAGE
);
2932 // Parse the command line and initialize the package library
2933 CommandLine
CmdL(Args
,_config
);
2934 if (pkgInitConfig(*_config
) == false ||
2935 CmdL
.Parse(argc
,argv
) == false ||
2936 pkgInitSystem(*_config
,_system
) == false)
2938 if (_config
->FindB("version") == true)
2941 _error
->DumpErrors();
2945 // See if the help should be shown
2946 if (_config
->FindB("help") == true ||
2947 _config
->FindB("version") == true ||
2948 CmdL
.FileSize() == 0)
2954 // simulate user-friendly if apt-get has no root privileges
2955 if (getuid() != 0 && _config
->FindB("APT::Get::Simulate") == true)
2957 if (_config
->FindB("APT::Get::Show-User-Simulation-Note",true) == true)
2958 cout
<< _("NOTE: This is only a simulation!\n"
2959 " apt-get needs root privileges for real execution.\n"
2960 " Keep also in mind that locking is deactivated,\n"
2961 " so don't depend on the relevance to the real current situation!"
2963 _config
->Set("Debug::NoLocking",true);
2966 // Deal with stdout not being a tty
2967 if (!isatty(STDOUT_FILENO
) && _config
->FindI("quiet", -1) == -1)
2968 _config
->Set("quiet","1");
2970 // Setup the output streams
2971 c0out
.rdbuf(cout
.rdbuf());
2972 c1out
.rdbuf(cout
.rdbuf());
2973 c2out
.rdbuf(cout
.rdbuf());
2974 if (_config
->FindI("quiet",0) > 0)
2975 c0out
.rdbuf(devnull
.rdbuf());
2976 if (_config
->FindI("quiet",0) > 1)
2977 c1out
.rdbuf(devnull
.rdbuf());
2979 // Setup the signals
2980 signal(SIGPIPE
,SIG_IGN
);
2981 signal(SIGWINCH
,SigWinch
);
2984 // Match the operation
2985 CmdL
.DispatchArg(Cmds
);
2987 // Print any errors or warnings found during parsing
2988 bool const Errors
= _error
->PendingError();
2989 if (_config
->FindI("quiet",0) > 0)
2990 _error
->DumpErrors();
2992 _error
->DumpErrors(GlobalError::DEBUG
);
2993 return Errors
== true ? 100 : 0;