]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
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 // CacheFile::NameComp - QSort compare by name /*{{{*/
613 // ---------------------------------------------------------------------
615 pkgCache
*CacheFile::SortCache
= 0;
616 int CacheFile::NameComp(const void *a
,const void *b
)
618 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
619 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
621 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
622 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
624 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
627 // CacheFile::Sort - Sort by name /*{{{*/
628 // ---------------------------------------------------------------------
630 void CacheFile::Sort()
633 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
634 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
635 pkgCache::PkgIterator I
= Cache
->PkgBegin();
636 for (;I
.end() != true; I
++)
640 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
643 // CacheFile::CheckDeps - Open the cache file /*{{{*/
644 // ---------------------------------------------------------------------
645 /* This routine generates the caches and then opens the dependency cache
646 and verifies that the system is OK. */
647 bool CacheFile::CheckDeps(bool AllowBroken
)
649 bool FixBroken
= _config
->FindB("APT::Get::Fix-Broken",false);
651 if (_error
->PendingError() == true)
654 // Check that the system is OK
655 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
656 return _error
->Error("Internal error, non-zero counts");
658 // Apply corrections for half-installed packages
659 if (pkgApplyStatus(*DCache
) == false)
662 if (_config
->FindB("APT::Get::Fix-Policy-Broken",false) == true)
665 if ((DCache
->PolicyBrokenCount() > 0))
667 // upgrade all policy-broken packages with ForceImportantDeps=True
668 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); !I
.end(); I
++)
669 if ((*DCache
)[I
].NowPolicyBroken() == true)
670 DCache
->MarkInstall(I
,true,0, false, true);
675 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
678 // Attempt to fix broken things
679 if (FixBroken
== true)
681 c1out
<< _("Correcting dependencies...") << flush
;
682 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
684 c1out
<< _(" failed.") << endl
;
685 ShowBroken(c1out
,*this,true);
687 return _error
->Error(_("Unable to correct dependencies"));
689 if (pkgMinimizeUpgrade(*DCache
) == false)
690 return _error
->Error(_("Unable to minimize the upgrade set"));
692 c1out
<< _(" Done") << endl
;
696 c1out
<< _("You might want to run 'apt-get -f install' to correct these.") << endl
;
697 ShowBroken(c1out
,*this,true);
699 return _error
->Error(_("Unmet dependencies. Try using -f."));
705 // CheckAuth - check if each download comes form a trusted source /*{{{*/
706 // ---------------------------------------------------------------------
708 static bool CheckAuth(pkgAcquire
& Fetcher
)
710 string UntrustedList
;
711 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd(); ++I
)
713 if (!(*I
)->IsTrusted())
715 UntrustedList
+= string((*I
)->ShortDesc()) + " ";
719 if (UntrustedList
== "")
724 ShowList(c2out
,_("WARNING: The following packages cannot be authenticated!"),UntrustedList
,"");
726 if (_config
->FindB("APT::Get::AllowUnauthenticated",false) == true)
728 c2out
<< _("Authentication warning overridden.\n");
732 if (_config
->FindI("quiet",0) < 2
733 && _config
->FindB("APT::Get::Assume-Yes",false) == false)
735 c2out
<< _("Install these packages without verification [y/N]? ") << flush
;
736 if (!YnPrompt(false))
737 return _error
->Error(_("Some packages could not be authenticated"));
741 else if (_config
->FindB("APT::Get::Force-Yes",false) == true)
746 return _error
->Error(_("There are problems and -y was used without --force-yes"));
749 // InstallPackages - Actually download and install the packages /*{{{*/
750 // ---------------------------------------------------------------------
751 /* This displays the informative messages describing what is going to
752 happen and then calls the download routines */
753 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,
756 if (_config
->FindB("APT::Get::Purge",false) == true)
758 pkgCache::PkgIterator I
= Cache
->PkgBegin();
759 for (; I
.end() == false; I
++)
761 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
762 Cache
->MarkDelete(I
,true);
767 bool Essential
= false;
769 // Show all the various warning indicators
770 ShowDel(c1out
,Cache
);
771 ShowNew(c1out
,Cache
);
773 ShowKept(c1out
,Cache
);
774 Fail
|= !ShowHold(c1out
,Cache
);
775 if (_config
->FindB("APT::Get::Show-Upgraded",true) == true)
776 ShowUpgraded(c1out
,Cache
);
777 Fail
|= !ShowDowngraded(c1out
,Cache
);
778 if (_config
->FindB("APT::Get::Download-Only",false) == false)
779 Essential
= !ShowEssential(c1out
,Cache
);
784 if (Cache
->BrokenCount() != 0)
786 ShowBroken(c1out
,Cache
,false);
787 return _error
->Error(_("Internal error, InstallPackages was called with broken packages!"));
790 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
791 Cache
->BadCount() == 0)
795 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::Remove",true) == false)
796 return _error
->Error(_("Packages need to be removed but remove is disabled."));
798 // Run the simulator ..
799 if (_config
->FindB("APT::Get::Simulate") == true)
801 pkgSimulate
PM(Cache
);
802 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
803 pkgPackageManager::OrderResult Res
= PM
.DoInstall(status_fd
);
804 if (Res
== pkgPackageManager::Failed
)
806 if (Res
!= pkgPackageManager::Completed
)
807 return _error
->Error(_("Internal error, Ordering didn't finish"));
811 // Create the text record parser
812 pkgRecords
Recs(Cache
);
813 if (_error
->PendingError() == true)
816 // Create the download object
818 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
819 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
821 // force a hashsum for compatibility reasons
822 _config
->CndSet("Acquire::ForceHash", "md5sum");
823 if (Fetcher
.Setup(&Stat
, "") == false)
826 else if (Fetcher
.Setup(&Stat
, _config
->FindDir("Dir::Cache::Archives")) == false)
829 // Read the source list
831 if (List
.ReadMainList() == false)
832 return _error
->Error(_("The list of sources could not be read."));
834 // Create the package manager and prepare to download
835 SPtr
<pkgPackageManager
> PM
= _system
->CreatePM(Cache
);
836 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false ||
837 _error
->PendingError() == true)
840 // Display statistics
841 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
842 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
843 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
844 if (DebBytes
!= Cache
->DebSize())
846 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
847 c0out
<< _("How odd.. The sizes didn't match, email apt@packages.debian.org") << endl
;
851 if (DebBytes
!= FetchBytes
)
852 ioprintf(c1out
,_("Need to get %sB/%sB of archives.\n"),
853 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
854 else if (DebBytes
!= 0)
855 ioprintf(c1out
,_("Need to get %sB of archives.\n"),
856 SizeToStr(DebBytes
).c_str());
859 if (Cache
->UsrSize() >= 0)
860 ioprintf(c1out
,_("After this operation, %sB of additional disk space will be used.\n"),
861 SizeToStr(Cache
->UsrSize()).c_str());
863 ioprintf(c1out
,_("After this operation, %sB disk space will be freed.\n"),
864 SizeToStr(-1*Cache
->UsrSize()).c_str());
866 if (_error
->PendingError() == true)
869 /* Check for enough free space, but only if we are actually going to
871 if (_config
->FindB("APT::Get::Print-URIs") == false &&
872 _config
->FindB("APT::Get::Download",true) == true)
875 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
876 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
877 if (errno
== EOVERFLOW
)
878 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
881 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
883 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
886 if (statfs(OutputDir
.c_str(),&Stat
) != 0
887 #if HAVE_STRUCT_STATFS_F_TYPE
888 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
891 return _error
->Error(_("You don't have enough free space in %s."),
897 if (_config
->FindI("quiet",0) >= 2 ||
898 _config
->FindB("APT::Get::Assume-Yes",false) == true)
900 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
901 return _error
->Error(_("There are problems and -y was used without --force-yes"));
904 if (Essential
== true && Safety
== true)
906 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
907 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
909 const char *Prompt
= _("Yes, do as I say!");
911 _("You are about to do something potentially harmful.\n"
912 "To continue type in the phrase '%s'\n"
915 if (AnalPrompt(Prompt
) == false)
917 c2out
<< _("Abort.") << endl
;
923 // Prompt to continue
924 if (Ask
== true || Fail
== true)
926 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
927 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
929 if (_config
->FindI("quiet",0) < 2 &&
930 _config
->FindB("APT::Get::Assume-Yes",false) == false)
932 c2out
<< _("Do you want to continue [Y/n]? ") << flush
;
934 if (YnPrompt() == false)
936 c2out
<< _("Abort.") << endl
;
943 // Just print out the uris an exit if the --print-uris flag was used
944 if (_config
->FindB("APT::Get::Print-URIs") == true)
946 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
947 for (; I
!= Fetcher
.UriEnd(); I
++)
948 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
949 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
953 if (!CheckAuth(Fetcher
))
956 /* Unlock the dpkg lock if we are not going to be doing an install
958 if (_config
->FindB("APT::Get::Download-Only",false) == true)
964 bool Transient
= false;
965 if (_config
->FindB("APT::Get::Download",true) == false)
967 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
969 if ((*I
)->Local
== true)
975 // Close the item and check if it was found in cache
977 if ((*I
)->Complete
== false)
980 // Clear it out of the fetch list
982 I
= Fetcher
.ItemsBegin();
986 if (Fetcher
.Run() == pkgAcquire::Failed
)
991 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
993 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
994 (*I
)->Complete
== true)
997 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
1004 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1005 (*I
)->ErrorText
.c_str());
1009 /* If we are in no download mode and missing files and there were
1010 'failures' then the user must specify -m. Furthermore, there
1011 is no such thing as a transient error in no-download mode! */
1012 if (Transient
== true &&
1013 _config
->FindB("APT::Get::Download",true) == false)
1019 if (_config
->FindB("APT::Get::Download-Only",false) == true)
1021 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
1022 return _error
->Error(_("Some files failed to download"));
1023 c1out
<< _("Download complete and in download only mode") << endl
;
1027 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
1029 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
1032 if (Transient
== true && Failed
== true)
1033 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
1035 // Try to deal with missing package files
1036 if (Failed
== true && PM
->FixMissing() == false)
1038 cerr
<< _("Unable to correct missing packages.") << endl
;
1039 return _error
->Error(_("Aborting install."));
1043 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
1044 pkgPackageManager::OrderResult Res
= PM
->DoInstall(status_fd
);
1045 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
1047 if (Res
== pkgPackageManager::Completed
)
1050 // Reload the fetcher object and loop again for media swapping
1052 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false)
1058 std::set
<std::string
> const disappearedPkgs
= PM
->GetDisappearedPackages();
1059 if (disappearedPkgs
.empty() == true)
1063 for (std::set
<std::string
>::const_iterator d
= disappearedPkgs
.begin();
1064 d
!= disappearedPkgs
.end(); ++d
)
1065 disappear
.append(*d
).append(" ");
1067 ShowList(c1out
, P_("The following package disappeared from your system as\n"
1068 "all files have been overwritten by other packages:",
1069 "The following packages disappeared from your system as\n"
1070 "all files have been overwritten by other packages:", disappearedPkgs
.size()), disappear
, "");
1071 c0out
<< _("Note: This is done automatic and on purpose by dpkg.") << std::endl
;
1076 // TryToInstall - Try to install a single package /*{{{*/
1077 // ---------------------------------------------------------------------
1078 /* This used to be inlined in DoInstall, but with the advent of regex package
1079 name matching it was split out.. */
1080 bool TryToInstall(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
1081 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
1082 bool AllowFail
= true)
1085 // Handle the no-upgrade case
1086 if (_config
->FindB("APT::Get::upgrade",true) == false &&
1087 Pkg
->CurrentVer
!= 0)
1089 if (AllowFail
== true)
1090 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
1091 Pkg
.FullName(true).c_str());
1095 // Ignore request for install if package would be new
1096 if (_config
->FindB("APT::Get::Only-Upgrade", false) == true &&
1097 Pkg
->CurrentVer
== 0)
1099 if (AllowFail
== true)
1100 ioprintf(c1out
,_("Skipping %s, it is not installed and only upgrades are requested.\n"),
1105 // Check if there is something at all to install
1106 pkgDepCache::StateCache
&State
= Cache
[Pkg
];
1107 if (Remove
== true && Pkg
->CurrentVer
== 0)
1113 /* We want to continue searching for regex hits, so we return false here
1114 otherwise this is not really an error. */
1115 if (AllowFail
== false)
1118 ioprintf(c1out
,_("Package %s is not installed, so not removed\n"),Pkg
.FullName(true).c_str());
1122 if (State
.CandidateVer
== 0 && Remove
== false)
1124 if (AllowFail
== false)
1127 if (Pkg
->ProvidesList
!= 0)
1129 ioprintf(c1out
,_("Package %s is a virtual package provided by:\n"),
1130 Pkg
.FullName(true).c_str());
1132 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
1133 unsigned short provider
= 0;
1134 for (; I
.end() == false; I
++)
1136 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
1138 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer())
1140 c1out
<< " " << Pkg
.FullName(true) << " " << I
.OwnerVer().VerStr();
1141 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
1142 c1out
<< _(" [Installed]");
1147 // if we found no candidate which provide this package, show non-candidates
1149 for (I
= Pkg
.ProvidesList(); I
.end() == false; I
++)
1150 c1out
<< " " << I
.OwnerPkg().FullName(true) << " " << I
.OwnerVer().VerStr()
1151 << _(" [Not candidate version]") << endl
;
1153 c1out
<< _("You should explicitly select one to install.") << endl
;
1158 _("Package %s is not available, but is referred to by another package.\n"
1159 "This may mean that the package is missing, has been obsoleted, or\n"
1160 "is only available from another source\n"),Pkg
.FullName(true).c_str());
1163 string VersionsList
;
1164 SPtrArray
<bool> Seen
= new bool[Cache
.Head().PackageCount
];
1165 memset(Seen
,0,Cache
.Head().PackageCount
*sizeof(*Seen
));
1166 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
1167 for (; Dep
.end() == false; Dep
++)
1169 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
1171 if (Seen
[Dep
.ParentPkg()->ID
] == true)
1173 Seen
[Dep
.ParentPkg()->ID
] = true;
1174 List
+= Dep
.ParentPkg().FullName(true) + " ";
1175 //VersionsList += string(Dep.ParentPkg().CurVersion) + "\n"; ???
1177 ShowList(c1out
,_("However the following packages replace it:"),List
,VersionsList
);
1180 _error
->Error(_("Package %s has no installation candidate"),Pkg
.FullName(true).c_str());
1189 Cache
.MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
1194 Cache
.MarkInstall(Pkg
,false);
1195 if (State
.Install() == false)
1197 if (_config
->FindB("APT::Get::ReInstall",false) == true)
1199 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
1200 ioprintf(c1out
,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
1201 Pkg
.FullName(true).c_str());
1203 Cache
.SetReInstall(Pkg
,true);
1207 if (AllowFail
== true)
1208 ioprintf(c1out
,_("%s is already the newest version.\n"),
1209 Pkg
.FullName(true).c_str());
1213 // Install it with autoinstalling enabled (if we not respect the minial
1214 // required deps or the policy)
1215 if ((State
.InstBroken() == true || State
.InstPolicyBroken() == true) && BrokenFix
== false)
1216 Cache
.MarkInstall(Pkg
,true);
1221 // FindSrc - Find a source record /*{{{*/
1222 // ---------------------------------------------------------------------
1224 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
1225 pkgSrcRecords
&SrcRecs
,string
&Src
,
1229 string DefRel
= _config
->Find("APT::Default-Release");
1230 string TmpSrc
= Name
;
1232 // extract the version/release from the pkgname
1233 const size_t found
= TmpSrc
.find_last_of("/=");
1234 if (found
!= string::npos
) {
1235 if (TmpSrc
[found
] == '/')
1236 DefRel
= TmpSrc
.substr(found
+1);
1238 VerTag
= TmpSrc
.substr(found
+1);
1239 TmpSrc
= TmpSrc
.substr(0,found
);
1242 /* Lookup the version of the package we would install if we were to
1243 install a version and determine the source package name, then look
1244 in the archive for a source package of the same name. */
1245 bool MatchSrcOnly
= _config
->FindB("APT::Get::Only-Source");
1246 const pkgCache::PkgIterator Pkg
= Cache
.FindPkg(TmpSrc
);
1247 if (MatchSrcOnly
== false && Pkg
.end() == false)
1249 if(VerTag
.empty() == false || DefRel
.empty() == false)
1252 // we have a default release, try to locate the pkg. we do it like
1253 // this because GetCandidateVer() will not "downgrade", that means
1254 // "apt-get source -t stable apt" won't work on a unstable system
1255 for (pkgCache::VerIterator Ver
= Pkg
.VersionList();; Ver
++)
1257 // try first only exact matches, later fuzzy matches
1258 if (Ver
.end() == true)
1263 Ver
= Pkg
.VersionList();
1264 // exit right away from the Pkg.VersionList() loop if we
1265 // don't have any versions
1266 if (Ver
.end() == true)
1269 // We match against a concrete version (or a part of this version)
1270 if (VerTag
.empty() == false &&
1271 (fuzzy
== true || Cache
.VS().CmpVersion(VerTag
, Ver
.VerStr()) != 0) && // exact match
1272 (fuzzy
== false || strncmp(VerTag
.c_str(), Ver
.VerStr(), VerTag
.size()) != 0)) // fuzzy match
1275 for (pkgCache::VerFileIterator VF
= Ver
.FileList();
1276 VF
.end() == false; VF
++)
1278 /* If this is the status file, and the current version is not the
1279 version in the status file (ie it is not installed, or somesuch)
1280 then it is not a candidate for installation, ever. This weeds
1281 out bogus entries that may be due to config-file states, or
1283 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) ==
1284 pkgCache::Flag::NotSource
&& Pkg
.CurrentVer() != Ver
)
1287 // or we match against a release
1288 if(VerTag
.empty() == false ||
1289 (VF
.File().Archive() != 0 && VF
.File().Archive() == DefRel
) ||
1290 (VF
.File().Codename() != 0 && VF
.File().Codename() == DefRel
))
1292 pkgRecords::Parser
&Parse
= Recs
.Lookup(VF
);
1293 Src
= Parse
.SourcePkg();
1294 // no SourcePkg name, so it is the "binary" name
1295 if (Src
.empty() == true)
1297 // the Version we have is possibly fuzzy or includes binUploads,
1298 // so we use the Version of the SourcePkg (empty if same as package)
1299 VerTag
= Parse
.SourceVer();
1300 if (VerTag
.empty() == true)
1301 VerTag
= Ver
.VerStr();
1305 if (Src
.empty() == false)
1308 if (Src
.empty() == true)
1310 // Sources files have no codename information
1311 if (VerTag
.empty() == true && DefRel
.empty() == false)
1313 _error
->Error(_("Ignore unavailable target release '%s' of package '%s'"), DefRel
.c_str(), TmpSrc
.c_str());
1318 if (Src
.empty() == true)
1320 // if we don't have found a fitting package yet so we will
1321 // choose a good candidate and proceed with that.
1322 // Maybe we will find a source later on with the right VerTag
1323 pkgCache::VerIterator Ver
= Cache
.GetCandidateVer(Pkg
);
1324 if (Ver
.end() == false)
1326 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1327 Src
= Parse
.SourcePkg();
1328 if (VerTag
.empty() == true)
1329 VerTag
= Parse
.SourceVer();
1334 if (Src
.empty() == true)
1338 /* if we have a source pkg name, make sure to only search
1339 for srcpkg names, otherwise apt gets confused if there
1340 is a binary package "pkg1" and a source package "pkg1"
1341 with the same name but that comes from different packages */
1342 MatchSrcOnly
= true;
1345 ioprintf(c1out
, _("Picking '%s' as source package instead of '%s'\n"), Src
.c_str(), TmpSrc
.c_str());
1350 pkgSrcRecords::Parser
*Last
= 0;
1351 unsigned long Offset
= 0;
1354 /* Iterate over all of the hits, which includes the resulting
1355 binary packages in the search */
1356 pkgSrcRecords::Parser
*Parse
;
1360 while ((Parse
= SrcRecs
.Find(Src
.c_str(), MatchSrcOnly
)) != 0)
1362 const string Ver
= Parse
->Version();
1364 // Ignore all versions which doesn't fit
1365 if (VerTag
.empty() == false &&
1366 Cache
.VS().CmpVersion(VerTag
, Ver
) != 0) // exact match
1369 // Newer version or an exact match? Save the hit
1370 if (Last
== 0 || Cache
.VS().CmpVersion(Version
,Ver
) < 0) {
1372 Offset
= Parse
->Offset();
1376 // was the version check above an exact match? If so, we don't need to look further
1377 if (VerTag
.empty() == false && VerTag
.size() == Ver
.size())
1380 if (Last
!= 0 || VerTag
.empty() == true)
1382 //if (VerTag.empty() == false && Last == 0)
1383 _error
->Error(_("Ignore unavailable version '%s' of package '%s'"), VerTag
.c_str(), TmpSrc
.c_str());
1387 if (Last
== 0 || Last
->Jump(Offset
) == false)
1393 // DoUpdate - Update the package lists /*{{{*/
1394 // ---------------------------------------------------------------------
1396 bool DoUpdate(CommandLine
&CmdL
)
1398 if (CmdL
.FileSize() != 1)
1399 return _error
->Error(_("The update command takes no arguments"));
1401 // Get the source list
1403 if (List
.ReadMainList() == false)
1406 // Create the progress
1407 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1409 // Just print out the uris an exit if the --print-uris flag was used
1410 if (_config
->FindB("APT::Get::Print-URIs") == true)
1412 // force a hashsum for compatibility reasons
1413 _config
->CndSet("Acquire::ForceHash", "md5sum");
1417 if (Fetcher
.Setup(&Stat
) == false)
1420 // Populate it with the source selection and get all Indexes
1422 if (List
.GetIndexes(&Fetcher
,true) == false)
1425 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1426 for (; I
!= Fetcher
.UriEnd(); I
++)
1427 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1428 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
1434 if (_config
->FindB("APT::Get::Download",true) == true)
1435 ListUpdate(Stat
, List
);
1437 // Rebuild the cache.
1438 if (Cache
.BuildCaches() == false)
1444 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
1445 // ---------------------------------------------------------------------
1446 /* Remove unused automatic packages */
1447 bool DoAutomaticRemove(CacheFile
&Cache
)
1449 bool Debug
= _config
->FindI("Debug::pkgAutoRemove",false);
1450 bool doAutoRemove
= _config
->FindB("APT::Get::AutomaticRemove", false);
1451 bool hideAutoRemove
= _config
->FindB("APT::Get::HideAutoRemove");
1453 pkgDepCache::ActionGroup
group(*Cache
);
1455 std::cout
<< "DoAutomaticRemove()" << std::endl
;
1457 // we don't want to autoremove and we don't want to see it, so why calculating?
1458 if (doAutoRemove
== false && hideAutoRemove
== true)
1461 if (doAutoRemove
== true &&
1462 _config
->FindB("APT::Get::Remove",true) == false)
1464 c1out
<< _("We are not supposed to delete stuff, can't start "
1465 "AutoRemover") << std::endl
;
1469 bool purgePkgs
= _config
->FindB("APT::Get::Purge", false);
1470 bool smallList
= (hideAutoRemove
== false &&
1471 strcasecmp(_config
->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
1473 string autoremovelist
, autoremoveversions
;
1474 unsigned long autoRemoveCount
= 0;
1475 // look over the cache to see what can be removed
1476 for (pkgCache::PkgIterator Pkg
= Cache
->PkgBegin(); ! Pkg
.end(); ++Pkg
)
1478 if (Cache
[Pkg
].Garbage
)
1480 if(Pkg
.CurrentVer() != 0 || Cache
[Pkg
].Install())
1482 std::cout
<< "We could delete %s" << Pkg
.FullName(true).c_str() << std::endl
;
1486 if(Pkg
.CurrentVer() != 0 &&
1487 Pkg
->CurrentState
!= pkgCache::State::ConfigFiles
)
1488 Cache
->MarkDelete(Pkg
, purgePkgs
);
1490 Cache
->MarkKeep(Pkg
, false, false);
1494 // only show stuff in the list that is not yet marked for removal
1495 if(Cache
[Pkg
].Delete() == false)
1498 // we don't need to fill the strings if we don't need them
1499 if (smallList
== false)
1501 autoremovelist
+= Pkg
.FullName(true) + " ";
1502 autoremoveversions
+= string(Cache
[Pkg
].CandVersion
) + "\n";
1508 // if we don't remove them, we should show them!
1509 if (doAutoRemove
== false && (autoremovelist
.empty() == false || autoRemoveCount
!= 0))
1511 if (smallList
== false)
1512 ShowList(c1out
, P_("The following package is automatically installed and is no longer required:",
1513 "The following packages were automatically installed and are no longer required:",
1514 autoRemoveCount
), autoremovelist
, autoremoveversions
);
1516 ioprintf(c1out
, P_("%lu package was automatically installed and is no longer required.\n",
1517 "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount
), autoRemoveCount
);
1518 c1out
<< _("Use 'apt-get autoremove' to remove them.") << std::endl
;
1520 // Now see if we had destroyed anything (if we had done anything)
1521 else if (Cache
->BrokenCount() != 0)
1523 c1out
<< _("Hmm, seems like the AutoRemover destroyed something which really\n"
1524 "shouldn't happen. Please file a bug report against apt.") << endl
;
1526 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1528 ShowBroken(c1out
,Cache
,false);
1530 return _error
->Error(_("Internal Error, AutoRemover broke stuff"));
1535 // DoUpgrade - Upgrade all packages /*{{{*/
1536 // ---------------------------------------------------------------------
1537 /* Upgrade all packages without installing new packages or erasing old
1539 bool DoUpgrade(CommandLine
&CmdL
)
1542 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1546 if (pkgAllUpgrade(Cache
) == false)
1548 ShowBroken(c1out
,Cache
,false);
1549 return _error
->Error(_("Internal error, AllUpgrade broke stuff"));
1552 return InstallPackages(Cache
,true);
1555 // CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/
1556 class CacheSetHelperAPTGet
: public APT::CacheSetHelper
{
1557 /** \brief stream message should be printed to */
1559 /** \brief were things like Task or RegEx used to select packages? */
1560 bool explicitlyNamed
;
1563 CacheSetHelperAPTGet(std::ostream
&out
) : APT::CacheSetHelper(true), out(out
) {
1564 explicitlyNamed
= true;
1567 virtual void showTaskSelection(APT::PackageSet
const &pkgset
, string
const &pattern
) {
1568 for (APT::PackageSet::const_iterator Pkg
= pkgset
.begin(); Pkg
!= pkgset
.end(); ++Pkg
)
1569 ioprintf(out
, _("Note, selecting '%s' for task '%s'\n"),
1570 Pkg
.FullName(true).c_str(), pattern
.c_str());
1571 explicitlyNamed
= false;
1573 virtual void showRegExSelection(APT::PackageSet
const &pkgset
, string
const &pattern
) {
1574 for (APT::PackageSet::const_iterator Pkg
= pkgset
.begin(); Pkg
!= pkgset
.end(); ++Pkg
)
1575 ioprintf(out
, _("Note, selecting '%s' for regex '%s'\n"),
1576 Pkg
.FullName(true).c_str(), pattern
.c_str());
1577 explicitlyNamed
= false;
1579 virtual void showSelectedVersion(pkgCache::PkgIterator
const &Pkg
, pkgCache::VerIterator
const Ver
,
1580 string
const &ver
, bool const &verIsRel
) {
1581 if (ver
!= Ver
.VerStr())
1582 ioprintf(out
, _("Selected version '%s' (%s) for '%s'\n"),
1583 Ver
.VerStr(), Ver
.RelStr().c_str(), Pkg
.FullName(true).c_str());
1586 virtual APT::VersionSet
canNotFindCandInstVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
1587 return tryVirtualPackage(Cache
, Pkg
, APT::VersionSet::CANDINST
);
1590 virtual APT::VersionSet
canNotFindInstCandVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
1591 return tryVirtualPackage(Cache
, Pkg
, APT::VersionSet::INSTCAND
);
1594 APT::VersionSet
tryVirtualPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
,
1595 APT::VersionSet::Version
const &select
) {
1596 /* This is a pure virtual package and there is a single available
1597 candidate providing it. */
1598 if (unlikely(Cache
[Pkg
].CandidateVer
!= 0) || Pkg
->ProvidesList
== 0) {
1599 if (select
== APT::VersionSet::CANDINST
)
1600 return APT::CacheSetHelper::canNotFindCandInstVer(Cache
, Pkg
);
1601 return APT::CacheSetHelper::canNotFindInstCandVer(Cache
, Pkg
);
1604 pkgCache::PkgIterator Prov
;
1605 bool found_one
= false;
1606 for (pkgCache::PrvIterator P
= Pkg
.ProvidesList(); P
; ++P
) {
1607 pkgCache::VerIterator
const PVer
= P
.OwnerVer();
1608 pkgCache::PkgIterator
const PPkg
= PVer
.ParentPkg();
1610 /* Ignore versions that are not a candidate. */
1611 if (Cache
[PPkg
].CandidateVer
!= PVer
)
1614 if (found_one
== false) {
1617 } else if (PPkg
!= Prov
) {
1618 found_one
= false; // we found at least two
1623 if (found_one
== true) {
1624 ioprintf(out
, _("Note, selecting '%s' instead of '%s'\n"),
1625 Prov
.FullName(true).c_str(), Pkg
.FullName(true).c_str());
1626 return APT::VersionSet::FromPackage(Cache
, Prov
, select
, *this);
1628 if (select
== APT::VersionSet::CANDINST
)
1629 return APT::CacheSetHelper::canNotFindCandInstVer(Cache
, Pkg
);
1630 return APT::CacheSetHelper::canNotFindInstCandVer(Cache
, Pkg
);
1633 inline bool allPkgNamedExplicitly() const { return explicitlyNamed
; }
1637 // DoInstall - Install packages from the command line /*{{{*/
1638 // ---------------------------------------------------------------------
1639 /* Install named packages */
1640 bool DoInstall(CommandLine
&CmdL
)
1643 if (Cache
.OpenForInstall() == false ||
1644 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
1647 // Enter the special broken fixing mode if the user specified arguments
1648 bool BrokenFix
= false;
1649 if (Cache
->BrokenCount() != 0)
1652 unsigned int AutoMarkChanged
= 0;
1653 pkgProblemResolver
Fix(Cache
);
1655 static const unsigned short MOD_REMOVE
= 1;
1656 static const unsigned short MOD_INSTALL
= 2;
1658 unsigned short fallback
= MOD_INSTALL
;
1659 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
1660 fallback
= MOD_REMOVE
;
1661 else if (strcasecmp(CmdL
.FileList
[0], "purge") == 0)
1663 _config
->Set("APT::Get::Purge", true);
1664 fallback
= MOD_REMOVE
;
1666 else if (strcasecmp(CmdL
.FileList
[0], "autoremove") == 0)
1668 _config
->Set("APT::Get::AutomaticRemove", "true");
1669 fallback
= MOD_REMOVE
;
1672 std::list
<APT::VersionSet::Modifier
> mods
;
1673 mods
.push_back(APT::VersionSet::Modifier(MOD_INSTALL
, "+",
1674 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::CANDINST
));
1675 mods
.push_back(APT::VersionSet::Modifier(MOD_REMOVE
, "-",
1676 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::INSTCAND
));
1677 CacheSetHelperAPTGet
helper(c0out
);
1678 std::map
<unsigned short, APT::VersionSet
> verset
= APT::VersionSet::GroupedFromCommandLine(Cache
,
1679 CmdL
.FileList
+ 1, mods
, fallback
, helper
);
1681 if (_error
->PendingError() == true)
1684 unsigned short order
[] = { 0, 0, 0 };
1685 if (fallback
== MOD_INSTALL
) {
1686 order
[0] = MOD_INSTALL
;
1687 order
[1] = MOD_REMOVE
;
1689 order
[0] = MOD_REMOVE
;
1690 order
[1] = MOD_INSTALL
;
1693 // new scope for the ActionGroup
1695 pkgDepCache::ActionGroup
group(Cache
);
1696 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
1698 if (order
[i
] == MOD_INSTALL
)
1699 for (APT::VersionSet::const_iterator Ver
= verset
[MOD_INSTALL
].begin();
1700 Ver
!= verset
[MOD_INSTALL
].end(); ++Ver
)
1702 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
1703 Cache
->SetCandidateVersion(Ver
);
1705 if (TryToInstall(Pkg
, Cache
, Fix
, false, BrokenFix
) == false)
1708 // see if we need to fix the auto-mark flag
1709 // e.g. apt-get install foo
1710 // where foo is marked automatic
1711 if (Cache
[Pkg
].Install() == false &&
1712 (Cache
[Pkg
].Flags
& pkgCache::Flag::Auto
) &&
1713 _config
->FindB("APT::Get::ReInstall",false) == false &&
1714 _config
->FindB("APT::Get::Only-Upgrade",false) == false &&
1715 _config
->FindB("APT::Get::Download-Only",false) == false)
1717 ioprintf(c1out
,_("%s set to manually installed.\n"),
1718 Pkg
.FullName(true).c_str());
1719 Cache
->MarkAuto(Pkg
,false);
1723 else if (order
[i
] == MOD_REMOVE
)
1724 for (APT::VersionSet::const_iterator Ver
= verset
[MOD_REMOVE
].begin();
1725 Ver
!= verset
[MOD_REMOVE
].end(); ++Ver
)
1727 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
1729 if (TryToInstall(Pkg
, Cache
, Fix
, true, BrokenFix
) == false)
1734 if (_error
->PendingError() == true)
1737 /* If we are in the Broken fixing mode we do not attempt to fix the
1738 problems. This is if the user invoked install without -f and gave
1740 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1742 c1out
<< _("You might want to run 'apt-get -f install' to correct these:") << endl
;
1743 ShowBroken(c1out
,Cache
,false);
1745 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1748 // Call the scored problem resolver
1749 Fix
.InstallProtect();
1750 if (Fix
.Resolve(true) == false)
1753 // Now we check the state of the packages,
1754 if (Cache
->BrokenCount() != 0)
1757 _("Some packages could not be installed. This may mean that you have\n"
1758 "requested an impossible situation or if you are using the unstable\n"
1759 "distribution that some required packages have not yet been created\n"
1760 "or been moved out of Incoming.") << endl
;
1766 _("Since you only requested a single operation it is extremely likely that\n"
1767 "the package is simply not installable and a bug report against\n"
1768 "that package should be filed.") << endl;
1772 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1774 ShowBroken(c1out
,Cache
,false);
1775 return _error
->Error(_("Broken packages"));
1778 if (!DoAutomaticRemove(Cache
))
1781 /* Print out a list of packages that are going to be installed extra
1782 to what the user asked */
1783 if (Cache
->InstCount() != verset
[MOD_INSTALL
].size())
1786 string VersionsList
;
1787 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1789 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1790 if ((*Cache
)[I
].Install() == false)
1794 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1795 if (strcmp(*J
,I
.Name()) == 0)
1799 List
+= I
.FullName(true) + " ";
1800 VersionsList
+= string(Cache
[I
].CandVersion
) + "\n";
1804 ShowList(c1out
,_("The following extra packages will be installed:"),List
,VersionsList
);
1807 /* Print out a list of suggested and recommended packages */
1809 string SuggestsList
, RecommendsList
, List
;
1810 string SuggestsVersions
, RecommendsVersions
;
1811 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1813 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
1815 /* Just look at the ones we want to install */
1816 if ((*Cache
)[Pkg
].Install() == false)
1819 // get the recommends/suggests for the candidate ver
1820 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1821 for (pkgCache::DepIterator D
= CV
.DependsList(); D
.end() == false; )
1823 pkgCache::DepIterator Start
;
1824 pkgCache::DepIterator End
;
1825 D
.GlobOr(Start
,End
); // advances D
1827 // FIXME: we really should display a or-group as a or-group to the user
1828 // the problem is that ShowList is incapable of doing this
1829 string RecommendsOrList
,RecommendsOrVersions
;
1830 string SuggestsOrList
,SuggestsOrVersions
;
1831 bool foundInstalledInOrGroup
= false;
1834 /* Skip if package is installed already, or is about to be */
1835 string target
= Start
.TargetPkg().FullName(true) + " ";
1836 pkgCache::PkgIterator
const TarPkg
= Start
.TargetPkg();
1837 if (TarPkg
->SelectedState
== pkgCache::State::Install
||
1838 TarPkg
->SelectedState
== pkgCache::State::Hold
||
1839 Cache
[Start
.TargetPkg()].Install())
1841 foundInstalledInOrGroup
=true;
1845 /* Skip if we already saw it */
1846 if (int(SuggestsList
.find(target
)) != -1 || int(RecommendsList
.find(target
)) != -1)
1848 foundInstalledInOrGroup
=true;
1852 // this is a dep on a virtual pkg, check if any package that provides it
1853 // should be installed
1854 if(Start
.TargetPkg().ProvidesList() != 0)
1856 pkgCache::PrvIterator I
= Start
.TargetPkg().ProvidesList();
1857 for (; I
.end() == false; I
++)
1859 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
1860 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer() &&
1861 Pkg
.CurrentVer() != 0)
1862 foundInstalledInOrGroup
=true;
1866 if (Start
->Type
== pkgCache::Dep::Suggests
)
1868 SuggestsOrList
+= target
;
1869 SuggestsOrVersions
+= string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
1872 if (Start
->Type
== pkgCache::Dep::Recommends
)
1874 RecommendsOrList
+= target
;
1875 RecommendsOrVersions
+= string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
1883 if(foundInstalledInOrGroup
== false)
1885 RecommendsList
+= RecommendsOrList
;
1886 RecommendsVersions
+= RecommendsOrVersions
;
1887 SuggestsList
+= SuggestsOrList
;
1888 SuggestsVersions
+= SuggestsOrVersions
;
1894 ShowList(c1out
,_("Suggested packages:"),SuggestsList
,SuggestsVersions
);
1895 ShowList(c1out
,_("Recommended packages:"),RecommendsList
,RecommendsVersions
);
1899 // if nothing changed in the cache, but only the automark information
1900 // we write the StateFile here, otherwise it will be written in
1902 if (AutoMarkChanged
> 0 &&
1903 Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
1904 Cache
->BadCount() == 0 &&
1905 _config
->FindB("APT::Get::Simulate",false) == false)
1906 Cache
->writeStateFile(NULL
);
1908 // See if we need to prompt
1909 // FIXME: check if really the packages in the set are going to be installed
1910 if (Cache
->InstCount() == verset
[MOD_INSTALL
].size() && Cache
->DelCount() == 0)
1911 return InstallPackages(Cache
,false,false);
1913 return InstallPackages(Cache
,false);
1916 /* mark packages as automatically/manually installed. */
1917 bool DoMarkAuto(CommandLine
&CmdL
)
1920 int AutoMarkChanged
= 0;
1921 OpTextProgress progress
;
1923 if (Cache
.Open() == false)
1926 if (strcasecmp(CmdL
.FileList
[0],"markauto") == 0)
1928 else if (strcasecmp(CmdL
.FileList
[0],"unmarkauto") == 0)
1931 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1934 // Locate the package
1935 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
1936 if (Pkg
.end() == true) {
1937 return _error
->Error(_("Couldn't find package %s"),S
);
1942 ioprintf(c1out
,_("%s set to manually installed.\n"), Pkg
.Name());
1944 ioprintf(c1out
,_("%s set to automatically installed.\n"),
1947 Cache
->MarkAuto(Pkg
,Action
);
1951 if (AutoMarkChanged
&& ! _config
->FindB("APT::Get::Simulate",false))
1952 return Cache
->writeStateFile(NULL
);
1956 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1957 // ---------------------------------------------------------------------
1958 /* Intelligent upgrader that will install and remove packages at will */
1959 bool DoDistUpgrade(CommandLine
&CmdL
)
1962 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1965 c0out
<< _("Calculating upgrade... ") << flush
;
1966 if (pkgDistUpgrade(*Cache
) == false)
1968 c0out
<< _("Failed") << endl
;
1969 ShowBroken(c1out
,Cache
,false);
1973 c0out
<< _("Done") << endl
;
1975 return InstallPackages(Cache
,true);
1978 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1979 // ---------------------------------------------------------------------
1980 /* Follows dselect's selections */
1981 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1984 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1987 pkgDepCache::ActionGroup
group(Cache
);
1989 // Install everything with the install flag set
1990 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1991 for (;I
.end() != true; I
++)
1993 /* Install the package only if it is a new install, the autoupgrader
1994 will deal with the rest */
1995 if (I
->SelectedState
== pkgCache::State::Install
)
1996 Cache
->MarkInstall(I
,false);
1999 /* Now install their deps too, if we do this above then order of
2000 the status file is significant for | groups */
2001 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
2003 /* Install the package only if it is a new install, the autoupgrader
2004 will deal with the rest */
2005 if (I
->SelectedState
== pkgCache::State::Install
)
2006 Cache
->MarkInstall(I
,true);
2009 // Apply erasures now, they override everything else.
2010 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
2013 if (I
->SelectedState
== pkgCache::State::DeInstall
||
2014 I
->SelectedState
== pkgCache::State::Purge
)
2015 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
2018 /* Resolve any problems that dselect created, allupgrade cannot handle
2019 such things. We do so quite agressively too.. */
2020 if (Cache
->BrokenCount() != 0)
2022 pkgProblemResolver
Fix(Cache
);
2024 // Hold back held packages.
2025 if (_config
->FindB("APT::Ignore-Hold",false) == false)
2027 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
2029 if (I
->SelectedState
== pkgCache::State::Hold
)
2037 if (Fix
.Resolve() == false)
2039 ShowBroken(c1out
,Cache
,false);
2040 return _error
->Error(_("Internal error, problem resolver broke stuff"));
2044 // Now upgrade everything
2045 if (pkgAllUpgrade(Cache
) == false)
2047 ShowBroken(c1out
,Cache
,false);
2048 return _error
->Error(_("Internal error, problem resolver broke stuff"));
2051 return InstallPackages(Cache
,false);
2054 // DoClean - Remove download archives /*{{{*/
2055 // ---------------------------------------------------------------------
2057 bool DoClean(CommandLine
&CmdL
)
2059 if (_config
->FindB("APT::Get::Simulate") == true)
2061 cout
<< "Del " << _config
->FindDir("Dir::Cache::archives") << "* " <<
2062 _config
->FindDir("Dir::Cache::archives") << "partial/*" << endl
;
2066 // Lock the archive directory
2068 if (_config
->FindB("Debug::NoLocking",false) == false)
2070 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
2071 if (_error
->PendingError() == true)
2072 return _error
->Error(_("Unable to lock the download directory"));
2076 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
2077 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
2081 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
2082 // ---------------------------------------------------------------------
2083 /* This is similar to clean but it only purges things that cannot be
2084 downloaded, that is old versions of cached packages. */
2085 class LogCleaner
: public pkgArchiveCleaner
2088 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
2090 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
2092 if (_config
->FindB("APT::Get::Simulate") == false)
2097 bool DoAutoClean(CommandLine
&CmdL
)
2099 // Lock the archive directory
2101 if (_config
->FindB("Debug::NoLocking",false) == false)
2103 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
2104 if (_error
->PendingError() == true)
2105 return _error
->Error(_("Unable to lock the download directory"));
2109 if (Cache
.Open() == false)
2114 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
2115 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
2118 // DoCheck - Perform the check operation /*{{{*/
2119 // ---------------------------------------------------------------------
2120 /* Opening automatically checks the system, this command is mostly used
2122 bool DoCheck(CommandLine
&CmdL
)
2131 // DoSource - Fetch a source archive /*{{{*/
2132 // ---------------------------------------------------------------------
2133 /* Fetch souce packages */
2141 bool DoSource(CommandLine
&CmdL
)
2144 if (Cache
.Open(false) == false)
2147 if (CmdL
.FileSize() <= 1)
2148 return _error
->Error(_("Must specify at least one package to fetch source for"));
2150 // Read the source list
2152 if (List
.ReadMainList() == false)
2153 return _error
->Error(_("The list of sources could not be read."));
2155 // Create the text record parsers
2156 pkgRecords
Recs(Cache
);
2157 pkgSrcRecords
SrcRecs(List
);
2158 if (_error
->PendingError() == true)
2161 // Create the download object
2162 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
2164 if (Fetcher
.Setup(&Stat
) == false)
2167 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
2169 // insert all downloaded uris into this set to avoid downloading them
2173 // Diff only mode only fetches .diff files
2174 bool const diffOnly
= _config
->FindB("APT::Get::Diff-Only", false);
2175 // Tar only mode only fetches .tar files
2176 bool const tarOnly
= _config
->FindB("APT::Get::Tar-Only", false);
2177 // Dsc only mode only fetches .dsc files
2178 bool const dscOnly
= _config
->FindB("APT::Get::Dsc-Only", false);
2180 // Load the requestd sources into the fetcher
2182 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
2185 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
2188 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
2190 string srec
= Last
->AsStr();
2191 string::size_type pos
= srec
.find("\nVcs-");
2192 while (pos
!= string::npos
)
2194 pos
+= strlen("\nVcs-");
2195 string vcs
= srec
.substr(pos
,srec
.find(":",pos
)-pos
);
2196 if(vcs
== "Browser")
2198 pos
= srec
.find("\nVcs-", pos
);
2201 pos
+= vcs
.length()+2;
2202 string::size_type epos
= srec
.find("\n", pos
);
2203 string uri
= srec
.substr(pos
,epos
-pos
).c_str();
2204 ioprintf(c1out
, _("NOTICE: '%s' packaging is maintained in "
2205 "the '%s' version control system at:\n"
2207 Src
.c_str(), vcs
.c_str(), uri
.c_str());
2209 ioprintf(c1out
,_("Please use:\n"
2211 "to retrieve the latest (possibly unreleased) "
2212 "updates to the package.\n"),
2218 vector
<pkgSrcRecords::File
> Lst
;
2219 if (Last
->Files(Lst
) == false)
2222 // Load them into the fetcher
2223 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
2224 I
!= Lst
.end(); I
++)
2226 // Try to guess what sort of file it is we are getting.
2227 if (I
->Type
== "dsc")
2229 Dsc
[J
].Package
= Last
->Package();
2230 Dsc
[J
].Version
= Last
->Version();
2231 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
2234 // Handle the only options so that multiple can be used at once
2235 if (diffOnly
== true || tarOnly
== true || dscOnly
== true)
2237 if ((diffOnly
== true && I
->Type
== "diff") ||
2238 (tarOnly
== true && I
->Type
== "tar") ||
2239 (dscOnly
== true && I
->Type
== "dsc"))
2240 ; // Fine, we want this file downloaded
2245 // don't download the same uri twice (should this be moved to
2246 // the fetcher interface itself?)
2247 if(queued
.find(Last
->Index().ArchiveURI(I
->Path
)) != queued
.end())
2249 queued
.insert(Last
->Index().ArchiveURI(I
->Path
));
2251 // check if we have a file with that md5 sum already localy
2252 if(!I
->MD5Hash
.empty() && FileExists(flNotDir(I
->Path
)))
2254 FileFd
Fd(flNotDir(I
->Path
), FileFd::ReadOnly
);
2256 sum
.AddFD(Fd
.Fd(), Fd
.Size());
2258 if((string
)sum
.Result() == I
->MD5Hash
)
2260 ioprintf(c1out
,_("Skipping already downloaded file '%s'\n"),
2261 flNotDir(I
->Path
).c_str());
2266 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
2268 Last
->Index().SourceInfo(*Last
,*I
),Src
);
2272 // Display statistics
2273 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
2274 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
2275 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
2277 // Check for enough free space
2279 string OutputDir
= ".";
2280 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
2281 if (errno
== EOVERFLOW
)
2282 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
2285 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
2287 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
2290 if (statfs(OutputDir
.c_str(),&Stat
) != 0
2291 #if HAVE_STRUCT_STATFS_F_TYPE
2292 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
2295 return _error
->Error(_("You don't have enough free space in %s"),
2300 if (DebBytes
!= FetchBytes
)
2301 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
2302 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
2304 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
2305 SizeToStr(DebBytes
).c_str());
2307 if (_config
->FindB("APT::Get::Simulate",false) == true)
2309 for (unsigned I
= 0; I
!= J
; I
++)
2310 ioprintf(cout
,_("Fetch source %s\n"),Dsc
[I
].Package
.c_str());
2315 // Just print out the uris an exit if the --print-uris flag was used
2316 if (_config
->FindB("APT::Get::Print-URIs") == true)
2318 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
2319 for (; I
!= Fetcher
.UriEnd(); I
++)
2320 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
2321 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
2327 if (Fetcher
.Run() == pkgAcquire::Failed
)
2330 // Print error messages
2331 bool Failed
= false;
2332 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
2334 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
2335 (*I
)->Complete
== true)
2338 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
2339 (*I
)->ErrorText
.c_str());
2343 return _error
->Error(_("Failed to fetch some archives."));
2345 if (_config
->FindB("APT::Get::Download-only",false) == true)
2347 c1out
<< _("Download complete and in download only mode") << endl
;
2352 // Unpack the sources
2353 pid_t Process
= ExecFork();
2357 bool const fixBroken
= _config
->FindB("APT::Get::Fix-Broken", false);
2358 for (unsigned I
= 0; I
!= J
; I
++)
2360 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
2362 // Diff only mode only fetches .diff files
2363 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
2364 _config
->FindB("APT::Get::Tar-Only",false) == true ||
2365 Dsc
[I
].Dsc
.empty() == true)
2368 // See if the package is already unpacked
2370 if (fixBroken
== false && stat(Dir
.c_str(),&Stat
) == 0 &&
2371 S_ISDIR(Stat
.st_mode
) != 0)
2373 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
2380 snprintf(S
,sizeof(S
),"%s -x %s",
2381 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
2382 Dsc
[I
].Dsc
.c_str());
2385 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
2386 fprintf(stderr
,_("Check if the 'dpkg-dev' package is installed.\n"));
2391 // Try to compile it with dpkg-buildpackage
2392 if (_config
->FindB("APT::Get::Compile",false) == true)
2394 // Call dpkg-buildpackage
2396 snprintf(S
,sizeof(S
),"cd %s && %s %s",
2398 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
2399 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
2403 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
2413 // Wait for the subprocess
2415 while (waitpid(Process
,&Status
,0) != Process
)
2419 return _error
->Errno("waitpid","Couldn't wait for subprocess");
2422 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
2423 return _error
->Error(_("Child process failed"));
2428 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
2429 // ---------------------------------------------------------------------
2430 /* This function will look at the build depends list of the given source
2431 package and install the necessary packages to make it true, or fail. */
2432 bool DoBuildDep(CommandLine
&CmdL
)
2435 if (Cache
.Open(true) == false)
2438 if (CmdL
.FileSize() <= 1)
2439 return _error
->Error(_("Must specify at least one package to check builddeps for"));
2441 // Read the source list
2443 if (List
.ReadMainList() == false)
2444 return _error
->Error(_("The list of sources could not be read."));
2446 // Create the text record parsers
2447 pkgRecords
Recs(Cache
);
2448 pkgSrcRecords
SrcRecs(List
);
2449 if (_error
->PendingError() == true)
2452 // Create the download object
2453 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
2455 if (Fetcher
.Setup(&Stat
) == false)
2459 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
2462 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
2464 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
2466 // Process the build-dependencies
2467 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
2468 if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only",true)) == false)
2469 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
2471 // Also ensure that build-essential packages are present
2472 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
2475 for (; Opts
; Opts
= Opts
->Next
)
2477 if (Opts
->Value
.empty() == true)
2480 pkgSrcRecords::Parser::BuildDepRec rec
;
2481 rec
.Package
= Opts
->Value
;
2482 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
2484 BuildDeps
.push_back(rec
);
2487 if (BuildDeps
.size() == 0)
2489 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
2493 // Install the requested packages
2494 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
2495 pkgProblemResolver
Fix(Cache
);
2496 bool skipAlternatives
= false; // skip remaining alternatives in an or group
2497 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); D
++)
2499 bool hasAlternatives
= (((*D
).Op
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
);
2501 if (skipAlternatives
== true)
2503 if (!hasAlternatives
)
2504 skipAlternatives
= false; // end of or group
2508 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
2509 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
2511 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
2512 // Build-conflicts on unknown packages are silently ignored
2513 if (Pkg
.end() == true)
2516 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
2519 * Remove if we have an installed version that satisfies the
2522 if (IV
.end() == false &&
2523 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2524 TryToInstall(Pkg
,Cache
,Fix
,true,false);
2526 else // BuildDep || BuildDepIndep
2528 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
2529 if (_config
->FindB("Debug::BuildDeps",false) == true)
2530 cout
<< "Looking for " << (*D
).Package
<< "...\n";
2532 if (Pkg
.end() == true)
2534 if (_config
->FindB("Debug::BuildDeps",false) == true)
2535 cout
<< " (not found)" << (*D
).Package
<< endl
;
2537 if (hasAlternatives
)
2540 return _error
->Error(_("%s dependency for %s cannot be satisfied "
2541 "because the package %s cannot be found"),
2542 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
2543 (*D
).Package
.c_str());
2547 * if there are alternatives, we've already picked one, so skip
2550 * TODO: this means that if there's a build-dep on A|B and B is
2551 * installed, we'll still try to install A; more importantly,
2552 * if A is currently broken, we cannot go back and try B. To fix
2553 * this would require we do a Resolve cycle for each package we
2554 * add to the install list. Ugh
2558 * If this is a virtual package, we need to check the list of
2559 * packages that provide it and see if any of those are
2562 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
2563 for (; Prv
.end() != true; Prv
++)
2565 if (_config
->FindB("Debug::BuildDeps",false) == true)
2566 cout
<< " Checking provider " << Prv
.OwnerPkg().FullName() << endl
;
2568 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
2572 // Get installed version and version we are going to install
2573 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
2575 if ((*D
).Version
[0] != '\0') {
2576 // Versioned dependency
2578 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
2580 for (; CV
.end() != true; CV
++)
2582 if (Cache
->VS().CheckDep(CV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2585 if (CV
.end() == true)
2587 if (hasAlternatives
)
2593 return _error
->Error(_("%s dependency for %s cannot be satisfied "
2594 "because no available versions of package %s "
2595 "can satisfy version requirements"),
2596 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
2597 (*D
).Package
.c_str());
2603 // Only consider virtual packages if there is no versioned dependency
2604 if (Prv
.end() == false)
2606 if (_config
->FindB("Debug::BuildDeps",false) == true)
2607 cout
<< " Is provided by installed package " << Prv
.OwnerPkg().FullName() << endl
;
2608 skipAlternatives
= hasAlternatives
;
2613 if (IV
.end() == false)
2615 if (_config
->FindB("Debug::BuildDeps",false) == true)
2616 cout
<< " Is installed\n";
2618 if (Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2620 skipAlternatives
= hasAlternatives
;
2624 if (_config
->FindB("Debug::BuildDeps",false) == true)
2625 cout
<< " ...but the installed version doesn't meet the version requirement\n";
2627 if (((*D
).Op
& pkgCache::Dep::LessEq
) == pkgCache::Dep::LessEq
)
2629 return _error
->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
2630 Last
->BuildDepType((*D
).Type
),
2632 Pkg
.FullName(true).c_str());
2637 if (_config
->FindB("Debug::BuildDeps",false) == true)
2638 cout
<< " Trying to install " << (*D
).Package
<< endl
;
2640 if (TryToInstall(Pkg
,Cache
,Fix
,false,false) == true)
2642 // We successfully installed something; skip remaining alternatives
2643 skipAlternatives
= hasAlternatives
;
2644 if(_config
->FindB("APT::Get::Build-Dep-Automatic", false) == true)
2645 Cache
->MarkAuto(Pkg
, true);
2648 else if (hasAlternatives
)
2650 if (_config
->FindB("Debug::BuildDeps",false) == true)
2651 cout
<< " Unsatisfiable, trying alternatives\n";
2656 return _error
->Error(_("Failed to satisfy %s dependency for %s: %s"),
2657 Last
->BuildDepType((*D
).Type
),
2659 (*D
).Package
.c_str());
2664 Fix
.InstallProtect();
2665 if (Fix
.Resolve(true) == false)
2668 // Now we check the state of the packages,
2669 if (Cache
->BrokenCount() != 0)
2671 ShowBroken(cout
, Cache
, false);
2672 return _error
->Error(_("Build-dependencies for %s could not be satisfied."),*I
);
2676 if (InstallPackages(Cache
, false, true) == false)
2677 return _error
->Error(_("Failed to process build dependencies"));
2681 // DoMoo - Never Ask, Never Tell /*{{{*/
2682 // ---------------------------------------------------------------------
2684 bool DoMoo(CommandLine
&CmdL
)
2693 "....\"Have you mooed today?\"...\n";
2698 // ShowHelp - Show a help screen /*{{{*/
2699 // ---------------------------------------------------------------------
2701 bool ShowHelp(CommandLine
&CmdL
)
2703 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,VERSION
,
2704 COMMON_ARCH
,__DATE__
,__TIME__
);
2706 if (_config
->FindB("version") == true)
2708 cout
<< _("Supported modules:") << endl
;
2710 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
2712 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
2713 if (_system
!= 0 && _system
->VS
== VS
)
2717 cout
<< "Ver: " << VS
->Label
<< endl
;
2719 /* Print out all the packaging systems that will work with
2721 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
2723 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
2728 if (Sys
->VS
->TestCompatibility(*VS
) == true)
2729 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
2733 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
2735 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
2736 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
2739 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
2741 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
2742 cout
<< " Idx: " << Type
->Label
<< endl
;
2749 _("Usage: apt-get [options] command\n"
2750 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
2751 " apt-get [options] source pkg1 [pkg2 ...]\n"
2753 "apt-get is a simple command line interface for downloading and\n"
2754 "installing packages. The most frequently used commands are update\n"
2758 " update - Retrieve new lists of packages\n"
2759 " upgrade - Perform an upgrade\n"
2760 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
2761 " remove - Remove packages\n"
2762 " autoremove - Remove automatically all unused packages\n"
2763 " purge - Remove packages and config files\n"
2764 " source - Download source archives\n"
2765 " build-dep - Configure build-dependencies for source packages\n"
2766 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
2767 " dselect-upgrade - Follow dselect selections\n"
2768 " clean - Erase downloaded archive files\n"
2769 " autoclean - Erase old downloaded archive files\n"
2770 " check - Verify that there are no broken dependencies\n"
2771 " markauto - Mark the given packages as automatically installed\n"
2772 " unmarkauto - Mark the given packages as manually installed\n"
2775 " -h This help text.\n"
2776 " -q Loggable output - no progress indicator\n"
2777 " -qq No output except for errors\n"
2778 " -d Download only - do NOT install or unpack archives\n"
2779 " -s No-act. Perform ordering simulation\n"
2780 " -y Assume Yes to all queries and do not prompt\n"
2781 " -f Attempt to correct a system with broken dependencies in place\n"
2782 " -m Attempt to continue if archives are unlocatable\n"
2783 " -u Show a list of upgraded packages as well\n"
2784 " -b Build the source package after fetching it\n"
2785 " -V Show verbose version numbers\n"
2786 " -c=? Read this configuration file\n"
2787 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
2788 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
2789 "pages for more information and options.\n"
2790 " This APT has Super Cow Powers.\n");
2794 // GetInitialize - Initialize things for apt-get /*{{{*/
2795 // ---------------------------------------------------------------------
2797 void GetInitialize()
2799 _config
->Set("quiet",0);
2800 _config
->Set("help",false);
2801 _config
->Set("APT::Get::Download-Only",false);
2802 _config
->Set("APT::Get::Simulate",false);
2803 _config
->Set("APT::Get::Assume-Yes",false);
2804 _config
->Set("APT::Get::Fix-Broken",false);
2805 _config
->Set("APT::Get::Force-Yes",false);
2806 _config
->Set("APT::Get::List-Cleanup",true);
2807 _config
->Set("APT::Get::AutomaticRemove",false);
2810 // SigWinch - Window size change signal handler /*{{{*/
2811 // ---------------------------------------------------------------------
2815 // Riped from GNU ls
2819 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
2820 ScreenWidth
= ws
.ws_col
- 1;
2824 int main(int argc
,const char *argv
[]) /*{{{*/
2826 CommandLine::Args Args
[] = {
2827 {'h',"help","help",0},
2828 {'v',"version","version",0},
2829 {'V',"verbose-versions","APT::Get::Show-Versions",0},
2830 {'q',"quiet","quiet",CommandLine::IntLevel
},
2831 {'q',"silent","quiet",CommandLine::IntLevel
},
2832 {'d',"download-only","APT::Get::Download-Only",0},
2833 {'b',"compile","APT::Get::Compile",0},
2834 {'b',"build","APT::Get::Compile",0},
2835 {'s',"simulate","APT::Get::Simulate",0},
2836 {'s',"just-print","APT::Get::Simulate",0},
2837 {'s',"recon","APT::Get::Simulate",0},
2838 {'s',"dry-run","APT::Get::Simulate",0},
2839 {'s',"no-act","APT::Get::Simulate",0},
2840 {'y',"yes","APT::Get::Assume-Yes",0},
2841 {'y',"assume-yes","APT::Get::Assume-Yes",0},
2842 {'f',"fix-broken","APT::Get::Fix-Broken",0},
2843 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
2844 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
2845 {'t',"target-release","APT::Default-Release",CommandLine::HasArg
},
2846 {'t',"default-release","APT::Default-Release",CommandLine::HasArg
},
2847 {0,"download","APT::Get::Download",0},
2848 {0,"fix-missing","APT::Get::Fix-Missing",0},
2849 {0,"ignore-hold","APT::Ignore-Hold",0},
2850 {0,"upgrade","APT::Get::upgrade",0},
2851 {0,"only-upgrade","APT::Get::Only-Upgrade",0},
2852 {0,"force-yes","APT::Get::force-yes",0},
2853 {0,"print-uris","APT::Get::Print-URIs",0},
2854 {0,"diff-only","APT::Get::Diff-Only",0},
2855 {0,"debian-only","APT::Get::Diff-Only",0},
2856 {0,"tar-only","APT::Get::Tar-Only",0},
2857 {0,"dsc-only","APT::Get::Dsc-Only",0},
2858 {0,"purge","APT::Get::Purge",0},
2859 {0,"list-cleanup","APT::Get::List-Cleanup",0},
2860 {0,"reinstall","APT::Get::ReInstall",0},
2861 {0,"trivial-only","APT::Get::Trivial-Only",0},
2862 {0,"remove","APT::Get::Remove",0},
2863 {0,"only-source","APT::Get::Only-Source",0},
2864 {0,"arch-only","APT::Get::Arch-Only",0},
2865 {0,"auto-remove","APT::Get::AutomaticRemove",0},
2866 {0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0},
2867 {0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean
},
2868 {0,"fix-policy","APT::Get::Fix-Policy-Broken",0},
2869 {'c',"config-file",0,CommandLine::ConfigFile
},
2870 {'o',"option",0,CommandLine::ArbItem
},
2872 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
2873 {"upgrade",&DoUpgrade
},
2874 {"install",&DoInstall
},
2875 {"remove",&DoInstall
},
2876 {"purge",&DoInstall
},
2877 {"autoremove",&DoInstall
},
2878 {"markauto",&DoMarkAuto
},
2879 {"unmarkauto",&DoMarkAuto
},
2880 {"dist-upgrade",&DoDistUpgrade
},
2881 {"dselect-upgrade",&DoDSelectUpgrade
},
2882 {"build-dep",&DoBuildDep
},
2884 {"autoclean",&DoAutoClean
},
2886 {"source",&DoSource
},
2891 // Set up gettext support
2892 setlocale(LC_ALL
,"");
2893 textdomain(PACKAGE
);
2895 // Parse the command line and initialize the package library
2896 CommandLine
CmdL(Args
,_config
);
2897 if (pkgInitConfig(*_config
) == false ||
2898 CmdL
.Parse(argc
,argv
) == false ||
2899 pkgInitSystem(*_config
,_system
) == false)
2901 if (_config
->FindB("version") == true)
2904 _error
->DumpErrors();
2908 // See if the help should be shown
2909 if (_config
->FindB("help") == true ||
2910 _config
->FindB("version") == true ||
2911 CmdL
.FileSize() == 0)
2917 // simulate user-friendly if apt-get has no root privileges
2918 if (getuid() != 0 && _config
->FindB("APT::Get::Simulate") == true)
2920 if (_config
->FindB("APT::Get::Show-User-Simulation-Note",true) == true)
2921 cout
<< _("NOTE: This is only a simulation!\n"
2922 " apt-get needs root privileges for real execution.\n"
2923 " Keep also in mind that locking is deactivated,\n"
2924 " so don't depend on the relevance to the real current situation!"
2926 _config
->Set("Debug::NoLocking",true);
2929 // Deal with stdout not being a tty
2930 if (!isatty(STDOUT_FILENO
) && _config
->FindI("quiet", -1) == -1)
2931 _config
->Set("quiet","1");
2933 // Setup the output streams
2934 c0out
.rdbuf(cout
.rdbuf());
2935 c1out
.rdbuf(cout
.rdbuf());
2936 c2out
.rdbuf(cout
.rdbuf());
2937 if (_config
->FindI("quiet",0) > 0)
2938 c0out
.rdbuf(devnull
.rdbuf());
2939 if (_config
->FindI("quiet",0) > 1)
2940 c1out
.rdbuf(devnull
.rdbuf());
2942 // Setup the signals
2943 signal(SIGPIPE
,SIG_IGN
);
2944 signal(SIGWINCH
,SigWinch
);
2947 // Match the operation
2948 CmdL
.DispatchArg(Cmds
);
2950 // Print any errors or warnings found during parsing
2951 bool const Errors
= _error
->PendingError();
2952 if (_config
->FindI("quiet",0) > 0)
2953 _error
->DumpErrors();
2955 _error
->DumpErrors(GlobalError::DEBUG
);
2956 return Errors
== true ? 100 : 0;