]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
e79bb391388e09d80e1fb792913198cfa14ca4dc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.108 2001/07/01 20:49:08 jgg 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/versionmatch.h>
46 #include "acqprogress.h"
50 #include <sys/ioctl.h>
52 #include <sys/statvfs.h>
66 ofstream
devnull("/dev/null");
67 unsigned int ScreenWidth
= 80;
69 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
70 // ---------------------------------------------------------------------
72 class CacheFile
: public pkgCacheFile
74 static pkgCache
*SortCache
;
75 static int NameComp(const void *a
,const void *b
);
78 pkgCache::Package
**List
;
81 bool CheckDeps(bool AllowBroken
= false);
82 bool Open(bool WithLock
= true)
84 OpTextProgress
Prog(*_config
);
85 if (pkgCacheFile::Open(Prog
,WithLock
) == false)
93 if (_config
->FindB("APT::Get::Print-URIs") == true)
98 CacheFile() : List(0) {};
102 // YnPrompt - Yes No Prompt. /*{{{*/
103 // ---------------------------------------------------------------------
104 /* Returns true on a Yes.*/
107 // This needs to be a capital
108 const char *Yes
= _("Y");
110 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
112 c1out
<< Yes
<< endl
;
118 if (read(STDIN_FILENO
,&C
,1) != 1)
120 while (C
!= '\n' && Jnk
!= '\n')
121 if (read(STDIN_FILENO
,&Jnk
,1) != 1)
124 if (!(toupper(C
) == *Yes
|| C
== '\n' || C
== '\r'))
129 // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
130 // ---------------------------------------------------------------------
131 /* Returns true on a Yes.*/
132 bool AnalPrompt(const char *Text
)
135 cin
.getline(Buf
,sizeof(Buf
));
136 if (strcmp(Buf
,Text
) == 0)
141 // ShowList - Show a list /*{{{*/
142 // ---------------------------------------------------------------------
143 /* This prints out a string of space separated words with a title and
144 a two space indent line wraped to the current screen width. */
145 bool ShowList(ostream
&out
,string Title
,string List
)
147 if (List
.empty() == true)
150 // Acount for the leading space
151 int ScreenWidth
= ::ScreenWidth
- 3;
153 out
<< Title
<< endl
;
154 string::size_type Start
= 0;
155 while (Start
< List
.size())
157 string::size_type End
;
158 if (Start
+ ScreenWidth
>= List
.size())
161 End
= List
.rfind(' ',Start
+ScreenWidth
);
163 if (End
== string::npos
|| End
< Start
)
164 End
= Start
+ ScreenWidth
;
165 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
171 // ShowBroken - Debugging aide /*{{{*/
172 // ---------------------------------------------------------------------
173 /* This prints out the names of all the packages that are broken along
174 with the name of each each broken dependency and a quite version
177 The output looks like:
178 Sorry, but the following packages have unmet dependencies:
179 exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed
180 Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
181 Depends: libsasl7 but it is not going to be installed
183 void ShowBroken(ostream
&out
,CacheFile
&Cache
,bool Now
)
185 out
<< _("Sorry, but the following packages have unmet dependencies:") << endl
;
186 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
188 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
190 if (Cache
[I
].InstBroken() == false)
193 // Print out each package and the failed dependencies
194 out
<<" " << I
.Name() << ":";
195 unsigned Indent
= strlen(I
.Name()) + 3;
197 if (Cache
[I
].InstVerIter(Cache
).end() == true)
203 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
205 // Compute a single dependency element (glob or)
206 pkgCache::DepIterator Start
;
207 pkgCache::DepIterator End
;
210 if (Cache
->IsImportantDep(End
) == false ||
211 (Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
218 for (unsigned J
= 0; J
!= Indent
; J
++)
222 if (FirstOr
== false)
224 for (unsigned J
= 0; J
!= strlen(End
.DepType()) + 3; J
++)
228 out
<< ' ' << End
.DepType() << ": ";
231 out
<< Start
.TargetPkg().Name();
233 // Show a quick summary of the version requirements
234 if (Start
.TargetVer() != 0)
235 out
<< " (" << Start
.CompType() << " " << Start
.TargetVer() << ")";
237 /* Show a summary of the target package if possible. In the case
238 of virtual packages we show nothing */
239 pkgCache::PkgIterator Targ
= Start
.TargetPkg();
240 if (Targ
->ProvidesList
== 0)
243 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
245 Ver
= Targ
.CurrentVer();
247 if (Ver
.end() == false)
250 ioprintf(out
,_("but %s is installed"),Ver
.VerStr());
252 ioprintf(out
,_("but %s is to be installed"),Ver
.VerStr());
256 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
258 if (Targ
->ProvidesList
== 0)
259 out
<< _("but it is not installable");
261 out
<< _("but it is a virtual package");
264 out
<< (Now
?_("but it is not installed"):_("but it is not going to be installed"));
280 // ShowNew - Show packages to newly install /*{{{*/
281 // ---------------------------------------------------------------------
283 void ShowNew(ostream
&out
,CacheFile
&Cache
)
285 /* Print out a list of packages that are going to be removed extra
286 to what the user asked */
288 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
290 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
291 if (Cache
[I
].NewInstall() == true)
292 List
+= string(I
.Name()) + " ";
295 ShowList(out
,_("The following NEW packages will be installed:"),List
);
298 // ShowDel - Show packages to delete /*{{{*/
299 // ---------------------------------------------------------------------
301 void ShowDel(ostream
&out
,CacheFile
&Cache
)
303 /* Print out a list of packages that are going to be removed extra
304 to what the user asked */
306 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
308 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
309 if (Cache
[I
].Delete() == true)
311 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
312 List
+= string(I
.Name()) + "* ";
314 List
+= string(I
.Name()) + " ";
318 ShowList(out
,_("The following packages will be REMOVED:"),List
);
321 // ShowKept - Show kept packages /*{{{*/
322 // ---------------------------------------------------------------------
324 void ShowKept(ostream
&out
,CacheFile
&Cache
)
327 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
329 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
332 if (Cache
[I
].Upgrade() == true || Cache
[I
].Upgradable() == false ||
333 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
336 List
+= string(I
.Name()) + " ";
338 ShowList(out
,_("The following packages have been kept back"),List
);
341 // ShowUpgraded - Show upgraded packages /*{{{*/
342 // ---------------------------------------------------------------------
344 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
347 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
349 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
352 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
355 List
+= string(I
.Name()) + " ";
357 ShowList(out
,_("The following packages will be upgraded"),List
);
360 // ShowDowngraded - Show downgraded packages /*{{{*/
361 // ---------------------------------------------------------------------
363 bool ShowDowngraded(ostream
&out
,CacheFile
&Cache
)
366 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
368 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
371 if (Cache
[I
].Downgrade() == false || Cache
[I
].NewInstall() == true)
374 List
+= string(I
.Name()) + " ";
376 return ShowList(out
,_("The following packages will be DOWNGRADED"),List
);
379 // ShowHold - Show held but changed packages /*{{{*/
380 // ---------------------------------------------------------------------
382 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
385 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
387 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
388 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
389 I
->SelectedState
== pkgCache::State::Hold
)
390 List
+= string(I
.Name()) + " ";
393 return ShowList(out
,_("The following held packages will be changed:"),List
);
396 // ShowEssential - Show an essential package warning /*{{{*/
397 // ---------------------------------------------------------------------
398 /* This prints out a warning message that is not to be ignored. It shows
399 all essential packages and their dependents that are to be removed.
400 It is insanely risky to remove the dependents of an essential package! */
401 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
404 bool *Added
= new bool[Cache
->Head().PackageCount
];
405 for (unsigned int I
= 0; I
!= Cache
->Head().PackageCount
; I
++)
408 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
410 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
411 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
&&
412 (I
->Flags
& pkgCache::Flag::Important
) != pkgCache::Flag::Important
)
415 // The essential package is being removed
416 if (Cache
[I
].Delete() == true)
418 if (Added
[I
->ID
] == false)
421 List
+= string(I
.Name()) + " ";
425 if (I
->CurrentVer
== 0)
428 // Print out any essential package depenendents that are to be removed
429 for (pkgCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
431 // Skip everything but depends
432 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
433 D
->Type
!= pkgCache::Dep::Depends
)
436 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
437 if (Cache
[P
].Delete() == true)
439 if (Added
[P
->ID
] == true)
444 snprintf(S
,sizeof(S
),_("%s (due to %s) "),P
.Name(),I
.Name());
451 return ShowList(out
,_("WARNING: The following essential packages will be removed\n"
452 "This should NOT be done unless you know exactly what you are doing!"),List
);
455 // Stats - Show some statistics /*{{{*/
456 // ---------------------------------------------------------------------
458 void Stats(ostream
&out
,pkgDepCache
&Dep
)
460 unsigned long Upgrade
= 0;
461 unsigned long Downgrade
= 0;
462 unsigned long Install
= 0;
463 unsigned long ReInstall
= 0;
464 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
466 if (Dep
[I
].NewInstall() == true)
470 if (Dep
[I
].Upgrade() == true)
473 if (Dep
[I
].Downgrade() == true)
477 if (Dep
[I
].Delete() == false && (Dep
[I
].iFlags
& pkgDepCache::ReInstall
) == pkgDepCache::ReInstall
)
481 ioprintf(out
,_("%lu packages upgraded, %lu newly installed, "),
485 ioprintf(out
,_("%lu reinstalled, "),ReInstall
);
487 ioprintf(out
,_("%lu downgraded, "),Downgrade
);
489 ioprintf(out
,_("%lu to remove and %lu not upgraded.\n"),
490 Dep
.DelCount(),Dep
.KeepCount());
492 if (Dep
.BadCount() != 0)
493 ioprintf(out
,_("%lu packages not fully installed or removed.\n"),
498 // CacheFile::NameComp - QSort compare by name /*{{{*/
499 // ---------------------------------------------------------------------
501 pkgCache
*CacheFile::SortCache
= 0;
502 int CacheFile::NameComp(const void *a
,const void *b
)
504 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
505 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
507 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
508 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
510 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
513 // CacheFile::Sort - Sort by name /*{{{*/
514 // ---------------------------------------------------------------------
516 void CacheFile::Sort()
519 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
520 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
521 pkgCache::PkgIterator I
= Cache
->PkgBegin();
522 for (;I
.end() != true; I
++)
526 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
529 // CacheFile::CheckDeps - Open the cache file /*{{{*/
530 // ---------------------------------------------------------------------
531 /* This routine generates the caches and then opens the dependency cache
532 and verifies that the system is OK. */
533 bool CacheFile::CheckDeps(bool AllowBroken
)
535 if (_error
->PendingError() == true)
538 // Check that the system is OK
539 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
540 return _error
->Error("Internal Error, non-zero counts");
542 // Apply corrections for half-installed packages
543 if (pkgApplyStatus(*DCache
) == false)
547 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
550 // Attempt to fix broken things
551 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
553 c1out
<< _("Correcting dependencies...") << flush
;
554 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
556 c1out
<< _(" failed.") << endl
;
557 ShowBroken(c1out
,*this,true);
559 return _error
->Error(_("Unable to correct dependencies"));
561 if (pkgMinimizeUpgrade(*DCache
) == false)
562 return _error
->Error(_("Unable to minimize the upgrade set"));
564 c1out
<< _(" Done") << endl
;
568 c1out
<< _("You might want to run `apt-get -f install' to correct these.") << endl
;
569 ShowBroken(c1out
,*this,true);
571 return _error
->Error(_("Unmet dependencies. Try using -f."));
578 // InstallPackages - Actually download and install the packages /*{{{*/
579 // ---------------------------------------------------------------------
580 /* This displays the informative messages describing what is going to
581 happen and then calls the download routines */
582 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,
585 if (_config
->FindB("APT::Get::Purge",false) == true)
587 pkgCache::PkgIterator I
= Cache
->PkgBegin();
588 for (; I
.end() == false; I
++)
590 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
591 Cache
->MarkDelete(I
,true);
596 bool Essential
= false;
598 // Show all the various warning indicators
599 ShowDel(c1out
,Cache
);
600 ShowNew(c1out
,Cache
);
602 ShowKept(c1out
,Cache
);
603 Fail
|= !ShowHold(c1out
,Cache
);
604 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
605 ShowUpgraded(c1out
,Cache
);
606 Fail
|= !ShowDowngraded(c1out
,Cache
);
607 Essential
= !ShowEssential(c1out
,Cache
);
612 if (Cache
->BrokenCount() != 0)
614 ShowBroken(c1out
,Cache
,false);
615 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
618 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
619 Cache
->BadCount() == 0)
623 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::Remove",true) == false)
624 return _error
->Error(_("Packages need to be removed but Remove is disabled."));
626 // Run the simulator ..
627 if (_config
->FindB("APT::Get::Simulate") == true)
629 pkgSimulate
PM(Cache
);
630 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
631 if (Res
== pkgPackageManager::Failed
)
633 if (Res
!= pkgPackageManager::Completed
)
634 return _error
->Error("Internal Error, Ordering didn't finish");
638 // Create the text record parser
639 pkgRecords
Recs(Cache
);
640 if (_error
->PendingError() == true)
643 // Lock the archive directory
645 if (_config
->FindB("Debug::NoLocking",false) == false &&
646 _config
->FindB("APT::Get::Print-URIs") == false)
648 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
649 if (_error
->PendingError() == true)
650 return _error
->Error(_("Unable to lock the download directory"));
653 // Create the download object
654 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
655 pkgAcquire
Fetcher(&Stat
);
657 // Read the source list
659 if (List
.ReadMainList() == false)
660 return _error
->Error(_("The list of sources could not be read."));
662 // Create the package manager and prepare to download
663 SPtr
<pkgPackageManager
> PM
= _system
->CreatePM(Cache
);
664 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false ||
665 _error
->PendingError() == true)
668 // Display statistics
669 double FetchBytes
= Fetcher
.FetchNeeded();
670 double FetchPBytes
= Fetcher
.PartialPresent();
671 double DebBytes
= Fetcher
.TotalNeeded();
672 if (DebBytes
!= Cache
->DebSize())
674 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
675 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
679 if (DebBytes
!= FetchBytes
)
680 ioprintf(c1out
,_("Need to get %sB/%sB of archives. "),
681 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
683 ioprintf(c1out
,_("Need to get %sB of archives. "),
684 SizeToStr(DebBytes
).c_str());
687 if (Cache
->UsrSize() >= 0)
688 ioprintf(c1out
,_("After unpacking %sB will be used.\n"),
689 SizeToStr(Cache
->UsrSize()).c_str());
691 ioprintf(c1out
,_("After unpacking %sB will be freed.\n"),
692 SizeToStr(-1*Cache
->UsrSize()).c_str());
694 if (_error
->PendingError() == true)
697 /* Check for enough free space, but only if we are actually going to
699 if (_config
->FindB("APT::Get::Print-URIs") == false)
702 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
703 if (statvfs(OutputDir
.c_str(),&Buf
) != 0)
704 return _error
->Errno("statvfs","Couldn't determine free space in %s",
706 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
707 return _error
->Error(_("Sorry, you don't have enough free space in %s to hold all the .debs."),
712 if (_config
->FindI("quiet",0) >= 2 ||
713 _config
->FindB("APT::Get::Assume-Yes",false) == true)
715 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
716 return _error
->Error(_("There are problems and -y was used without --force-yes"));
719 if (Essential
== true && Saftey
== true)
721 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
722 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
724 const char *Prompt
= _("Yes, do as I say!");
726 _("You are about to do something potentially harmful\n"
727 "To continue type in the phrase '%s'\n"
730 if (AnalPrompt(Prompt
) == false)
732 c2out
<< _("Abort.") << endl
;
738 // Prompt to continue
739 if (Ask
== true || Fail
== true)
741 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
742 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
744 if (_config
->FindI("quiet",0) < 2 &&
745 _config
->FindB("APT::Get::Assume-Yes",false) == false)
747 c2out
<< _("Do you want to continue? [Y/n] ") << flush
;
749 if (YnPrompt() == false)
751 c2out
<< _("Abort.") << endl
;
758 // Just print out the uris an exit if the --print-uris flag was used
759 if (_config
->FindB("APT::Get::Print-URIs") == true)
761 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
762 for (; I
!= Fetcher
.UriEnd(); I
++)
763 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
764 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
768 /* Unlock the dpkg lock if we are not going to be doing an install
770 if (_config
->FindB("APT::Get::Download-Only",false) == true)
776 bool Transient
= false;
777 if (_config
->FindB("APT::Get::Download",true) == false)
779 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
781 if ((*I
)->Local
== true)
787 // Close the item and check if it was found in cache
789 if ((*I
)->Complete
== false)
792 // Clear it out of the fetch list
794 I
= Fetcher
.ItemsBegin();
798 if (Fetcher
.Run() == pkgAcquire::Failed
)
803 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
805 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
806 (*I
)->Complete
== true)
809 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
816 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
817 (*I
)->ErrorText
.c_str());
821 /* If we are in no download mode and missing files and there were
822 'failures' then the user must specify -m. Furthermore, there
823 is no such thing as a transient error in no-download mode! */
824 if (Transient
== true &&
825 _config
->FindB("APT::Get::Download",true) == false)
831 if (_config
->FindB("APT::Get::Download-Only",false) == true)
833 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
834 return _error
->Error(_("Some files failed to download"));
835 c1out
<< _("Download complete and in download only mode") << endl
;
839 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
841 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
844 if (Transient
== true && Failed
== true)
845 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
847 // Try to deal with missing package files
848 if (Failed
== true && PM
->FixMissing() == false)
850 cerr
<< _("Unable to correct missing packages.") << endl
;
851 return _error
->Error(_("Aborting Install."));
855 pkgPackageManager::OrderResult Res
= PM
->DoInstall();
856 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
858 if (Res
== pkgPackageManager::Completed
)
861 // Reload the fetcher object and loop again for media swapping
863 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false)
870 // TryToInstall - Try to install a single package /*{{{*/
871 // ---------------------------------------------------------------------
872 /* This used to be inlined in DoInstall, but with the advent of regex package
873 name matching it was split out.. */
874 bool TryToInstall(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
875 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
876 unsigned int &ExpectedInst
,bool AllowFail
= true)
878 /* This is a pure virtual package and there is a single available
880 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0 &&
881 Pkg
.ProvidesList()->NextProvides
== 0)
883 pkgCache::PkgIterator Tmp
= Pkg
.ProvidesList().OwnerPkg();
884 ioprintf(c1out
,_("Note, selecting %s instead of %s\n"),
885 Tmp
.Name(),Pkg
.Name());
889 // Handle the no-upgrade case
890 if (_config
->FindB("APT::Get::upgrade",true) == false &&
891 Pkg
->CurrentVer
!= 0)
893 if (AllowFail
== true)
894 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
899 // Check if there is something at all to install
900 pkgDepCache::StateCache
&State
= Cache
[Pkg
];
901 if (Remove
== true && Pkg
->CurrentVer
== 0)
903 /* We want to continue searching for regex hits, so we return false here
904 otherwise this is not really an error. */
905 if (AllowFail
== false)
907 ioprintf(c1out
,_("Package %s is not installed, so not removed\n"),Pkg
.Name());
911 if (State
.CandidateVer
== 0 && Remove
== false)
913 if (AllowFail
== false)
916 if (Pkg
->ProvidesList
!= 0)
918 ioprintf(c1out
,_("Package %s is a virtual package provided by:\n"),
921 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
922 for (; I
.end() == false; I
++)
924 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
926 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer())
928 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
929 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
930 _(" [Installed]") << endl
;
932 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
935 c1out
<< _("You should explicitly select one to install.") << endl
;
940 _("Package %s has no available version, but exists in the database.\n"
941 "This typically means that the package was mentioned in a dependency and\n"
942 "never uploaded, has been obsoleted or is not available with the contents\n"
943 "of sources.list\n"),Pkg
.Name());
946 SPtrArray
<bool> Seen
= new bool[Cache
.Head().PackageCount
];
947 memset(Seen
,0,Cache
.Head().PackageCount
*sizeof(*Seen
));
948 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
949 for (; Dep
.end() == false; Dep
++)
951 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
953 if (Seen
[Dep
.ParentPkg()->ID
] == true)
955 Seen
[Dep
.ParentPkg()->ID
] = true;
956 List
+= string(Dep
.ParentPkg().Name()) + " ";
958 ShowList(c1out
,_("However the following packages replace it:"),List
);
961 _error
->Error(_("Package %s has no installation candidate"),Pkg
.Name());
970 Cache
.MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
975 Cache
.MarkInstall(Pkg
,false);
976 if (State
.Install() == false)
978 if (_config
->FindB("APT::Get::ReInstall",false) == true)
980 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
981 ioprintf(c1out
,_("Sorry, re-installation of %s is not possible, it cannot be downloaded.\n"),
984 Cache
.SetReInstall(Pkg
,true);
988 if (AllowFail
== true)
989 ioprintf(c1out
,_("Sorry, %s is already the newest version.\n"),
996 // Install it with autoinstalling enabled.
997 if (State
.InstBroken() == true && BrokenFix
== false)
998 Cache
.MarkInstall(Pkg
,true);
1002 // TryToChangeVer - Try to change a candidate version /*{{{*/
1003 // ---------------------------------------------------------------------
1005 bool TryToChangeVer(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
1006 const char *VerTag
,bool IsRel
)
1008 pkgVersionMatch
Match(VerTag
,(IsRel
== true?pkgVersionMatch::Release
:pkgVersionMatch::Version
));
1010 pkgCache::VerIterator Ver
= Match
.Find(Pkg
);
1012 if (Ver
.end() == true)
1015 return _error
->Error(_("Release '%s' for '%s' was not found"),
1017 return _error
->Error(_("Version '%s' for '%s' was not found"),
1021 if (strcmp(VerTag
,Ver
.VerStr()) != 0)
1023 ioprintf(c1out
,_("Selected version %s (%s) for %s\n"),
1024 Ver
.VerStr(),Ver
.RelStr().c_str(),Pkg
.Name());
1027 Cache
.SetCandidateVersion(Ver
);
1031 // FindSrc - Find a source record /*{{{*/
1032 // ---------------------------------------------------------------------
1034 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
1035 pkgSrcRecords
&SrcRecs
,string
&Src
,
1038 // We want to pull the version off the package specification..
1040 string TmpSrc
= Name
;
1041 string::size_type Slash
= TmpSrc
.rfind('=');
1042 if (Slash
!= string::npos
)
1044 VerTag
= string(TmpSrc
.begin() + Slash
+ 1,TmpSrc
.end());
1045 TmpSrc
= string(TmpSrc
.begin(),TmpSrc
.begin() + Slash
);
1048 /* Lookup the version of the package we would install if we were to
1049 install a version and determine the source package name, then look
1050 in the archive for a source package of the same name. In theory
1051 we could stash the version string as well and match that too but
1052 today there aren't multi source versions in the archive. */
1053 if (_config
->FindB("APT::Get::Only-Source") == false &&
1054 VerTag
.empty() == true)
1056 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(TmpSrc
);
1057 if (Pkg
.end() == false)
1059 pkgCache::VerIterator Ver
= Cache
.GetCandidateVer(Pkg
);
1060 if (Ver
.end() == false)
1062 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1063 Src
= Parse
.SourcePkg();
1068 // No source package name..
1069 if (Src
.empty() == true)
1073 pkgSrcRecords::Parser
*Last
= 0;
1074 unsigned long Offset
= 0;
1076 bool IsMatch
= false;
1078 // If we are matching by version then we need exact matches to be happy
1079 if (VerTag
.empty() == false)
1082 /* Iterate over all of the hits, which includes the resulting
1083 binary packages in the search */
1084 pkgSrcRecords::Parser
*Parse
;
1086 while ((Parse
= SrcRecs
.Find(Src
.c_str(),false)) != 0)
1088 string Ver
= Parse
->Version();
1090 // Skip name mismatches
1091 if (IsMatch
== true && Parse
->Package() != Src
)
1094 if (VerTag
.empty() == false)
1096 /* Don't want to fall through because we are doing exact version
1098 if (Cache
.VS().CmpVersion(VerTag
,Ver
) != 0)
1102 Offset
= Parse
->Offset();
1106 // Newer version or an exact match
1107 if (Last
== 0 || Cache
.VS().CmpVersion(Version
,Ver
) < 0 ||
1108 (Parse
->Package() == Src
&& IsMatch
== false))
1110 IsMatch
= Parse
->Package() == Src
;
1112 Offset
= Parse
->Offset();
1120 if (Last
->Jump(Offset
) == false)
1127 // DoUpdate - Update the package lists /*{{{*/
1128 // ---------------------------------------------------------------------
1130 bool DoUpdate(CommandLine
&CmdL
)
1132 if (CmdL
.FileSize() != 1)
1133 return _error
->Error(_("The update command takes no arguments"));
1135 // Get the source list
1137 if (List
.ReadMainList() == false)
1140 // Lock the list directory
1142 if (_config
->FindB("Debug::NoLocking",false) == false)
1144 Lock
.Fd(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
1145 if (_error
->PendingError() == true)
1146 return _error
->Error(_("Unable to lock the list directory"));
1149 // Create the download object
1150 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1151 pkgAcquire
Fetcher(&Stat
);
1153 // Populate it with the source selection
1154 if (List
.GetIndexes(&Fetcher
) == false)
1158 if (Fetcher
.Run() == pkgAcquire::Failed
)
1161 bool Failed
= false;
1162 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1164 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
1169 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1170 (*I
)->ErrorText
.c_str());
1174 // Clean out any old list files
1175 if (_config
->FindB("APT::Get::List-Cleanup",true) == true)
1177 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
1178 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
1182 // Prepare the cache.
1184 if (Cache
.Open() == false)
1188 return _error
->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
1193 // DoUpgrade - Upgrade all packages /*{{{*/
1194 // ---------------------------------------------------------------------
1195 /* Upgrade all packages without installing new packages or erasing old
1197 bool DoUpgrade(CommandLine
&CmdL
)
1200 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1204 if (pkgAllUpgrade(Cache
) == false)
1206 ShowBroken(c1out
,Cache
,false);
1207 return _error
->Error(_("Internal Error, AllUpgrade broke stuff"));
1210 return InstallPackages(Cache
,true);
1213 // DoInstall - Install packages from the command line /*{{{*/
1214 // ---------------------------------------------------------------------
1215 /* Install named packages */
1216 bool DoInstall(CommandLine
&CmdL
)
1219 if (Cache
.OpenForInstall() == false ||
1220 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
1223 // Enter the special broken fixing mode if the user specified arguments
1224 bool BrokenFix
= false;
1225 if (Cache
->BrokenCount() != 0)
1228 unsigned int ExpectedInst
= 0;
1229 unsigned int Packages
= 0;
1230 pkgProblemResolver
Fix(Cache
);
1232 bool DefRemove
= false;
1233 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
1236 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1238 // Duplicate the string
1239 unsigned int Length
= strlen(*I
);
1241 if (Length
>= sizeof(S
))
1245 // See if we are removing and special indicators..
1246 bool Remove
= DefRemove
;
1248 bool VerIsRel
= false;
1249 while (Cache
->FindPkg(S
).end() == true)
1251 // Handle an optional end tag indicating what to do
1252 if (S
[Length
- 1] == '-')
1259 if (S
[Length
- 1] == '+')
1266 char *Slash
= strchr(S
,'=');
1274 Slash
= strchr(S
,'/');
1285 // Locate the package
1286 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
1288 if (Pkg
.end() == true)
1290 // Check if the name is a regex
1292 for (I
= S
; *I
!= 0; I
++)
1293 if (*I
== '.' || *I
== '?' || *I
== '*' || *I
== '|')
1296 return _error
->Error(_("Couldn't find package %s"),S
);
1298 // Regexs must always be confirmed
1299 ExpectedInst
+= 1000;
1301 // Compile the regex pattern
1304 if ((Res
= regcomp(&Pattern
,S
,REG_EXTENDED
| REG_ICASE
|
1308 regerror(Res
,&Pattern
,Error
,sizeof(Error
));
1309 return _error
->Error(_("Regex compilation error - %s"),Error
);
1312 // Run over the matches
1314 for (Pkg
= Cache
->PkgBegin(); Pkg
.end() == false; Pkg
++)
1316 if (regexec(&Pattern
,Pkg
.Name(),0,0,0) != 0)
1320 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1323 Hit
|= TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,
1324 ExpectedInst
,false);
1329 return _error
->Error(_("Couldn't find package %s"),S
);
1334 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1336 if (TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,ExpectedInst
) == false)
1341 /* If we are in the Broken fixing mode we do not attempt to fix the
1342 problems. This is if the user invoked install without -f and gave
1344 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1346 c1out
<< _("You might want to run `apt-get -f install' to correct these:") << endl
;
1347 ShowBroken(c1out
,Cache
,false);
1349 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1352 // Call the scored problem resolver
1353 Fix
.InstallProtect();
1354 if (Fix
.Resolve(true) == false)
1357 // Now we check the state of the packages,
1358 if (Cache
->BrokenCount() != 0)
1361 _("Some packages could not be installed. This may mean that you have\n"
1362 "requested an impossible situation or if you are using the unstable\n"
1363 "distribution that some required packages have not yet been created\n"
1364 "or been moved out of Incoming.") << endl
;
1369 _("Since you only requested a single operation it is extremely likely that\n"
1370 "the package is simply not installable and a bug report against\n"
1371 "that package should be filed.") << endl
;
1374 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1376 ShowBroken(c1out
,Cache
,false);
1377 return _error
->Error(_("Sorry, broken packages"));
1380 /* Print out a list of packages that are going to be installed extra
1381 to what the user asked */
1382 if (Cache
->InstCount() != ExpectedInst
)
1385 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1387 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1388 if ((*Cache
)[I
].Install() == false)
1392 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1393 if (strcmp(*J
,I
.Name()) == 0)
1397 List
+= string(I
.Name()) + " ";
1400 ShowList(c1out
,_("The following extra packages will be installed:"),List
);
1403 // See if we need to prompt
1404 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
1405 return InstallPackages(Cache
,false,false);
1407 return InstallPackages(Cache
,false);
1410 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1411 // ---------------------------------------------------------------------
1412 /* Intelligent upgrader that will install and remove packages at will */
1413 bool DoDistUpgrade(CommandLine
&CmdL
)
1416 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1419 c0out
<< _("Calculating Upgrade... ") << flush
;
1420 if (pkgDistUpgrade(*Cache
) == false)
1422 c0out
<< _("Failed") << endl
;
1423 ShowBroken(c1out
,Cache
,false);
1427 c0out
<< _("Done") << endl
;
1429 return InstallPackages(Cache
,true);
1432 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1433 // ---------------------------------------------------------------------
1434 /* Follows dselect's selections */
1435 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1438 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1441 // Install everything with the install flag set
1442 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1443 for (;I
.end() != true; I
++)
1445 /* Install the package only if it is a new install, the autoupgrader
1446 will deal with the rest */
1447 if (I
->SelectedState
== pkgCache::State::Install
)
1448 Cache
->MarkInstall(I
,false);
1451 /* Now install their deps too, if we do this above then order of
1452 the status file is significant for | groups */
1453 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1455 /* Install the package only if it is a new install, the autoupgrader
1456 will deal with the rest */
1457 if (I
->SelectedState
== pkgCache::State::Install
)
1458 Cache
->MarkInstall(I
,true);
1461 // Apply erasures now, they override everything else.
1462 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1465 if (I
->SelectedState
== pkgCache::State::DeInstall
||
1466 I
->SelectedState
== pkgCache::State::Purge
)
1467 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
1470 /* Resolve any problems that dselect created, allupgrade cannot handle
1471 such things. We do so quite agressively too.. */
1472 if (Cache
->BrokenCount() != 0)
1474 pkgProblemResolver
Fix(Cache
);
1476 // Hold back held packages.
1477 if (_config
->FindB("APT::Ignore-Hold",false) == false)
1479 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
1481 if (I
->SelectedState
== pkgCache::State::Hold
)
1489 if (Fix
.Resolve() == false)
1491 ShowBroken(c1out
,Cache
,false);
1492 return _error
->Error("Internal Error, problem resolver broke stuff");
1496 // Now upgrade everything
1497 if (pkgAllUpgrade(Cache
) == false)
1499 ShowBroken(c1out
,Cache
,false);
1500 return _error
->Error("Internal Error, problem resolver broke stuff");
1503 return InstallPackages(Cache
,false);
1506 // DoClean - Remove download archives /*{{{*/
1507 // ---------------------------------------------------------------------
1509 bool DoClean(CommandLine
&CmdL
)
1511 if (_config
->FindB("APT::Get::Simulate") == true)
1513 cout
<< "Del " << _config
->FindDir("Dir::Cache::archives") << "* " <<
1514 _config
->FindDir("Dir::Cache::archives") << "partial/*" << endl
;
1518 // Lock the archive directory
1520 if (_config
->FindB("Debug::NoLocking",false) == false)
1522 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1523 if (_error
->PendingError() == true)
1524 return _error
->Error(_("Unable to lock the download directory"));
1528 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
1529 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
1533 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
1534 // ---------------------------------------------------------------------
1535 /* This is similar to clean but it only purges things that cannot be
1536 downloaded, that is old versions of cached packages. */
1537 class LogCleaner
: public pkgArchiveCleaner
1540 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1542 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
1544 if (_config
->FindB("APT::Get::Simulate") == false)
1549 bool DoAutoClean(CommandLine
&CmdL
)
1551 // Lock the archive directory
1553 if (_config
->FindB("Debug::NoLocking",false) == false)
1555 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1556 if (_error
->PendingError() == true)
1557 return _error
->Error(_("Unable to lock the download directory"));
1561 if (Cache
.Open() == false)
1566 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1567 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1570 // DoCheck - Perform the check operation /*{{{*/
1571 // ---------------------------------------------------------------------
1572 /* Opening automatically checks the system, this command is mostly used
1574 bool DoCheck(CommandLine
&CmdL
)
1583 // DoSource - Fetch a source archive /*{{{*/
1584 // ---------------------------------------------------------------------
1585 /* Fetch souce packages */
1593 bool DoSource(CommandLine
&CmdL
)
1596 if (Cache
.Open(false) == false)
1599 if (CmdL
.FileSize() <= 1)
1600 return _error
->Error(_("Must specify at least one package to fetch source for"));
1602 // Read the source list
1604 if (List
.ReadMainList() == false)
1605 return _error
->Error(_("The list of sources could not be read."));
1607 // Create the text record parsers
1608 pkgRecords
Recs(Cache
);
1609 pkgSrcRecords
SrcRecs(List
);
1610 if (_error
->PendingError() == true)
1613 // Create the download object
1614 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1615 pkgAcquire
Fetcher(&Stat
);
1617 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
1619 // Load the requestd sources into the fetcher
1621 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1624 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1627 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1630 vector
<pkgSrcRecords::File
> Lst
;
1631 if (Last
->Files(Lst
) == false)
1634 // Load them into the fetcher
1635 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
1636 I
!= Lst
.end(); I
++)
1638 // Try to guess what sort of file it is we are getting.
1639 if (I
->Type
== "dsc")
1641 Dsc
[J
].Package
= Last
->Package();
1642 Dsc
[J
].Version
= Last
->Version();
1643 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
1646 // Diff only mode only fetches .diff files
1647 if (_config
->FindB("APT::Get::Diff-Only",false) == true &&
1651 // Tar only mode only fetches .tar files
1652 if (_config
->FindB("APT::Get::Tar-Only",false) == true &&
1656 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
1658 Last
->Index().SourceInfo(*Last
,*I
),Src
);
1662 // Display statistics
1663 double FetchBytes
= Fetcher
.FetchNeeded();
1664 double FetchPBytes
= Fetcher
.PartialPresent();
1665 double DebBytes
= Fetcher
.TotalNeeded();
1667 // Check for enough free space
1669 string OutputDir
= ".";
1670 if (statvfs(OutputDir
.c_str(),&Buf
) != 0)
1671 return _error
->Errno("statvfs","Couldn't determine free space in %s",
1673 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1674 return _error
->Error(_("Sorry, you don't have enough free space in %s"),
1678 if (DebBytes
!= FetchBytes
)
1679 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
1680 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
1682 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
1683 SizeToStr(DebBytes
).c_str());
1685 if (_config
->FindB("APT::Get::Simulate",false) == true)
1687 for (unsigned I
= 0; I
!= J
; I
++)
1688 ioprintf(cout
,_("Fetch Source %s\n"),Dsc
[I
].Package
.c_str());
1692 // Just print out the uris an exit if the --print-uris flag was used
1693 if (_config
->FindB("APT::Get::Print-URIs") == true)
1695 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1696 for (; I
!= Fetcher
.UriEnd(); I
++)
1697 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1698 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1703 if (Fetcher
.Run() == pkgAcquire::Failed
)
1706 // Print error messages
1707 bool Failed
= false;
1708 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1710 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1711 (*I
)->Complete
== true)
1714 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1715 (*I
)->ErrorText
.c_str());
1719 return _error
->Error(_("Failed to fetch some archives."));
1721 if (_config
->FindB("APT::Get::Download-only",false) == true)
1723 c1out
<< _("Download complete and in download only mode") << endl
;
1727 // Unpack the sources
1728 pid_t Process
= ExecFork();
1732 for (unsigned I
= 0; I
!= J
; I
++)
1734 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
1736 // Diff only mode only fetches .diff files
1737 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
1738 _config
->FindB("APT::Get::Tar-Only",false) == true ||
1739 Dsc
[I
].Dsc
.empty() == true)
1742 // See if the package is already unpacked
1744 if (stat(Dir
.c_str(),&Stat
) == 0 &&
1745 S_ISDIR(Stat
.st_mode
) != 0)
1747 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
1754 snprintf(S
,sizeof(S
),"%s -x %s",
1755 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
1756 Dsc
[I
].Dsc
.c_str());
1759 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
1764 // Try to compile it with dpkg-buildpackage
1765 if (_config
->FindB("APT::Get::Compile",false) == true)
1767 // Call dpkg-buildpackage
1769 snprintf(S
,sizeof(S
),"cd %s && %s %s",
1771 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
1772 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
1776 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
1785 // Wait for the subprocess
1787 while (waitpid(Process
,&Status
,0) != Process
)
1791 return _error
->Errno("waitpid","Couldn't wait for subprocess");
1794 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
1795 return _error
->Error(_("Child process failed"));
1800 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
1801 // ---------------------------------------------------------------------
1802 /* This function will look at the build depends list of the given source
1803 package and install the necessary packages to make it true, or fail. */
1804 bool DoBuildDep(CommandLine
&CmdL
)
1807 if (Cache
.Open(true) == false)
1810 if (CmdL
.FileSize() <= 1)
1811 return _error
->Error(_("Must specify at least one package to check builddeps for"));
1813 // Read the source list
1815 if (List
.ReadMainList() == false)
1816 return _error
->Error(_("The list of sources could not be read."));
1818 // Create the text record parsers
1819 pkgRecords
Recs(Cache
);
1820 pkgSrcRecords
SrcRecs(List
);
1821 if (_error
->PendingError() == true)
1824 // Create the download object
1825 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1826 pkgAcquire
Fetcher(&Stat
);
1829 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1832 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1834 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1836 // Process the build-dependencies
1837 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
1838 if (Last
->BuildDepends(BuildDeps
) == false)
1839 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
1841 if (BuildDeps
.size() == 0)
1843 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
1847 // Install the requested packages
1848 unsigned int ExpectedInst
= 0;
1849 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
1850 pkgProblemResolver
Fix(Cache
);
1851 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); D
++)
1853 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
1854 if (Pkg
.end() == true)
1855 return _error
->Error(_("%s dependency on %s cannot be satisfied because the package %s cannot be found"),
1856 Last
->BuildDepType((*D
).Type
),Src
.c_str(),(*D
).Package
.c_str());
1857 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1859 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1860 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1863 * conflict; need to remove if we have an installed version
1864 * that satisfies the version criterial
1866 if (IV
.end() == false &&
1867 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1868 TryToInstall(Pkg
,Cache
,Fix
,true,false,ExpectedInst
);
1873 * If this is a virtual package, we need to check the list of
1874 * packages that provide it and see if any of those are
1877 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
1878 for (; Prv
.end() != true; Prv
++)
1879 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
1882 if (Prv
.end() == true)
1885 * depends; need to install or upgrade if we don't have the
1886 * package installed or if the version does not satisfy the
1887 * build dep. This is complicated by the fact that if we
1888 * depend on a version lower than what we already have
1889 * installed it is not clear what should be done; in practice
1890 * this case should be rare though and right now nothing
1891 * is done about it :-(
1893 if (IV
.end() == true ||
1894 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == false)
1895 TryToInstall(Pkg
,Cache
,Fix
,false,false,ExpectedInst
);
1900 Fix
.InstallProtect();
1901 if (Fix
.Resolve(true) == false)
1904 // Now we check the state of the packages,
1905 if (Cache
->BrokenCount() != 0)
1906 return _error
->Error(_("Some broken packages were found while trying to process build-dependencies.\n"
1907 "You might want to run `apt-get -f install' to correct these."));
1910 if (InstallPackages(Cache
, false, true) == false)
1911 return _error
->Error(_("Failed to process build dependencies"));
1916 // DoMoo - Never Ask, Never Tell /*{{{*/
1917 // ---------------------------------------------------------------------
1919 bool DoMoo(CommandLine
&CmdL
)
1928 "....\"Have you mooed today?\"...\n";
1933 // ShowHelp - Show a help screen /*{{{*/
1934 // ---------------------------------------------------------------------
1936 bool ShowHelp(CommandLine
&CmdL
)
1938 ioprintf(cout
,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE
,VERSION
,
1939 COMMON_OS
,COMMON_CPU
,__DATE__
,__TIME__
);
1941 if (_config
->FindB("version") == true)
1943 cout
<< _("Supported Modules:") << endl
;
1945 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
1947 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
1948 if (_system
!= 0 && _system
->VS
== VS
)
1952 cout
<< "Ver: " << VS
->Label
<< endl
;
1954 /* Print out all the packaging systems that will work with
1956 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
1958 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
1963 if (Sys
->VS
->TestCompatibility(*VS
) == true)
1964 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
1968 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
1970 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
1971 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
1974 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
1976 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
1977 cout
<< " Idx: " << Type
->Label
<< endl
;
1984 _("Usage: apt-get [options] command\n"
1985 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
1986 " apt-get [options] source pkg1 [pkg2 ...]\n"
1988 "apt-get is a simple command line interface for downloading and\n"
1989 "installing packages. The most frequently used commands are update\n"
1993 " update - Retrieve new lists of packages\n"
1994 " upgrade - Perform an upgrade\n"
1995 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
1996 " remove - Remove packages\n"
1997 " source - Download source archives\n"
1998 " build-dep - Configure build-dependencies for source packages\n"
1999 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
2000 " dselect-upgrade - Follow dselect selections\n"
2001 " clean - Erase downloaded archive files\n"
2002 " autoclean - Erase old downloaded archive files\n"
2003 " check - Verify that there are no broken dependencies\n"
2006 " -h This help text.\n"
2007 " -q Loggable output - no progress indicator\n"
2008 " -qq No output except for errors\n"
2009 " -d Download only - do NOT install or unpack archives\n"
2010 " -s No-act. Perform ordering simulation\n"
2011 " -y Assume Yes to all queries and do not prompt\n"
2012 " -f Attempt to continue if the integrity check fails\n"
2013 " -m Attempt to continue if archives are unlocatable\n"
2014 " -u Show a list of upgraded packages as well\n"
2015 " -b Build the source package after fetching it\n"
2016 " -c=? Read this configuration file\n"
2017 " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n"
2018 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
2019 "pages for more information and options.\n"
2020 " This APT has Super Cow Powers.\n");
2024 // GetInitialize - Initialize things for apt-get /*{{{*/
2025 // ---------------------------------------------------------------------
2027 void GetInitialize()
2029 _config
->Set("quiet",0);
2030 _config
->Set("help",false);
2031 _config
->Set("APT::Get::Download-Only",false);
2032 _config
->Set("APT::Get::Simulate",false);
2033 _config
->Set("APT::Get::Assume-Yes",false);
2034 _config
->Set("APT::Get::Fix-Broken",false);
2035 _config
->Set("APT::Get::Force-Yes",false);
2036 _config
->Set("APT::Get::APT::Get::No-List-Cleanup",true);
2039 // SigWinch - Window size change signal handler /*{{{*/
2040 // ---------------------------------------------------------------------
2044 // Riped from GNU ls
2048 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
2049 ScreenWidth
= ws
.ws_col
- 1;
2054 int main(int argc
,const char *argv
[])
2056 CommandLine::Args Args
[] = {
2057 {'h',"help","help",0},
2058 {'v',"version","version",0},
2059 {'q',"quiet","quiet",CommandLine::IntLevel
},
2060 {'q',"silent","quiet",CommandLine::IntLevel
},
2061 {'d',"download-only","APT::Get::Download-Only",0},
2062 {'b',"compile","APT::Get::Compile",0},
2063 {'b',"build","APT::Get::Compile",0},
2064 {'s',"simulate","APT::Get::Simulate",0},
2065 {'s',"just-print","APT::Get::Simulate",0},
2066 {'s',"recon","APT::Get::Simulate",0},
2067 {'s',"dry-run","APT::Get::Simulate",0},
2068 {'s',"no-act","APT::Get::Simulate",0},
2069 {'y',"yes","APT::Get::Assume-Yes",0},
2070 {'y',"assume-yes","APT::Get::Assume-Yes",0},
2071 {'f',"fix-broken","APT::Get::Fix-Broken",0},
2072 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
2073 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
2074 {'t',"target-release","APT::Default-Release",CommandLine::HasArg
},
2075 {'t',"default-release","APT::Default-Release",CommandLine::HasArg
},
2076 {0,"download","APT::Get::Download",0},
2077 {0,"fix-missing","APT::Get::Fix-Missing",0},
2078 {0,"ignore-hold","APT::Ignore-Hold",0},
2079 {0,"upgrade","APT::Get::upgrade",0},
2080 {0,"force-yes","APT::Get::force-yes",0},
2081 {0,"print-uris","APT::Get::Print-URIs",0},
2082 {0,"diff-only","APT::Get::Diff-Only",0},
2083 {0,"tar-only","APT::Get::tar-Only",0},
2084 {0,"purge","APT::Get::Purge",0},
2085 {0,"list-cleanup","APT::Get::List-Cleanup",0},
2086 {0,"reinstall","APT::Get::ReInstall",0},
2087 {0,"trivial-only","APT::Get::Trivial-Only",0},
2088 {0,"remove","APT::Get::Remove",0},
2089 {0,"only-source","APT::Get::Only-Source",0},
2090 {'c',"config-file",0,CommandLine::ConfigFile
},
2091 {'o',"option",0,CommandLine::ArbItem
},
2093 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
2094 {"upgrade",&DoUpgrade
},
2095 {"install",&DoInstall
},
2096 {"remove",&DoInstall
},
2097 {"dist-upgrade",&DoDistUpgrade
},
2098 {"dselect-upgrade",&DoDSelectUpgrade
},
2099 {"build-dep",&DoBuildDep
},
2101 {"autoclean",&DoAutoClean
},
2103 {"source",&DoSource
},
2108 // Parse the command line and initialize the package library
2109 CommandLine
CmdL(Args
,_config
);
2110 if (pkgInitConfig(*_config
) == false ||
2111 CmdL
.Parse(argc
,argv
) == false ||
2112 pkgInitSystem(*_config
,_system
) == false)
2114 if (_config
->FindB("version") == true)
2117 _error
->DumpErrors();
2121 // See if the help should be shown
2122 if (_config
->FindB("help") == true ||
2123 _config
->FindB("version") == true ||
2124 CmdL
.FileSize() == 0)
2130 // Deal with stdout not being a tty
2131 if (ttyname(STDOUT_FILENO
) == 0 && _config
->FindI("quiet",0) < 1)
2132 _config
->Set("quiet","1");
2134 // Setup the output streams
2135 c0out
.rdbuf(cout
.rdbuf());
2136 c1out
.rdbuf(cout
.rdbuf());
2137 c2out
.rdbuf(cout
.rdbuf());
2138 if (_config
->FindI("quiet",0) > 0)
2139 c0out
.rdbuf(devnull
.rdbuf());
2140 if (_config
->FindI("quiet",0) > 1)
2141 c1out
.rdbuf(devnull
.rdbuf());
2143 // Setup the signals
2144 signal(SIGPIPE
,SIG_IGN
);
2145 signal(SIGWINCH
,SigWinch
);
2148 // Match the operation
2149 CmdL
.DispatchArg(Cmds
);
2151 // Print any errors or warnings found during parsing
2152 if (_error
->empty() == false)
2154 bool Errors
= _error
->PendingError();
2155 _error
->DumpErrors();
2156 return Errors
== true?100:0;