]>
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>
43 #include <apt-pkg/cacheset.h>
48 #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 double FetchBytes
= Fetcher
.FetchNeeded();
842 double FetchPBytes
= Fetcher
.PartialPresent();
843 double 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 unsigned int &ExpectedInst
,bool AllowFail
= true)
1084 /* This is a pure virtual package and there is a single available
1085 candidate providing it. */
1086 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0)
1088 pkgCache::PkgIterator Prov
;
1089 bool found_one
= false;
1091 for (pkgCache::PrvIterator P
= Pkg
.ProvidesList(); P
; P
++)
1093 pkgCache::VerIterator
const PVer
= P
.OwnerVer();
1094 pkgCache::PkgIterator
const PPkg
= PVer
.ParentPkg();
1096 /* Ignore versions that are not a candidate. */
1097 if (Cache
[PPkg
].CandidateVer
!= PVer
)
1100 if (found_one
== false)
1105 else if (PPkg
!= Prov
)
1107 found_one
= false; // we found at least two
1112 if (found_one
== true)
1114 ioprintf(c1out
,_("Note, selecting %s instead of %s\n"),
1115 Prov
.FullName(true).c_str(),Pkg
.FullName(true).c_str());
1120 // Handle the no-upgrade case
1121 if (_config
->FindB("APT::Get::upgrade",true) == false &&
1122 Pkg
->CurrentVer
!= 0)
1124 if (AllowFail
== true)
1125 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
1126 Pkg
.FullName(true).c_str());
1130 // Ignore request for install if package would be new
1131 if (_config
->FindB("APT::Get::Only-Upgrade", false) == true &&
1132 Pkg
->CurrentVer
== 0)
1134 if (AllowFail
== true)
1135 ioprintf(c1out
,_("Skipping %s, it is not installed and only upgrades are requested.\n"),
1140 // Check if there is something at all to install
1141 pkgDepCache::StateCache
&State
= Cache
[Pkg
];
1142 if (Remove
== true && Pkg
->CurrentVer
== 0)
1148 /* We want to continue searching for regex hits, so we return false here
1149 otherwise this is not really an error. */
1150 if (AllowFail
== false)
1153 ioprintf(c1out
,_("Package %s is not installed, so not removed\n"),Pkg
.FullName(true).c_str());
1157 if (State
.CandidateVer
== 0 && Remove
== false)
1159 if (AllowFail
== false)
1162 if (Pkg
->ProvidesList
!= 0)
1164 ioprintf(c1out
,_("Package %s is a virtual package provided by:\n"),
1165 Pkg
.FullName(true).c_str());
1167 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
1168 unsigned short provider
= 0;
1169 for (; I
.end() == false; I
++)
1171 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
1173 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer())
1175 c1out
<< " " << Pkg
.FullName(true) << " " << I
.OwnerVer().VerStr();
1176 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
1177 c1out
<< _(" [Installed]");
1182 // if we found no candidate which provide this package, show non-candidates
1184 for (I
= Pkg
.ProvidesList(); I
.end() == false; I
++)
1185 c1out
<< " " << I
.OwnerPkg().FullName(true) << " " << I
.OwnerVer().VerStr()
1186 << _(" [Not candidate version]") << endl
;
1188 c1out
<< _("You should explicitly select one to install.") << endl
;
1193 _("Package %s is not available, but is referred to by another package.\n"
1194 "This may mean that the package is missing, has been obsoleted, or\n"
1195 "is only available from another source\n"),Pkg
.FullName(true).c_str());
1198 string VersionsList
;
1199 SPtrArray
<bool> Seen
= new bool[Cache
.Head().PackageCount
];
1200 memset(Seen
,0,Cache
.Head().PackageCount
*sizeof(*Seen
));
1201 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
1202 for (; Dep
.end() == false; Dep
++)
1204 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
1206 if (Seen
[Dep
.ParentPkg()->ID
] == true)
1208 Seen
[Dep
.ParentPkg()->ID
] = true;
1209 List
+= Dep
.ParentPkg().FullName(true) + " ";
1210 //VersionsList += string(Dep.ParentPkg().CurVersion) + "\n"; ???
1212 ShowList(c1out
,_("However the following packages replace it:"),List
,VersionsList
);
1215 _error
->Error(_("Package %s has no installation candidate"),Pkg
.FullName(true).c_str());
1224 Cache
.MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
1229 Cache
.MarkInstall(Pkg
,false);
1230 if (State
.Install() == false)
1232 if (_config
->FindB("APT::Get::ReInstall",false) == true)
1234 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
1235 ioprintf(c1out
,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
1236 Pkg
.FullName(true).c_str());
1238 Cache
.SetReInstall(Pkg
,true);
1242 if (AllowFail
== true)
1243 ioprintf(c1out
,_("%s is already the newest version.\n"),
1244 Pkg
.FullName(true).c_str());
1250 // Install it with autoinstalling enabled (if we not respect the minial
1251 // required deps or the policy)
1252 if ((State
.InstBroken() == true || State
.InstPolicyBroken() == true) && BrokenFix
== false)
1253 Cache
.MarkInstall(Pkg
,true);
1258 // TryToChangeVer - Try to change a candidate version /*{{{*/
1259 // ---------------------------------------------------------------------
1261 bool TryToChangeVer(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
1262 const char *VerTag
,bool IsRel
)
1264 pkgVersionMatch
Match(VerTag
,(IsRel
== true?pkgVersionMatch::Release
:
1265 pkgVersionMatch::Version
));
1267 pkgCache::VerIterator Ver
= Match
.Find(Pkg
);
1269 if (Ver
.end() == true)
1272 return _error
->Error(_("Release '%s' for '%s' was not found"),
1273 VerTag
,Pkg
.FullName(true).c_str());
1274 return _error
->Error(_("Version '%s' for '%s' was not found"),
1275 VerTag
,Pkg
.FullName(true).c_str());
1278 if (strcmp(VerTag
,Ver
.VerStr()) != 0)
1280 ioprintf(c1out
,_("Selected version %s (%s) for %s\n"),
1281 Ver
.VerStr(),Ver
.RelStr().c_str(),Pkg
.FullName(true).c_str());
1284 Cache
.SetCandidateVersion(Ver
);
1286 // Set the all package to the same candidate
1287 if (Ver
.Pseudo() == true)
1288 Cache
.SetCandidateVersion(Match
.Find(Pkg
.Group().FindPkg("all")));
1293 // FindSrc - Find a source record /*{{{*/
1294 // ---------------------------------------------------------------------
1296 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
1297 pkgSrcRecords
&SrcRecs
,string
&Src
,
1301 string DefRel
= _config
->Find("APT::Default-Release");
1302 string TmpSrc
= Name
;
1304 // extract the version/release from the pkgname
1305 const size_t found
= TmpSrc
.find_last_of("/=");
1306 if (found
!= string::npos
) {
1307 if (TmpSrc
[found
] == '/')
1308 DefRel
= TmpSrc
.substr(found
+1);
1310 VerTag
= TmpSrc
.substr(found
+1);
1311 TmpSrc
= TmpSrc
.substr(0,found
);
1314 /* Lookup the version of the package we would install if we were to
1315 install a version and determine the source package name, then look
1316 in the archive for a source package of the same name. */
1317 bool MatchSrcOnly
= _config
->FindB("APT::Get::Only-Source");
1318 const pkgCache::PkgIterator Pkg
= Cache
.FindPkg(TmpSrc
);
1319 if (MatchSrcOnly
== false && Pkg
.end() == false)
1321 if(VerTag
.empty() == false || DefRel
.empty() == false)
1324 // we have a default release, try to locate the pkg. we do it like
1325 // this because GetCandidateVer() will not "downgrade", that means
1326 // "apt-get source -t stable apt" won't work on a unstable system
1327 for (pkgCache::VerIterator Ver
= Pkg
.VersionList();; Ver
++)
1329 // try first only exact matches, later fuzzy matches
1330 if (Ver
.end() == true)
1335 Ver
= Pkg
.VersionList();
1336 // exit right away from the Pkg.VersionList() loop if we
1337 // don't have any versions
1338 if (Ver
.end() == true)
1341 // We match against a concrete version (or a part of this version)
1342 if (VerTag
.empty() == false &&
1343 (fuzzy
== true || Cache
.VS().CmpVersion(VerTag
, Ver
.VerStr()) != 0) && // exact match
1344 (fuzzy
== false || strncmp(VerTag
.c_str(), Ver
.VerStr(), VerTag
.size()) != 0)) // fuzzy match
1347 for (pkgCache::VerFileIterator VF
= Ver
.FileList();
1348 VF
.end() == false; VF
++)
1350 /* If this is the status file, and the current version is not the
1351 version in the status file (ie it is not installed, or somesuch)
1352 then it is not a candidate for installation, ever. This weeds
1353 out bogus entries that may be due to config-file states, or
1355 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) ==
1356 pkgCache::Flag::NotSource
&& Pkg
.CurrentVer() != Ver
)
1359 // or we match against a release
1360 if(VerTag
.empty() == false ||
1361 (VF
.File().Archive() != 0 && VF
.File().Archive() == DefRel
) ||
1362 (VF
.File().Codename() != 0 && VF
.File().Codename() == DefRel
))
1364 pkgRecords::Parser
&Parse
= Recs
.Lookup(VF
);
1365 Src
= Parse
.SourcePkg();
1366 // no SourcePkg name, so it is the "binary" name
1367 if (Src
.empty() == true)
1369 // the Version we have is possibly fuzzy or includes binUploads,
1370 // so we use the Version of the SourcePkg (empty if same as package)
1371 VerTag
= Parse
.SourceVer();
1372 if (VerTag
.empty() == true)
1373 VerTag
= Ver
.VerStr();
1377 if (Src
.empty() == false)
1380 if (Src
.empty() == true)
1382 // Sources files have no codename information
1383 if (VerTag
.empty() == true && DefRel
.empty() == false)
1385 _error
->Error(_("Ignore unavailable target release '%s' of package '%s'"), DefRel
.c_str(), TmpSrc
.c_str());
1390 if (Src
.empty() == true)
1392 // if we don't have found a fitting package yet so we will
1393 // choose a good candidate and proceed with that.
1394 // Maybe we will find a source later on with the right VerTag
1395 pkgCache::VerIterator Ver
= Cache
.GetCandidateVer(Pkg
);
1396 if (Ver
.end() == false)
1398 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1399 Src
= Parse
.SourcePkg();
1400 if (VerTag
.empty() == true)
1401 VerTag
= Parse
.SourceVer();
1406 if (Src
.empty() == true)
1410 /* if we have a source pkg name, make sure to only search
1411 for srcpkg names, otherwise apt gets confused if there
1412 is a binary package "pkg1" and a source package "pkg1"
1413 with the same name but that comes from different packages */
1414 MatchSrcOnly
= true;
1417 ioprintf(c1out
, _("Picking '%s' as source package instead of '%s'\n"), Src
.c_str(), TmpSrc
.c_str());
1422 pkgSrcRecords::Parser
*Last
= 0;
1423 unsigned long Offset
= 0;
1426 /* Iterate over all of the hits, which includes the resulting
1427 binary packages in the search */
1428 pkgSrcRecords::Parser
*Parse
;
1432 while ((Parse
= SrcRecs
.Find(Src
.c_str(), MatchSrcOnly
)) != 0)
1434 const string Ver
= Parse
->Version();
1436 // Ignore all versions which doesn't fit
1437 if (VerTag
.empty() == false &&
1438 Cache
.VS().CmpVersion(VerTag
, Ver
) != 0) // exact match
1441 // Newer version or an exact match? Save the hit
1442 if (Last
== 0 || Cache
.VS().CmpVersion(Version
,Ver
) < 0) {
1444 Offset
= Parse
->Offset();
1448 // was the version check above an exact match? If so, we don't need to look further
1449 if (VerTag
.empty() == false && VerTag
.size() == Ver
.size())
1452 if (Last
!= 0 || VerTag
.empty() == true)
1454 //if (VerTag.empty() == false && Last == 0)
1455 _error
->Error(_("Ignore unavailable version '%s' of package '%s'"), VerTag
.c_str(), TmpSrc
.c_str());
1459 if (Last
== 0 || Last
->Jump(Offset
) == false)
1465 // DoUpdate - Update the package lists /*{{{*/
1466 // ---------------------------------------------------------------------
1468 bool DoUpdate(CommandLine
&CmdL
)
1470 if (CmdL
.FileSize() != 1)
1471 return _error
->Error(_("The update command takes no arguments"));
1473 // Get the source list
1475 if (List
.ReadMainList() == false)
1478 // Create the progress
1479 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1481 // Just print out the uris an exit if the --print-uris flag was used
1482 if (_config
->FindB("APT::Get::Print-URIs") == true)
1484 // force a hashsum for compatibility reasons
1485 _config
->CndSet("Acquire::ForceHash", "md5sum");
1489 if (Fetcher
.Setup(&Stat
) == false)
1492 // Populate it with the source selection and get all Indexes
1494 if (List
.GetIndexes(&Fetcher
,true) == false)
1497 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1498 for (; I
!= Fetcher
.UriEnd(); I
++)
1499 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1500 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
1506 if (_config
->FindB("APT::Get::Download",true) == true)
1507 ListUpdate(Stat
, List
);
1509 // Rebuild the cache.
1510 if (Cache
.BuildCaches() == false)
1516 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
1517 // ---------------------------------------------------------------------
1518 /* Remove unused automatic packages */
1519 bool DoAutomaticRemove(CacheFile
&Cache
)
1521 bool Debug
= _config
->FindI("Debug::pkgAutoRemove",false);
1522 bool doAutoRemove
= _config
->FindB("APT::Get::AutomaticRemove", false);
1523 bool hideAutoRemove
= _config
->FindB("APT::Get::HideAutoRemove");
1525 pkgDepCache::ActionGroup
group(*Cache
);
1527 std::cout
<< "DoAutomaticRemove()" << std::endl
;
1529 // we don't want to autoremove and we don't want to see it, so why calculating?
1530 if (doAutoRemove
== false && hideAutoRemove
== true)
1533 if (doAutoRemove
== true &&
1534 _config
->FindB("APT::Get::Remove",true) == false)
1536 c1out
<< _("We are not supposed to delete stuff, can't start "
1537 "AutoRemover") << std::endl
;
1541 bool purgePkgs
= _config
->FindB("APT::Get::Purge", false);
1542 bool smallList
= (hideAutoRemove
== false &&
1543 strcasecmp(_config
->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
1545 string autoremovelist
, autoremoveversions
;
1546 unsigned long autoRemoveCount
= 0;
1547 // look over the cache to see what can be removed
1548 for (pkgCache::PkgIterator Pkg
= Cache
->PkgBegin(); ! Pkg
.end(); ++Pkg
)
1550 if (Cache
[Pkg
].Garbage
)
1552 if(Pkg
.CurrentVer() != 0 || Cache
[Pkg
].Install())
1554 std::cout
<< "We could delete %s" << Pkg
.FullName(true).c_str() << std::endl
;
1558 if(Pkg
.CurrentVer() != 0 &&
1559 Pkg
->CurrentState
!= pkgCache::State::ConfigFiles
)
1560 Cache
->MarkDelete(Pkg
, purgePkgs
);
1562 Cache
->MarkKeep(Pkg
, false, false);
1566 // only show stuff in the list that is not yet marked for removal
1567 if(Cache
[Pkg
].Delete() == false)
1570 // we don't need to fill the strings if we don't need them
1571 if (smallList
== false)
1573 autoremovelist
+= Pkg
.FullName(true) + " ";
1574 autoremoveversions
+= string(Cache
[Pkg
].CandVersion
) + "\n";
1580 // if we don't remove them, we should show them!
1581 if (doAutoRemove
== false && (autoremovelist
.empty() == false || autoRemoveCount
!= 0))
1583 if (smallList
== false)
1584 ShowList(c1out
, P_("The following package is automatically installed and is no longer required:",
1585 "The following packages were automatically installed and are no longer required:",
1586 autoRemoveCount
), autoremovelist
, autoremoveversions
);
1588 ioprintf(c1out
, P_("%lu package was automatically installed and is no longer required.\n",
1589 "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount
), autoRemoveCount
);
1590 c1out
<< _("Use 'apt-get autoremove' to remove them.") << std::endl
;
1592 // Now see if we had destroyed anything (if we had done anything)
1593 else if (Cache
->BrokenCount() != 0)
1595 c1out
<< _("Hmm, seems like the AutoRemover destroyed something which really\n"
1596 "shouldn't happen. Please file a bug report against apt.") << endl
;
1598 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1600 ShowBroken(c1out
,Cache
,false);
1602 return _error
->Error(_("Internal Error, AutoRemover broke stuff"));
1607 // DoUpgrade - Upgrade all packages /*{{{*/
1608 // ---------------------------------------------------------------------
1609 /* Upgrade all packages without installing new packages or erasing old
1611 bool DoUpgrade(CommandLine
&CmdL
)
1614 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1618 if (pkgAllUpgrade(Cache
) == false)
1620 ShowBroken(c1out
,Cache
,false);
1621 return _error
->Error(_("Internal error, AllUpgrade broke stuff"));
1624 return InstallPackages(Cache
,true);
1627 // DoInstallTask - Install task from the command line /*{{{*/
1628 // ---------------------------------------------------------------------
1629 /* Install named task */
1630 bool TryInstallTask(pkgDepCache
&Cache
, pkgProblemResolver
&Fix
,
1632 unsigned int& ExpectedInst
,
1633 const char *taskname
,
1636 const char *start
, *end
;
1637 pkgCache::PkgIterator Pkg
;
1642 pkgRecords
Recs(Cache
);
1644 // build regexp for the task
1646 snprintf(S
, sizeof(S
), "^Task:.*[, ]%s([, ]|$)", taskname
);
1647 if(regcomp(&Pattern
,S
, REG_EXTENDED
| REG_NOSUB
| REG_NEWLINE
) != 0)
1648 return _error
->Error("Failed to compile task regexp");
1653 // two runs, first ignore dependencies, second install any missing
1654 for(int IgnoreBroken
=1; IgnoreBroken
>= 0; IgnoreBroken
--)
1656 for (Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
1658 pkgCache::VerIterator ver
= Cache
[Pkg
].CandidateVerIter(Cache
);
1661 pkgRecords::Parser
&parser
= Recs
.Lookup(ver
.FileList());
1662 parser
.GetRec(start
,end
);
1663 strncpy(buf
, start
, end
-start
);
1664 buf
[end
-start
] = 0x0;
1665 if (regexec(&Pattern
,buf
,0,0,0) != 0)
1667 res
&= TryToInstall(Pkg
,Cache
,Fix
,Remove
,IgnoreBroken
,ExpectedInst
);
1672 // now let the problem resolver deal with any issues
1676 _error
->Error(_("Couldn't find task %s"),taskname
);
1682 // DoInstall - Install packages from the command line /*{{{*/
1683 // ---------------------------------------------------------------------
1684 /* Install named packages */
1685 bool DoInstall(CommandLine
&CmdL
)
1688 if (Cache
.OpenForInstall() == false ||
1689 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
1692 // Enter the special broken fixing mode if the user specified arguments
1693 bool BrokenFix
= false;
1694 if (Cache
->BrokenCount() != 0)
1697 unsigned int AutoMarkChanged
= 0;
1698 unsigned int ExpectedInst
= 0;
1699 unsigned int Packages
= 0;
1700 pkgProblemResolver
Fix(Cache
);
1702 bool DefRemove
= false;
1703 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
1705 else if (strcasecmp(CmdL
.FileList
[0], "purge") == 0)
1707 _config
->Set("APT::Get::Purge", true);
1710 else if (strcasecmp(CmdL
.FileList
[0], "autoremove") == 0)
1712 _config
->Set("APT::Get::AutomaticRemove", "true");
1715 // new scope for the ActionGroup
1717 pkgDepCache::ActionGroup
group(Cache
);
1718 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1720 // Duplicate the string
1721 unsigned int Length
= strlen(*I
);
1723 if (Length
>= sizeof(S
))
1727 // See if we are removing and special indicators..
1728 bool Remove
= DefRemove
;
1730 bool VerIsRel
= false;
1733 if (Length
>= 1 && S
[Length
- 1] == '^')
1736 // tasks must always be confirmed
1737 ExpectedInst
+= 1000;
1738 // see if we can install it
1739 TryInstallTask(Cache
, Fix
, BrokenFix
, ExpectedInst
, S
, Remove
);
1743 while (Cache
->FindPkg(S
).end() == true)
1745 // Handle an optional end tag indicating what to do
1746 if (Length
>= 1 && S
[Length
- 1] == '-')
1753 if (Length
>= 1 && S
[Length
- 1] == '+')
1760 char *Slash
= strchr(S
,'=');
1768 Slash
= strchr(S
,'/');
1779 // Locate the package
1780 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
1782 if (Pkg
.end() == true)
1784 APT::PackageSet pkgset
= APT::PackageSet::FromRegEx(Cache
, S
, c1out
);
1785 if (pkgset
.empty() == true)
1786 return _error
->Error(_("Couldn't find package %s"),S
);
1788 // Regexs must always be confirmed
1789 ExpectedInst
+= 1000;
1792 for (APT::PackageSet::const_iterator Pkg
= pkgset
.begin(); Pkg
!= pkgset
.end(); ++Pkg
)
1795 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1798 Hit
|= TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,
1799 ExpectedInst
,false);
1803 return _error
->Error(_("Couldn't find package %s"),S
);
1808 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1810 if (TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,ExpectedInst
) == false)
1813 // see if we need to fix the auto-mark flag
1814 // e.g. apt-get install foo
1815 // where foo is marked automatic
1817 Cache
[Pkg
].Install() == false &&
1818 (Cache
[Pkg
].Flags
& pkgCache::Flag::Auto
) &&
1819 _config
->FindB("APT::Get::ReInstall",false) == false &&
1820 _config
->FindB("APT::Get::Only-Upgrade",false) == false &&
1821 _config
->FindB("APT::Get::Download-Only",false) == false)
1823 ioprintf(c1out
,_("%s set to manually installed.\n"),
1824 Pkg
.FullName(true).c_str());
1825 Cache
->MarkAuto(Pkg
,false);
1831 /* If we are in the Broken fixing mode we do not attempt to fix the
1832 problems. This is if the user invoked install without -f and gave
1834 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1836 c1out
<< _("You might want to run 'apt-get -f install' to correct these:") << endl
;
1837 ShowBroken(c1out
,Cache
,false);
1839 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1842 // Call the scored problem resolver
1843 Fix
.InstallProtect();
1844 if (Fix
.Resolve(true) == false)
1847 // Now we check the state of the packages,
1848 if (Cache
->BrokenCount() != 0)
1851 _("Some packages could not be installed. This may mean that you have\n"
1852 "requested an impossible situation or if you are using the unstable\n"
1853 "distribution that some required packages have not yet been created\n"
1854 "or been moved out of Incoming.") << endl
;
1860 _("Since you only requested a single operation it is extremely likely that\n"
1861 "the package is simply not installable and a bug report against\n"
1862 "that package should be filed.") << endl;
1866 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1868 ShowBroken(c1out
,Cache
,false);
1869 return _error
->Error(_("Broken packages"));
1872 if (!DoAutomaticRemove(Cache
))
1875 /* Print out a list of packages that are going to be installed extra
1876 to what the user asked */
1877 if (Cache
->InstCount() != ExpectedInst
)
1880 string VersionsList
;
1881 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1883 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1884 if ((*Cache
)[I
].Install() == false)
1888 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1889 if (strcmp(*J
,I
.Name()) == 0)
1893 List
+= I
.FullName(true) + " ";
1894 VersionsList
+= string(Cache
[I
].CandVersion
) + "\n";
1898 ShowList(c1out
,_("The following extra packages will be installed:"),List
,VersionsList
);
1901 /* Print out a list of suggested and recommended packages */
1903 string SuggestsList
, RecommendsList
, List
;
1904 string SuggestsVersions
, RecommendsVersions
;
1905 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1907 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
1909 /* Just look at the ones we want to install */
1910 if ((*Cache
)[Pkg
].Install() == false)
1913 // get the recommends/suggests for the candidate ver
1914 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1915 for (pkgCache::DepIterator D
= CV
.DependsList(); D
.end() == false; )
1917 pkgCache::DepIterator Start
;
1918 pkgCache::DepIterator End
;
1919 D
.GlobOr(Start
,End
); // advances D
1921 // FIXME: we really should display a or-group as a or-group to the user
1922 // the problem is that ShowList is incapable of doing this
1923 string RecommendsOrList
,RecommendsOrVersions
;
1924 string SuggestsOrList
,SuggestsOrVersions
;
1925 bool foundInstalledInOrGroup
= false;
1928 /* Skip if package is installed already, or is about to be */
1929 string target
= Start
.TargetPkg().FullName(true) + " ";
1930 pkgCache::PkgIterator
const TarPkg
= Start
.TargetPkg();
1931 if (TarPkg
->SelectedState
== pkgCache::State::Install
||
1932 TarPkg
->SelectedState
== pkgCache::State::Hold
||
1933 Cache
[Start
.TargetPkg()].Install())
1935 foundInstalledInOrGroup
=true;
1939 /* Skip if we already saw it */
1940 if (int(SuggestsList
.find(target
)) != -1 || int(RecommendsList
.find(target
)) != -1)
1942 foundInstalledInOrGroup
=true;
1946 // this is a dep on a virtual pkg, check if any package that provides it
1947 // should be installed
1948 if(Start
.TargetPkg().ProvidesList() != 0)
1950 pkgCache::PrvIterator I
= Start
.TargetPkg().ProvidesList();
1951 for (; I
.end() == false; I
++)
1953 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
1954 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer() &&
1955 Pkg
.CurrentVer() != 0)
1956 foundInstalledInOrGroup
=true;
1960 if (Start
->Type
== pkgCache::Dep::Suggests
)
1962 SuggestsOrList
+= target
;
1963 SuggestsOrVersions
+= string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
1966 if (Start
->Type
== pkgCache::Dep::Recommends
)
1968 RecommendsOrList
+= target
;
1969 RecommendsOrVersions
+= string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
1977 if(foundInstalledInOrGroup
== false)
1979 RecommendsList
+= RecommendsOrList
;
1980 RecommendsVersions
+= RecommendsOrVersions
;
1981 SuggestsList
+= SuggestsOrList
;
1982 SuggestsVersions
+= SuggestsOrVersions
;
1988 ShowList(c1out
,_("Suggested packages:"),SuggestsList
,SuggestsVersions
);
1989 ShowList(c1out
,_("Recommended packages:"),RecommendsList
,RecommendsVersions
);
1993 // if nothing changed in the cache, but only the automark information
1994 // we write the StateFile here, otherwise it will be written in
1996 if (AutoMarkChanged
> 0 &&
1997 Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
1998 Cache
->BadCount() == 0 &&
1999 _config
->FindB("APT::Get::Simulate",false) == false)
2000 Cache
->writeStateFile(NULL
);
2002 // See if we need to prompt
2003 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
2004 return InstallPackages(Cache
,false,false);
2006 return InstallPackages(Cache
,false);
2009 /* mark packages as automatically/manually installed. */
2010 bool DoMarkAuto(CommandLine
&CmdL
)
2013 int AutoMarkChanged
= 0;
2014 OpTextProgress progress
;
2016 if (Cache
.Open() == false)
2019 if (strcasecmp(CmdL
.FileList
[0],"markauto") == 0)
2021 else if (strcasecmp(CmdL
.FileList
[0],"unmarkauto") == 0)
2024 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
2027 // Locate the package
2028 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
2029 if (Pkg
.end() == true) {
2030 return _error
->Error(_("Couldn't find package %s"),S
);
2035 ioprintf(c1out
,_("%s set to manually installed.\n"), Pkg
.Name());
2037 ioprintf(c1out
,_("%s set to automatically installed.\n"),
2040 Cache
->MarkAuto(Pkg
,Action
);
2044 if (AutoMarkChanged
&& ! _config
->FindB("APT::Get::Simulate",false))
2045 return Cache
->writeStateFile(NULL
);
2049 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
2050 // ---------------------------------------------------------------------
2051 /* Intelligent upgrader that will install and remove packages at will */
2052 bool DoDistUpgrade(CommandLine
&CmdL
)
2055 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
2058 c0out
<< _("Calculating upgrade... ") << flush
;
2059 if (pkgDistUpgrade(*Cache
) == false)
2061 c0out
<< _("Failed") << endl
;
2062 ShowBroken(c1out
,Cache
,false);
2066 c0out
<< _("Done") << endl
;
2068 return InstallPackages(Cache
,true);
2071 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
2072 // ---------------------------------------------------------------------
2073 /* Follows dselect's selections */
2074 bool DoDSelectUpgrade(CommandLine
&CmdL
)
2077 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
2080 pkgDepCache::ActionGroup
group(Cache
);
2082 // Install everything with the install flag set
2083 pkgCache::PkgIterator I
= Cache
->PkgBegin();
2084 for (;I
.end() != true; I
++)
2086 /* Install the package only if it is a new install, the autoupgrader
2087 will deal with the rest */
2088 if (I
->SelectedState
== pkgCache::State::Install
)
2089 Cache
->MarkInstall(I
,false);
2092 /* Now install their deps too, if we do this above then order of
2093 the status file is significant for | groups */
2094 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
2096 /* Install the package only if it is a new install, the autoupgrader
2097 will deal with the rest */
2098 if (I
->SelectedState
== pkgCache::State::Install
)
2099 Cache
->MarkInstall(I
,true);
2102 // Apply erasures now, they override everything else.
2103 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
2106 if (I
->SelectedState
== pkgCache::State::DeInstall
||
2107 I
->SelectedState
== pkgCache::State::Purge
)
2108 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
2111 /* Resolve any problems that dselect created, allupgrade cannot handle
2112 such things. We do so quite agressively too.. */
2113 if (Cache
->BrokenCount() != 0)
2115 pkgProblemResolver
Fix(Cache
);
2117 // Hold back held packages.
2118 if (_config
->FindB("APT::Ignore-Hold",false) == false)
2120 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
2122 if (I
->SelectedState
== pkgCache::State::Hold
)
2130 if (Fix
.Resolve() == false)
2132 ShowBroken(c1out
,Cache
,false);
2133 return _error
->Error(_("Internal error, problem resolver broke stuff"));
2137 // Now upgrade everything
2138 if (pkgAllUpgrade(Cache
) == false)
2140 ShowBroken(c1out
,Cache
,false);
2141 return _error
->Error(_("Internal error, problem resolver broke stuff"));
2144 return InstallPackages(Cache
,false);
2147 // DoClean - Remove download archives /*{{{*/
2148 // ---------------------------------------------------------------------
2150 bool DoClean(CommandLine
&CmdL
)
2152 if (_config
->FindB("APT::Get::Simulate") == true)
2154 cout
<< "Del " << _config
->FindDir("Dir::Cache::archives") << "* " <<
2155 _config
->FindDir("Dir::Cache::archives") << "partial/*" << endl
;
2159 // Lock the archive directory
2161 if (_config
->FindB("Debug::NoLocking",false) == false)
2163 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
2164 if (_error
->PendingError() == true)
2165 return _error
->Error(_("Unable to lock the download directory"));
2169 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
2170 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
2174 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
2175 // ---------------------------------------------------------------------
2176 /* This is similar to clean but it only purges things that cannot be
2177 downloaded, that is old versions of cached packages. */
2178 class LogCleaner
: public pkgArchiveCleaner
2181 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
2183 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
2185 if (_config
->FindB("APT::Get::Simulate") == false)
2190 bool DoAutoClean(CommandLine
&CmdL
)
2192 // Lock the archive directory
2194 if (_config
->FindB("Debug::NoLocking",false) == false)
2196 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
2197 if (_error
->PendingError() == true)
2198 return _error
->Error(_("Unable to lock the download directory"));
2202 if (Cache
.Open() == false)
2207 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
2208 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
2211 // DoCheck - Perform the check operation /*{{{*/
2212 // ---------------------------------------------------------------------
2213 /* Opening automatically checks the system, this command is mostly used
2215 bool DoCheck(CommandLine
&CmdL
)
2224 // DoSource - Fetch a source archive /*{{{*/
2225 // ---------------------------------------------------------------------
2226 /* Fetch souce packages */
2234 bool DoSource(CommandLine
&CmdL
)
2237 if (Cache
.Open(false) == false)
2240 if (CmdL
.FileSize() <= 1)
2241 return _error
->Error(_("Must specify at least one package to fetch source for"));
2243 // Read the source list
2245 if (List
.ReadMainList() == false)
2246 return _error
->Error(_("The list of sources could not be read."));
2248 // Create the text record parsers
2249 pkgRecords
Recs(Cache
);
2250 pkgSrcRecords
SrcRecs(List
);
2251 if (_error
->PendingError() == true)
2254 // Create the download object
2255 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
2257 if (Fetcher
.Setup(&Stat
) == false)
2260 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
2262 // insert all downloaded uris into this set to avoid downloading them
2266 // Diff only mode only fetches .diff files
2267 bool const diffOnly
= _config
->FindB("APT::Get::Diff-Only", false);
2268 // Tar only mode only fetches .tar files
2269 bool const tarOnly
= _config
->FindB("APT::Get::Tar-Only", false);
2270 // Dsc only mode only fetches .dsc files
2271 bool const dscOnly
= _config
->FindB("APT::Get::Dsc-Only", false);
2273 // Load the requestd sources into the fetcher
2275 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
2278 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
2281 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
2284 vector
<pkgSrcRecords::File
> Lst
;
2285 if (Last
->Files(Lst
) == false)
2288 // Load them into the fetcher
2289 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
2290 I
!= Lst
.end(); I
++)
2292 // Try to guess what sort of file it is we are getting.
2293 if (I
->Type
== "dsc")
2295 Dsc
[J
].Package
= Last
->Package();
2296 Dsc
[J
].Version
= Last
->Version();
2297 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
2300 // Handle the only options so that multiple can be used at once
2301 if (diffOnly
== true || tarOnly
== true || dscOnly
== true)
2303 if ((diffOnly
== true && I
->Type
== "diff") ||
2304 (tarOnly
== true && I
->Type
== "tar") ||
2305 (dscOnly
== true && I
->Type
== "dsc"))
2306 ; // Fine, we want this file downloaded
2311 // don't download the same uri twice (should this be moved to
2312 // the fetcher interface itself?)
2313 if(queued
.find(Last
->Index().ArchiveURI(I
->Path
)) != queued
.end())
2315 queued
.insert(Last
->Index().ArchiveURI(I
->Path
));
2317 // check if we have a file with that md5 sum already localy
2318 if(!I
->MD5Hash
.empty() && FileExists(flNotDir(I
->Path
)))
2320 FileFd
Fd(flNotDir(I
->Path
), FileFd::ReadOnly
);
2322 sum
.AddFD(Fd
.Fd(), Fd
.Size());
2324 if((string
)sum
.Result() == I
->MD5Hash
)
2326 ioprintf(c1out
,_("Skipping already downloaded file '%s'\n"),
2327 flNotDir(I
->Path
).c_str());
2332 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
2334 Last
->Index().SourceInfo(*Last
,*I
),Src
);
2338 // Display statistics
2339 double FetchBytes
= Fetcher
.FetchNeeded();
2340 double FetchPBytes
= Fetcher
.PartialPresent();
2341 double DebBytes
= Fetcher
.TotalNeeded();
2343 // Check for enough free space
2345 string OutputDir
= ".";
2346 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
2347 if (errno
== EOVERFLOW
)
2348 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
2351 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
2353 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
2356 if (statfs(OutputDir
.c_str(),&Stat
) != 0
2357 #if HAVE_STRUCT_STATFS_F_TYPE
2358 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
2361 return _error
->Error(_("You don't have enough free space in %s"),
2366 if (DebBytes
!= FetchBytes
)
2367 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
2368 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
2370 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
2371 SizeToStr(DebBytes
).c_str());
2373 if (_config
->FindB("APT::Get::Simulate",false) == true)
2375 for (unsigned I
= 0; I
!= J
; I
++)
2376 ioprintf(cout
,_("Fetch source %s\n"),Dsc
[I
].Package
.c_str());
2381 // Just print out the uris an exit if the --print-uris flag was used
2382 if (_config
->FindB("APT::Get::Print-URIs") == true)
2384 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
2385 for (; I
!= Fetcher
.UriEnd(); I
++)
2386 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
2387 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
2393 if (Fetcher
.Run() == pkgAcquire::Failed
)
2396 // Print error messages
2397 bool Failed
= false;
2398 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
2400 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
2401 (*I
)->Complete
== true)
2404 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
2405 (*I
)->ErrorText
.c_str());
2409 return _error
->Error(_("Failed to fetch some archives."));
2411 if (_config
->FindB("APT::Get::Download-only",false) == true)
2413 c1out
<< _("Download complete and in download only mode") << endl
;
2418 // Unpack the sources
2419 pid_t Process
= ExecFork();
2423 bool const fixBroken
= _config
->FindB("APT::Get::Fix-Broken", false);
2424 for (unsigned I
= 0; I
!= J
; I
++)
2426 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
2428 // Diff only mode only fetches .diff files
2429 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
2430 _config
->FindB("APT::Get::Tar-Only",false) == true ||
2431 Dsc
[I
].Dsc
.empty() == true)
2434 // See if the package is already unpacked
2436 if (fixBroken
== false && stat(Dir
.c_str(),&Stat
) == 0 &&
2437 S_ISDIR(Stat
.st_mode
) != 0)
2439 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
2446 snprintf(S
,sizeof(S
),"%s -x %s",
2447 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
2448 Dsc
[I
].Dsc
.c_str());
2451 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
2452 fprintf(stderr
,_("Check if the 'dpkg-dev' package is installed.\n"));
2457 // Try to compile it with dpkg-buildpackage
2458 if (_config
->FindB("APT::Get::Compile",false) == true)
2460 // Call dpkg-buildpackage
2462 snprintf(S
,sizeof(S
),"cd %s && %s %s",
2464 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
2465 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
2469 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
2479 // Wait for the subprocess
2481 while (waitpid(Process
,&Status
,0) != Process
)
2485 return _error
->Errno("waitpid","Couldn't wait for subprocess");
2488 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
2489 return _error
->Error(_("Child process failed"));
2494 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
2495 // ---------------------------------------------------------------------
2496 /* This function will look at the build depends list of the given source
2497 package and install the necessary packages to make it true, or fail. */
2498 bool DoBuildDep(CommandLine
&CmdL
)
2501 if (Cache
.Open(true) == false)
2504 if (CmdL
.FileSize() <= 1)
2505 return _error
->Error(_("Must specify at least one package to check builddeps for"));
2507 // Read the source list
2509 if (List
.ReadMainList() == false)
2510 return _error
->Error(_("The list of sources could not be read."));
2512 // Create the text record parsers
2513 pkgRecords
Recs(Cache
);
2514 pkgSrcRecords
SrcRecs(List
);
2515 if (_error
->PendingError() == true)
2518 // Create the download object
2519 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
2521 if (Fetcher
.Setup(&Stat
) == false)
2525 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
2528 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
2530 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
2532 // Process the build-dependencies
2533 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
2534 if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only",true)) == false)
2535 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
2537 // Also ensure that build-essential packages are present
2538 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
2541 for (; Opts
; Opts
= Opts
->Next
)
2543 if (Opts
->Value
.empty() == true)
2546 pkgSrcRecords::Parser::BuildDepRec rec
;
2547 rec
.Package
= Opts
->Value
;
2548 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
2550 BuildDeps
.push_back(rec
);
2553 if (BuildDeps
.size() == 0)
2555 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
2559 // Install the requested packages
2560 unsigned int ExpectedInst
= 0;
2561 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
2562 pkgProblemResolver
Fix(Cache
);
2563 bool skipAlternatives
= false; // skip remaining alternatives in an or group
2564 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); D
++)
2566 bool hasAlternatives
= (((*D
).Op
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
);
2568 if (skipAlternatives
== true)
2570 if (!hasAlternatives
)
2571 skipAlternatives
= false; // end of or group
2575 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
2576 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
2578 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
2579 // Build-conflicts on unknown packages are silently ignored
2580 if (Pkg
.end() == true)
2583 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
2586 * Remove if we have an installed version that satisfies the
2589 if (IV
.end() == false &&
2590 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2591 TryToInstall(Pkg
,Cache
,Fix
,true,false,ExpectedInst
);
2593 else // BuildDep || BuildDepIndep
2595 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
2596 if (_config
->FindB("Debug::BuildDeps",false) == true)
2597 cout
<< "Looking for " << (*D
).Package
<< "...\n";
2599 if (Pkg
.end() == true)
2601 if (_config
->FindB("Debug::BuildDeps",false) == true)
2602 cout
<< " (not found)" << (*D
).Package
<< endl
;
2604 if (hasAlternatives
)
2607 return _error
->Error(_("%s dependency for %s cannot be satisfied "
2608 "because the package %s cannot be found"),
2609 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
2610 (*D
).Package
.c_str());
2614 * if there are alternatives, we've already picked one, so skip
2617 * TODO: this means that if there's a build-dep on A|B and B is
2618 * installed, we'll still try to install A; more importantly,
2619 * if A is currently broken, we cannot go back and try B. To fix
2620 * this would require we do a Resolve cycle for each package we
2621 * add to the install list. Ugh
2625 * If this is a virtual package, we need to check the list of
2626 * packages that provide it and see if any of those are
2629 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
2630 for (; Prv
.end() != true; Prv
++)
2632 if (_config
->FindB("Debug::BuildDeps",false) == true)
2633 cout
<< " Checking provider " << Prv
.OwnerPkg().FullName() << endl
;
2635 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
2639 // Get installed version and version we are going to install
2640 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
2642 if ((*D
).Version
[0] != '\0') {
2643 // Versioned dependency
2645 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
2647 for (; CV
.end() != true; CV
++)
2649 if (Cache
->VS().CheckDep(CV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2652 if (CV
.end() == true)
2654 if (hasAlternatives
)
2660 return _error
->Error(_("%s dependency for %s cannot be satisfied "
2661 "because no available versions of package %s "
2662 "can satisfy version requirements"),
2663 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
2664 (*D
).Package
.c_str());
2670 // Only consider virtual packages if there is no versioned dependency
2671 if (Prv
.end() == false)
2673 if (_config
->FindB("Debug::BuildDeps",false) == true)
2674 cout
<< " Is provided by installed package " << Prv
.OwnerPkg().FullName() << endl
;
2675 skipAlternatives
= hasAlternatives
;
2680 if (IV
.end() == false)
2682 if (_config
->FindB("Debug::BuildDeps",false) == true)
2683 cout
<< " Is installed\n";
2685 if (Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2687 skipAlternatives
= hasAlternatives
;
2691 if (_config
->FindB("Debug::BuildDeps",false) == true)
2692 cout
<< " ...but the installed version doesn't meet the version requirement\n";
2694 if (((*D
).Op
& pkgCache::Dep::LessEq
) == pkgCache::Dep::LessEq
)
2696 return _error
->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
2697 Last
->BuildDepType((*D
).Type
),
2699 Pkg
.FullName(true).c_str());
2704 if (_config
->FindB("Debug::BuildDeps",false) == true)
2705 cout
<< " Trying to install " << (*D
).Package
<< endl
;
2707 if (TryToInstall(Pkg
,Cache
,Fix
,false,false,ExpectedInst
) == true)
2709 // We successfully installed something; skip remaining alternatives
2710 skipAlternatives
= hasAlternatives
;
2711 if(_config
->FindB("APT::Get::Build-Dep-Automatic", false) == true)
2712 Cache
->MarkAuto(Pkg
, true);
2715 else if (hasAlternatives
)
2717 if (_config
->FindB("Debug::BuildDeps",false) == true)
2718 cout
<< " Unsatisfiable, trying alternatives\n";
2723 return _error
->Error(_("Failed to satisfy %s dependency for %s: %s"),
2724 Last
->BuildDepType((*D
).Type
),
2726 (*D
).Package
.c_str());
2731 Fix
.InstallProtect();
2732 if (Fix
.Resolve(true) == false)
2735 // Now we check the state of the packages,
2736 if (Cache
->BrokenCount() != 0)
2738 ShowBroken(cout
, Cache
, false);
2739 return _error
->Error(_("Build-dependencies for %s could not be satisfied."),*I
);
2743 if (InstallPackages(Cache
, false, true) == false)
2744 return _error
->Error(_("Failed to process build dependencies"));
2748 // DoMoo - Never Ask, Never Tell /*{{{*/
2749 // ---------------------------------------------------------------------
2751 bool DoMoo(CommandLine
&CmdL
)
2760 "....\"Have you mooed today?\"...\n";
2765 // ShowHelp - Show a help screen /*{{{*/
2766 // ---------------------------------------------------------------------
2768 bool ShowHelp(CommandLine
&CmdL
)
2770 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,VERSION
,
2771 COMMON_ARCH
,__DATE__
,__TIME__
);
2773 if (_config
->FindB("version") == true)
2775 cout
<< _("Supported modules:") << endl
;
2777 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
2779 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
2780 if (_system
!= 0 && _system
->VS
== VS
)
2784 cout
<< "Ver: " << VS
->Label
<< endl
;
2786 /* Print out all the packaging systems that will work with
2788 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
2790 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
2795 if (Sys
->VS
->TestCompatibility(*VS
) == true)
2796 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
2800 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
2802 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
2803 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
2806 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
2808 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
2809 cout
<< " Idx: " << Type
->Label
<< endl
;
2816 _("Usage: apt-get [options] command\n"
2817 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
2818 " apt-get [options] source pkg1 [pkg2 ...]\n"
2820 "apt-get is a simple command line interface for downloading and\n"
2821 "installing packages. The most frequently used commands are update\n"
2825 " update - Retrieve new lists of packages\n"
2826 " upgrade - Perform an upgrade\n"
2827 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
2828 " remove - Remove packages\n"
2829 " autoremove - Remove automatically all unused packages\n"
2830 " purge - Remove packages and config files\n"
2831 " source - Download source archives\n"
2832 " build-dep - Configure build-dependencies for source packages\n"
2833 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
2834 " dselect-upgrade - Follow dselect selections\n"
2835 " clean - Erase downloaded archive files\n"
2836 " autoclean - Erase old downloaded archive files\n"
2837 " check - Verify that there are no broken dependencies\n"
2838 " markauto - Mark the given packages as automatically installed\n"
2839 " unmarkauto - Mark the given packages as manually installed\n"
2842 " -h This help text.\n"
2843 " -q Loggable output - no progress indicator\n"
2844 " -qq No output except for errors\n"
2845 " -d Download only - do NOT install or unpack archives\n"
2846 " -s No-act. Perform ordering simulation\n"
2847 " -y Assume Yes to all queries and do not prompt\n"
2848 " -f Attempt to correct a system with broken dependencies in place\n"
2849 " -m Attempt to continue if archives are unlocatable\n"
2850 " -u Show a list of upgraded packages as well\n"
2851 " -b Build the source package after fetching it\n"
2852 " -V Show verbose version numbers\n"
2853 " -c=? Read this configuration file\n"
2854 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
2855 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
2856 "pages for more information and options.\n"
2857 " This APT has Super Cow Powers.\n");
2861 // GetInitialize - Initialize things for apt-get /*{{{*/
2862 // ---------------------------------------------------------------------
2864 void GetInitialize()
2866 _config
->Set("quiet",0);
2867 _config
->Set("help",false);
2868 _config
->Set("APT::Get::Download-Only",false);
2869 _config
->Set("APT::Get::Simulate",false);
2870 _config
->Set("APT::Get::Assume-Yes",false);
2871 _config
->Set("APT::Get::Fix-Broken",false);
2872 _config
->Set("APT::Get::Force-Yes",false);
2873 _config
->Set("APT::Get::List-Cleanup",true);
2874 _config
->Set("APT::Get::AutomaticRemove",false);
2877 // SigWinch - Window size change signal handler /*{{{*/
2878 // ---------------------------------------------------------------------
2882 // Riped from GNU ls
2886 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
2887 ScreenWidth
= ws
.ws_col
- 1;
2891 int main(int argc
,const char *argv
[]) /*{{{*/
2893 CommandLine::Args Args
[] = {
2894 {'h',"help","help",0},
2895 {'v',"version","version",0},
2896 {'V',"verbose-versions","APT::Get::Show-Versions",0},
2897 {'q',"quiet","quiet",CommandLine::IntLevel
},
2898 {'q',"silent","quiet",CommandLine::IntLevel
},
2899 {'d',"download-only","APT::Get::Download-Only",0},
2900 {'b',"compile","APT::Get::Compile",0},
2901 {'b',"build","APT::Get::Compile",0},
2902 {'s',"simulate","APT::Get::Simulate",0},
2903 {'s',"just-print","APT::Get::Simulate",0},
2904 {'s',"recon","APT::Get::Simulate",0},
2905 {'s',"dry-run","APT::Get::Simulate",0},
2906 {'s',"no-act","APT::Get::Simulate",0},
2907 {'y',"yes","APT::Get::Assume-Yes",0},
2908 {'y',"assume-yes","APT::Get::Assume-Yes",0},
2909 {'f',"fix-broken","APT::Get::Fix-Broken",0},
2910 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
2911 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
2912 {'t',"target-release","APT::Default-Release",CommandLine::HasArg
},
2913 {'t',"default-release","APT::Default-Release",CommandLine::HasArg
},
2914 {0,"download","APT::Get::Download",0},
2915 {0,"fix-missing","APT::Get::Fix-Missing",0},
2916 {0,"ignore-hold","APT::Ignore-Hold",0},
2917 {0,"upgrade","APT::Get::upgrade",0},
2918 {0,"only-upgrade","APT::Get::Only-Upgrade",0},
2919 {0,"force-yes","APT::Get::force-yes",0},
2920 {0,"print-uris","APT::Get::Print-URIs",0},
2921 {0,"diff-only","APT::Get::Diff-Only",0},
2922 {0,"debian-only","APT::Get::Diff-Only",0},
2923 {0,"tar-only","APT::Get::Tar-Only",0},
2924 {0,"dsc-only","APT::Get::Dsc-Only",0},
2925 {0,"purge","APT::Get::Purge",0},
2926 {0,"list-cleanup","APT::Get::List-Cleanup",0},
2927 {0,"reinstall","APT::Get::ReInstall",0},
2928 {0,"trivial-only","APT::Get::Trivial-Only",0},
2929 {0,"remove","APT::Get::Remove",0},
2930 {0,"only-source","APT::Get::Only-Source",0},
2931 {0,"arch-only","APT::Get::Arch-Only",0},
2932 {0,"auto-remove","APT::Get::AutomaticRemove",0},
2933 {0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0},
2934 {0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean
},
2935 {0,"fix-policy","APT::Get::Fix-Policy-Broken",0},
2936 {'c',"config-file",0,CommandLine::ConfigFile
},
2937 {'o',"option",0,CommandLine::ArbItem
},
2939 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
2940 {"upgrade",&DoUpgrade
},
2941 {"install",&DoInstall
},
2942 {"remove",&DoInstall
},
2943 {"purge",&DoInstall
},
2944 {"autoremove",&DoInstall
},
2945 {"purge",&DoInstall
},
2946 {"markauto",&DoMarkAuto
},
2947 {"unmarkauto",&DoMarkAuto
},
2948 {"dist-upgrade",&DoDistUpgrade
},
2949 {"dselect-upgrade",&DoDSelectUpgrade
},
2950 {"build-dep",&DoBuildDep
},
2952 {"autoclean",&DoAutoClean
},
2954 {"source",&DoSource
},
2959 // Set up gettext support
2960 setlocale(LC_ALL
,"");
2961 textdomain(PACKAGE
);
2963 // Parse the command line and initialize the package library
2964 CommandLine
CmdL(Args
,_config
);
2965 if (pkgInitConfig(*_config
) == false ||
2966 CmdL
.Parse(argc
,argv
) == false ||
2967 pkgInitSystem(*_config
,_system
) == false)
2969 if (_config
->FindB("version") == true)
2972 _error
->DumpErrors();
2976 // See if the help should be shown
2977 if (_config
->FindB("help") == true ||
2978 _config
->FindB("version") == true ||
2979 CmdL
.FileSize() == 0)
2985 // simulate user-friendly if apt-get has no root privileges
2986 if (getuid() != 0 && _config
->FindB("APT::Get::Simulate") == true)
2988 if (_config
->FindB("APT::Get::Show-User-Simulation-Note",true) == true)
2989 cout
<< _("NOTE: This is only a simulation!\n"
2990 " apt-get needs root privileges for real execution.\n"
2991 " Keep also in mind that locking is deactivated,\n"
2992 " so don't depend on the relevance to the real current situation!"
2994 _config
->Set("Debug::NoLocking",true);
2997 // Deal with stdout not being a tty
2998 if (!isatty(STDOUT_FILENO
) && _config
->FindI("quiet",0) < 1)
2999 _config
->Set("quiet","1");
3001 // Setup the output streams
3002 c0out
.rdbuf(cout
.rdbuf());
3003 c1out
.rdbuf(cout
.rdbuf());
3004 c2out
.rdbuf(cout
.rdbuf());
3005 if (_config
->FindI("quiet",0) > 0)
3006 c0out
.rdbuf(devnull
.rdbuf());
3007 if (_config
->FindI("quiet",0) > 1)
3008 c1out
.rdbuf(devnull
.rdbuf());
3010 // Setup the signals
3011 signal(SIGPIPE
,SIG_IGN
);
3012 signal(SIGWINCH
,SigWinch
);
3015 // Match the operation
3016 CmdL
.DispatchArg(Cmds
);
3018 // Print any errors or warnings found during parsing
3019 if (_error
->empty() == false)
3021 bool Errors
= _error
->PendingError();
3022 _error
->DumpErrors();
3023 return Errors
== true?100:0;