]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
76945b805c32f9e4f9e8365d816f44e56da1f72f
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.111 2001/11/04 17:09:18 tausq 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
]);
192 if (Cache
[I
].NowBroken() == false)
197 if (Cache
[I
].InstBroken() == false)
201 // Print out each package and the failed dependencies
202 out
<<" " << I
.Name() << ":";
203 unsigned Indent
= strlen(I
.Name()) + 3;
205 pkgCache::VerIterator Ver
;
208 Ver
= I
.CurrentVer();
210 Ver
= Cache
[I
].InstVerIter(Cache
);
212 if (Ver
.end() == true)
218 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false;)
220 // Compute a single dependency element (glob or)
221 pkgCache::DepIterator Start
;
222 pkgCache::DepIterator End
;
225 if (Cache
->IsImportantDep(End
) == false)
230 if ((Cache
[End
] & pkgDepCache::DepGNow
) == pkgDepCache::DepGNow
)
235 if ((Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
243 for (unsigned J
= 0; J
!= Indent
; J
++)
247 if (FirstOr
== false)
249 for (unsigned J
= 0; J
!= strlen(End
.DepType()) + 3; J
++)
253 out
<< ' ' << End
.DepType() << ": ";
256 out
<< Start
.TargetPkg().Name();
258 // Show a quick summary of the version requirements
259 if (Start
.TargetVer() != 0)
260 out
<< " (" << Start
.CompType() << " " << Start
.TargetVer() << ")";
262 /* Show a summary of the target package if possible. In the case
263 of virtual packages we show nothing */
264 pkgCache::PkgIterator Targ
= Start
.TargetPkg();
265 if (Targ
->ProvidesList
== 0)
268 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
270 Ver
= Targ
.CurrentVer();
272 if (Ver
.end() == false)
275 ioprintf(out
,_("but %s is installed"),Ver
.VerStr());
277 ioprintf(out
,_("but %s is to be installed"),Ver
.VerStr());
281 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
283 if (Targ
->ProvidesList
== 0)
284 out
<< _("but it is not installable");
286 out
<< _("but it is a virtual package");
289 out
<< (Now
?_("but it is not installed"):_("but it is not going to be installed"));
305 // ShowNew - Show packages to newly install /*{{{*/
306 // ---------------------------------------------------------------------
308 void ShowNew(ostream
&out
,CacheFile
&Cache
)
310 /* Print out a list of packages that are going to be removed extra
311 to what the user asked */
313 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
315 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
316 if (Cache
[I
].NewInstall() == true)
317 List
+= string(I
.Name()) + " ";
320 ShowList(out
,_("The following NEW packages will be installed:"),List
);
323 // ShowDel - Show packages to delete /*{{{*/
324 // ---------------------------------------------------------------------
326 void ShowDel(ostream
&out
,CacheFile
&Cache
)
328 /* Print out a list of packages that are going to be removed extra
329 to what the user asked */
331 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
333 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
334 if (Cache
[I
].Delete() == true)
336 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
337 List
+= string(I
.Name()) + "* ";
339 List
+= string(I
.Name()) + " ";
343 ShowList(out
,_("The following packages will be REMOVED:"),List
);
346 // ShowKept - Show kept packages /*{{{*/
347 // ---------------------------------------------------------------------
349 void ShowKept(ostream
&out
,CacheFile
&Cache
)
352 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
354 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
357 if (Cache
[I
].Upgrade() == true || Cache
[I
].Upgradable() == false ||
358 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
361 List
+= string(I
.Name()) + " ";
363 ShowList(out
,_("The following packages have been kept back"),List
);
366 // ShowUpgraded - Show upgraded packages /*{{{*/
367 // ---------------------------------------------------------------------
369 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
372 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
374 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
377 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
380 List
+= string(I
.Name()) + " ";
382 ShowList(out
,_("The following packages will be upgraded"),List
);
385 // ShowDowngraded - Show downgraded packages /*{{{*/
386 // ---------------------------------------------------------------------
388 bool ShowDowngraded(ostream
&out
,CacheFile
&Cache
)
391 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
393 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
396 if (Cache
[I
].Downgrade() == false || Cache
[I
].NewInstall() == true)
399 List
+= string(I
.Name()) + " ";
401 return ShowList(out
,_("The following packages will be DOWNGRADED"),List
);
404 // ShowHold - Show held but changed packages /*{{{*/
405 // ---------------------------------------------------------------------
407 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
410 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
412 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
413 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
414 I
->SelectedState
== pkgCache::State::Hold
)
415 List
+= string(I
.Name()) + " ";
418 return ShowList(out
,_("The following held packages will be changed:"),List
);
421 // ShowEssential - Show an essential package warning /*{{{*/
422 // ---------------------------------------------------------------------
423 /* This prints out a warning message that is not to be ignored. It shows
424 all essential packages and their dependents that are to be removed.
425 It is insanely risky to remove the dependents of an essential package! */
426 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
429 bool *Added
= new bool[Cache
->Head().PackageCount
];
430 for (unsigned int I
= 0; I
!= Cache
->Head().PackageCount
; I
++)
433 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
435 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
436 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
&&
437 (I
->Flags
& pkgCache::Flag::Important
) != pkgCache::Flag::Important
)
440 // The essential package is being removed
441 if (Cache
[I
].Delete() == true)
443 if (Added
[I
->ID
] == false)
446 List
+= string(I
.Name()) + " ";
450 if (I
->CurrentVer
== 0)
453 // Print out any essential package depenendents that are to be removed
454 for (pkgCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
456 // Skip everything but depends
457 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
458 D
->Type
!= pkgCache::Dep::Depends
)
461 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
462 if (Cache
[P
].Delete() == true)
464 if (Added
[P
->ID
] == true)
469 snprintf(S
,sizeof(S
),_("%s (due to %s) "),P
.Name(),I
.Name());
476 return ShowList(out
,_("WARNING: The following essential packages will be removed\n"
477 "This should NOT be done unless you know exactly what you are doing!"),List
);
480 // Stats - Show some statistics /*{{{*/
481 // ---------------------------------------------------------------------
483 void Stats(ostream
&out
,pkgDepCache
&Dep
)
485 unsigned long Upgrade
= 0;
486 unsigned long Downgrade
= 0;
487 unsigned long Install
= 0;
488 unsigned long ReInstall
= 0;
489 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
491 if (Dep
[I
].NewInstall() == true)
495 if (Dep
[I
].Upgrade() == true)
498 if (Dep
[I
].Downgrade() == true)
502 if (Dep
[I
].Delete() == false && (Dep
[I
].iFlags
& pkgDepCache::ReInstall
) == pkgDepCache::ReInstall
)
506 ioprintf(out
,_("%lu packages upgraded, %lu newly installed, "),
510 ioprintf(out
,_("%lu reinstalled, "),ReInstall
);
512 ioprintf(out
,_("%lu downgraded, "),Downgrade
);
514 ioprintf(out
,_("%lu to remove and %lu not upgraded.\n"),
515 Dep
.DelCount(),Dep
.KeepCount());
517 if (Dep
.BadCount() != 0)
518 ioprintf(out
,_("%lu packages not fully installed or removed.\n"),
523 // CacheFile::NameComp - QSort compare by name /*{{{*/
524 // ---------------------------------------------------------------------
526 pkgCache
*CacheFile::SortCache
= 0;
527 int CacheFile::NameComp(const void *a
,const void *b
)
529 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
530 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
532 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
533 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
535 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
538 // CacheFile::Sort - Sort by name /*{{{*/
539 // ---------------------------------------------------------------------
541 void CacheFile::Sort()
544 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
545 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
546 pkgCache::PkgIterator I
= Cache
->PkgBegin();
547 for (;I
.end() != true; I
++)
551 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
554 // CacheFile::CheckDeps - Open the cache file /*{{{*/
555 // ---------------------------------------------------------------------
556 /* This routine generates the caches and then opens the dependency cache
557 and verifies that the system is OK. */
558 bool CacheFile::CheckDeps(bool AllowBroken
)
560 if (_error
->PendingError() == true)
563 // Check that the system is OK
564 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
565 return _error
->Error("Internal Error, non-zero counts");
567 // Apply corrections for half-installed packages
568 if (pkgApplyStatus(*DCache
) == false)
572 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
575 // Attempt to fix broken things
576 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
578 c1out
<< _("Correcting dependencies...") << flush
;
579 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
581 c1out
<< _(" failed.") << endl
;
582 ShowBroken(c1out
,*this,true);
584 return _error
->Error(_("Unable to correct dependencies"));
586 if (pkgMinimizeUpgrade(*DCache
) == false)
587 return _error
->Error(_("Unable to minimize the upgrade set"));
589 c1out
<< _(" Done") << endl
;
593 c1out
<< _("You might want to run `apt-get -f install' to correct these.") << endl
;
594 ShowBroken(c1out
,*this,true);
596 return _error
->Error(_("Unmet dependencies. Try using -f."));
603 // InstallPackages - Actually download and install the packages /*{{{*/
604 // ---------------------------------------------------------------------
605 /* This displays the informative messages describing what is going to
606 happen and then calls the download routines */
607 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,
610 if (_config
->FindB("APT::Get::Purge",false) == true)
612 pkgCache::PkgIterator I
= Cache
->PkgBegin();
613 for (; I
.end() == false; I
++)
615 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
616 Cache
->MarkDelete(I
,true);
621 bool Essential
= false;
623 // Show all the various warning indicators
624 ShowDel(c1out
,Cache
);
625 ShowNew(c1out
,Cache
);
627 ShowKept(c1out
,Cache
);
628 Fail
|= !ShowHold(c1out
,Cache
);
629 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
630 ShowUpgraded(c1out
,Cache
);
631 Fail
|= !ShowDowngraded(c1out
,Cache
);
632 Essential
= !ShowEssential(c1out
,Cache
);
637 if (Cache
->BrokenCount() != 0)
639 ShowBroken(c1out
,Cache
,false);
640 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
643 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
644 Cache
->BadCount() == 0)
648 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::Remove",true) == false)
649 return _error
->Error(_("Packages need to be removed but Remove is disabled."));
651 // Run the simulator ..
652 if (_config
->FindB("APT::Get::Simulate") == true)
654 pkgSimulate
PM(Cache
);
655 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
656 if (Res
== pkgPackageManager::Failed
)
658 if (Res
!= pkgPackageManager::Completed
)
659 return _error
->Error("Internal Error, Ordering didn't finish");
663 // Create the text record parser
664 pkgRecords
Recs(Cache
);
665 if (_error
->PendingError() == true)
668 // Lock the archive directory
670 if (_config
->FindB("Debug::NoLocking",false) == false &&
671 _config
->FindB("APT::Get::Print-URIs") == false)
673 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
674 if (_error
->PendingError() == true)
675 return _error
->Error(_("Unable to lock the download directory"));
678 // Create the download object
679 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
680 pkgAcquire
Fetcher(&Stat
);
682 // Read the source list
684 if (List
.ReadMainList() == false)
685 return _error
->Error(_("The list of sources could not be read."));
687 // Create the package manager and prepare to download
688 SPtr
<pkgPackageManager
> PM
= _system
->CreatePM(Cache
);
689 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false ||
690 _error
->PendingError() == true)
693 // Display statistics
694 double FetchBytes
= Fetcher
.FetchNeeded();
695 double FetchPBytes
= Fetcher
.PartialPresent();
696 double DebBytes
= Fetcher
.TotalNeeded();
697 if (DebBytes
!= Cache
->DebSize())
699 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
700 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
704 if (DebBytes
!= FetchBytes
)
705 ioprintf(c1out
,_("Need to get %sB/%sB of archives. "),
706 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
708 ioprintf(c1out
,_("Need to get %sB of archives. "),
709 SizeToStr(DebBytes
).c_str());
712 if (Cache
->UsrSize() >= 0)
713 ioprintf(c1out
,_("After unpacking %sB will be used.\n"),
714 SizeToStr(Cache
->UsrSize()).c_str());
716 ioprintf(c1out
,_("After unpacking %sB will be freed.\n"),
717 SizeToStr(-1*Cache
->UsrSize()).c_str());
719 if (_error
->PendingError() == true)
722 /* Check for enough free space, but only if we are actually going to
724 if (_config
->FindB("APT::Get::Print-URIs") == false)
727 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
728 if (statvfs(OutputDir
.c_str(),&Buf
) != 0)
729 return _error
->Errno("statvfs","Couldn't determine free space in %s",
731 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
732 return _error
->Error(_("Sorry, you don't have enough free space in %s to hold all the .debs."),
737 if (_config
->FindI("quiet",0) >= 2 ||
738 _config
->FindB("APT::Get::Assume-Yes",false) == true)
740 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
741 return _error
->Error(_("There are problems and -y was used without --force-yes"));
744 if (Essential
== true && Saftey
== true)
746 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
747 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
749 const char *Prompt
= _("Yes, do as I say!");
751 _("You are about to do something potentially harmful\n"
752 "To continue type in the phrase '%s'\n"
755 if (AnalPrompt(Prompt
) == false)
757 c2out
<< _("Abort.") << endl
;
763 // Prompt to continue
764 if (Ask
== true || Fail
== true)
766 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
767 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
769 if (_config
->FindI("quiet",0) < 2 &&
770 _config
->FindB("APT::Get::Assume-Yes",false) == false)
772 c2out
<< _("Do you want to continue? [Y/n] ") << flush
;
774 if (YnPrompt() == false)
776 c2out
<< _("Abort.") << endl
;
783 // Just print out the uris an exit if the --print-uris flag was used
784 if (_config
->FindB("APT::Get::Print-URIs") == true)
786 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
787 for (; I
!= Fetcher
.UriEnd(); I
++)
788 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
789 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
793 /* Unlock the dpkg lock if we are not going to be doing an install
795 if (_config
->FindB("APT::Get::Download-Only",false) == true)
801 bool Transient
= false;
802 if (_config
->FindB("APT::Get::Download",true) == false)
804 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
806 if ((*I
)->Local
== true)
812 // Close the item and check if it was found in cache
814 if ((*I
)->Complete
== false)
817 // Clear it out of the fetch list
819 I
= Fetcher
.ItemsBegin();
823 if (Fetcher
.Run() == pkgAcquire::Failed
)
828 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
830 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
831 (*I
)->Complete
== true)
834 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
841 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
842 (*I
)->ErrorText
.c_str());
846 /* If we are in no download mode and missing files and there were
847 'failures' then the user must specify -m. Furthermore, there
848 is no such thing as a transient error in no-download mode! */
849 if (Transient
== true &&
850 _config
->FindB("APT::Get::Download",true) == false)
856 if (_config
->FindB("APT::Get::Download-Only",false) == true)
858 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
859 return _error
->Error(_("Some files failed to download"));
860 c1out
<< _("Download complete and in download only mode") << endl
;
864 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
866 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
869 if (Transient
== true && Failed
== true)
870 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
872 // Try to deal with missing package files
873 if (Failed
== true && PM
->FixMissing() == false)
875 cerr
<< _("Unable to correct missing packages.") << endl
;
876 return _error
->Error(_("Aborting Install."));
880 pkgPackageManager::OrderResult Res
= PM
->DoInstall();
881 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
883 if (Res
== pkgPackageManager::Completed
)
886 // Reload the fetcher object and loop again for media swapping
888 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false)
895 // TryToInstall - Try to install a single package /*{{{*/
896 // ---------------------------------------------------------------------
897 /* This used to be inlined in DoInstall, but with the advent of regex package
898 name matching it was split out.. */
899 bool TryToInstall(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
900 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
901 unsigned int &ExpectedInst
,bool AllowFail
= true)
903 /* This is a pure virtual package and there is a single available
905 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0 &&
906 Pkg
.ProvidesList()->NextProvides
== 0)
908 pkgCache::PkgIterator Tmp
= Pkg
.ProvidesList().OwnerPkg();
909 ioprintf(c1out
,_("Note, selecting %s instead of %s\n"),
910 Tmp
.Name(),Pkg
.Name());
914 // Handle the no-upgrade case
915 if (_config
->FindB("APT::Get::upgrade",true) == false &&
916 Pkg
->CurrentVer
!= 0)
918 if (AllowFail
== true)
919 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
924 // Check if there is something at all to install
925 pkgDepCache::StateCache
&State
= Cache
[Pkg
];
926 if (Remove
== true && Pkg
->CurrentVer
== 0)
928 /* We want to continue searching for regex hits, so we return false here
929 otherwise this is not really an error. */
930 if (AllowFail
== false)
932 ioprintf(c1out
,_("Package %s is not installed, so not removed\n"),Pkg
.Name());
936 if (State
.CandidateVer
== 0 && Remove
== false)
938 if (AllowFail
== false)
941 if (Pkg
->ProvidesList
!= 0)
943 ioprintf(c1out
,_("Package %s is a virtual package provided by:\n"),
946 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
947 for (; I
.end() == false; I
++)
949 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
951 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer())
953 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
954 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
955 _(" [Installed]") << endl
;
957 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
960 c1out
<< _("You should explicitly select one to install.") << endl
;
965 _("Package %s has no available version, but exists in the database.\n"
966 "This typically means that the package was mentioned in a dependency and\n"
967 "never uploaded, has been obsoleted or is not available with the contents\n"
968 "of sources.list\n"),Pkg
.Name());
971 SPtrArray
<bool> Seen
= new bool[Cache
.Head().PackageCount
];
972 memset(Seen
,0,Cache
.Head().PackageCount
*sizeof(*Seen
));
973 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
974 for (; Dep
.end() == false; Dep
++)
976 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
978 if (Seen
[Dep
.ParentPkg()->ID
] == true)
980 Seen
[Dep
.ParentPkg()->ID
] = true;
981 List
+= string(Dep
.ParentPkg().Name()) + " ";
983 ShowList(c1out
,_("However the following packages replace it:"),List
);
986 _error
->Error(_("Package %s has no installation candidate"),Pkg
.Name());
995 Cache
.MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
1000 Cache
.MarkInstall(Pkg
,false);
1001 if (State
.Install() == false)
1003 if (_config
->FindB("APT::Get::ReInstall",false) == true)
1005 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
1006 ioprintf(c1out
,_("Sorry, re-installation of %s is not possible, it cannot be downloaded.\n"),
1009 Cache
.SetReInstall(Pkg
,true);
1013 if (AllowFail
== true)
1014 ioprintf(c1out
,_("Sorry, %s is already the newest version.\n"),
1021 // Install it with autoinstalling enabled.
1022 if (State
.InstBroken() == true && BrokenFix
== false)
1023 Cache
.MarkInstall(Pkg
,true);
1027 // TryToChangeVer - Try to change a candidate version /*{{{*/
1028 // ---------------------------------------------------------------------
1030 bool TryToChangeVer(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
1031 const char *VerTag
,bool IsRel
)
1033 pkgVersionMatch
Match(VerTag
,(IsRel
== true?pkgVersionMatch::Release
:pkgVersionMatch::Version
));
1035 pkgCache::VerIterator Ver
= Match
.Find(Pkg
);
1037 if (Ver
.end() == true)
1040 return _error
->Error(_("Release '%s' for '%s' was not found"),
1042 return _error
->Error(_("Version '%s' for '%s' was not found"),
1046 if (strcmp(VerTag
,Ver
.VerStr()) != 0)
1048 ioprintf(c1out
,_("Selected version %s (%s) for %s\n"),
1049 Ver
.VerStr(),Ver
.RelStr().c_str(),Pkg
.Name());
1052 Cache
.SetCandidateVersion(Ver
);
1056 // FindSrc - Find a source record /*{{{*/
1057 // ---------------------------------------------------------------------
1059 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
1060 pkgSrcRecords
&SrcRecs
,string
&Src
,
1063 // We want to pull the version off the package specification..
1065 string TmpSrc
= Name
;
1066 string::size_type Slash
= TmpSrc
.rfind('=');
1067 if (Slash
!= string::npos
)
1069 VerTag
= string(TmpSrc
.begin() + Slash
+ 1,TmpSrc
.end());
1070 TmpSrc
= string(TmpSrc
.begin(),TmpSrc
.begin() + Slash
);
1073 /* Lookup the version of the package we would install if we were to
1074 install a version and determine the source package name, then look
1075 in the archive for a source package of the same name. In theory
1076 we could stash the version string as well and match that too but
1077 today there aren't multi source versions in the archive. */
1078 if (_config
->FindB("APT::Get::Only-Source") == false &&
1079 VerTag
.empty() == true)
1081 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(TmpSrc
);
1082 if (Pkg
.end() == false)
1084 pkgCache::VerIterator Ver
= Cache
.GetCandidateVer(Pkg
);
1085 if (Ver
.end() == false)
1087 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1088 Src
= Parse
.SourcePkg();
1093 // No source package name..
1094 if (Src
.empty() == true)
1098 pkgSrcRecords::Parser
*Last
= 0;
1099 unsigned long Offset
= 0;
1101 bool IsMatch
= false;
1103 // If we are matching by version then we need exact matches to be happy
1104 if (VerTag
.empty() == false)
1107 /* Iterate over all of the hits, which includes the resulting
1108 binary packages in the search */
1109 pkgSrcRecords::Parser
*Parse
;
1111 while ((Parse
= SrcRecs
.Find(Src
.c_str(),false)) != 0)
1113 string Ver
= Parse
->Version();
1115 // Skip name mismatches
1116 if (IsMatch
== true && Parse
->Package() != Src
)
1119 if (VerTag
.empty() == false)
1121 /* Don't want to fall through because we are doing exact version
1123 if (Cache
.VS().CmpVersion(VerTag
,Ver
) != 0)
1127 Offset
= Parse
->Offset();
1131 // Newer version or an exact match
1132 if (Last
== 0 || Cache
.VS().CmpVersion(Version
,Ver
) < 0 ||
1133 (Parse
->Package() == Src
&& IsMatch
== false))
1135 IsMatch
= Parse
->Package() == Src
;
1137 Offset
= Parse
->Offset();
1145 if (Last
->Jump(Offset
) == false)
1152 // DoUpdate - Update the package lists /*{{{*/
1153 // ---------------------------------------------------------------------
1155 bool DoUpdate(CommandLine
&CmdL
)
1157 if (CmdL
.FileSize() != 1)
1158 return _error
->Error(_("The update command takes no arguments"));
1160 // Get the source list
1162 if (List
.ReadMainList() == false)
1165 // Lock the list directory
1167 if (_config
->FindB("Debug::NoLocking",false) == false)
1169 Lock
.Fd(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
1170 if (_error
->PendingError() == true)
1171 return _error
->Error(_("Unable to lock the list directory"));
1174 // Create the download object
1175 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1176 pkgAcquire
Fetcher(&Stat
);
1178 // Populate it with the source selection
1179 if (List
.GetIndexes(&Fetcher
) == false)
1183 if (Fetcher
.Run() == pkgAcquire::Failed
)
1186 bool Failed
= false;
1187 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1189 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
1194 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1195 (*I
)->ErrorText
.c_str());
1199 // Clean out any old list files
1200 if (_config
->FindB("APT::Get::List-Cleanup",true) == true)
1202 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
1203 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
1207 // Prepare the cache.
1209 if (Cache
.Open() == false)
1213 return _error
->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
1218 // DoUpgrade - Upgrade all packages /*{{{*/
1219 // ---------------------------------------------------------------------
1220 /* Upgrade all packages without installing new packages or erasing old
1222 bool DoUpgrade(CommandLine
&CmdL
)
1225 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1229 if (pkgAllUpgrade(Cache
) == false)
1231 ShowBroken(c1out
,Cache
,false);
1232 return _error
->Error(_("Internal Error, AllUpgrade broke stuff"));
1235 return InstallPackages(Cache
,true);
1238 // DoInstall - Install packages from the command line /*{{{*/
1239 // ---------------------------------------------------------------------
1240 /* Install named packages */
1241 bool DoInstall(CommandLine
&CmdL
)
1244 if (Cache
.OpenForInstall() == false ||
1245 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
1248 // Enter the special broken fixing mode if the user specified arguments
1249 bool BrokenFix
= false;
1250 if (Cache
->BrokenCount() != 0)
1253 unsigned int ExpectedInst
= 0;
1254 unsigned int Packages
= 0;
1255 pkgProblemResolver
Fix(Cache
);
1257 bool DefRemove
= false;
1258 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
1261 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1263 // Duplicate the string
1264 unsigned int Length
= strlen(*I
);
1266 if (Length
>= sizeof(S
))
1270 // See if we are removing and special indicators..
1271 bool Remove
= DefRemove
;
1273 bool VerIsRel
= false;
1274 while (Cache
->FindPkg(S
).end() == true)
1276 // Handle an optional end tag indicating what to do
1277 if (S
[Length
- 1] == '-')
1284 if (S
[Length
- 1] == '+')
1291 char *Slash
= strchr(S
,'=');
1299 Slash
= strchr(S
,'/');
1310 // Locate the package
1311 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
1313 if (Pkg
.end() == true)
1315 // Check if the name is a regex
1317 for (I
= S
; *I
!= 0; I
++)
1318 if (*I
== '.' || *I
== '?' || *I
== '*' || *I
== '|')
1321 return _error
->Error(_("Couldn't find package %s"),S
);
1323 // Regexs must always be confirmed
1324 ExpectedInst
+= 1000;
1326 // Compile the regex pattern
1329 if ((Res
= regcomp(&Pattern
,S
,REG_EXTENDED
| REG_ICASE
|
1333 regerror(Res
,&Pattern
,Error
,sizeof(Error
));
1334 return _error
->Error(_("Regex compilation error - %s"),Error
);
1337 // Run over the matches
1339 for (Pkg
= Cache
->PkgBegin(); Pkg
.end() == false; Pkg
++)
1341 if (regexec(&Pattern
,Pkg
.Name(),0,0,0) != 0)
1345 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1348 Hit
|= TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,
1349 ExpectedInst
,false);
1354 return _error
->Error(_("Couldn't find package %s"),S
);
1359 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1361 if (TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,ExpectedInst
) == false)
1366 /* If we are in the Broken fixing mode we do not attempt to fix the
1367 problems. This is if the user invoked install without -f and gave
1369 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1371 c1out
<< _("You might want to run `apt-get -f install' to correct these:") << endl
;
1372 ShowBroken(c1out
,Cache
,false);
1374 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1377 // Call the scored problem resolver
1378 Fix
.InstallProtect();
1379 if (Fix
.Resolve(true) == false)
1382 // Now we check the state of the packages,
1383 if (Cache
->BrokenCount() != 0)
1386 _("Some packages could not be installed. This may mean that you have\n"
1387 "requested an impossible situation or if you are using the unstable\n"
1388 "distribution that some required packages have not yet been created\n"
1389 "or been moved out of Incoming.") << endl
;
1394 _("Since you only requested a single operation it is extremely likely that\n"
1395 "the package is simply not installable and a bug report against\n"
1396 "that package should be filed.") << endl
;
1399 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1401 ShowBroken(c1out
,Cache
,false);
1402 return _error
->Error(_("Sorry, broken packages"));
1405 /* Print out a list of packages that are going to be installed extra
1406 to what the user asked */
1407 if (Cache
->InstCount() != ExpectedInst
)
1410 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1412 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1413 if ((*Cache
)[I
].Install() == false)
1417 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1418 if (strcmp(*J
,I
.Name()) == 0)
1422 List
+= string(I
.Name()) + " ";
1425 ShowList(c1out
,_("The following extra packages will be installed:"),List
);
1428 // See if we need to prompt
1429 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
1430 return InstallPackages(Cache
,false,false);
1432 return InstallPackages(Cache
,false);
1435 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1436 // ---------------------------------------------------------------------
1437 /* Intelligent upgrader that will install and remove packages at will */
1438 bool DoDistUpgrade(CommandLine
&CmdL
)
1441 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1444 c0out
<< _("Calculating Upgrade... ") << flush
;
1445 if (pkgDistUpgrade(*Cache
) == false)
1447 c0out
<< _("Failed") << endl
;
1448 ShowBroken(c1out
,Cache
,false);
1452 c0out
<< _("Done") << endl
;
1454 return InstallPackages(Cache
,true);
1457 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1458 // ---------------------------------------------------------------------
1459 /* Follows dselect's selections */
1460 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1463 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1466 // Install everything with the install flag set
1467 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1468 for (;I
.end() != true; I
++)
1470 /* Install the package only if it is a new install, the autoupgrader
1471 will deal with the rest */
1472 if (I
->SelectedState
== pkgCache::State::Install
)
1473 Cache
->MarkInstall(I
,false);
1476 /* Now install their deps too, if we do this above then order of
1477 the status file is significant for | groups */
1478 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1480 /* Install the package only if it is a new install, the autoupgrader
1481 will deal with the rest */
1482 if (I
->SelectedState
== pkgCache::State::Install
)
1483 Cache
->MarkInstall(I
,true);
1486 // Apply erasures now, they override everything else.
1487 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1490 if (I
->SelectedState
== pkgCache::State::DeInstall
||
1491 I
->SelectedState
== pkgCache::State::Purge
)
1492 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
1495 /* Resolve any problems that dselect created, allupgrade cannot handle
1496 such things. We do so quite agressively too.. */
1497 if (Cache
->BrokenCount() != 0)
1499 pkgProblemResolver
Fix(Cache
);
1501 // Hold back held packages.
1502 if (_config
->FindB("APT::Ignore-Hold",false) == false)
1504 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
1506 if (I
->SelectedState
== pkgCache::State::Hold
)
1514 if (Fix
.Resolve() == false)
1516 ShowBroken(c1out
,Cache
,false);
1517 return _error
->Error("Internal Error, problem resolver broke stuff");
1521 // Now upgrade everything
1522 if (pkgAllUpgrade(Cache
) == false)
1524 ShowBroken(c1out
,Cache
,false);
1525 return _error
->Error("Internal Error, problem resolver broke stuff");
1528 return InstallPackages(Cache
,false);
1531 // DoClean - Remove download archives /*{{{*/
1532 // ---------------------------------------------------------------------
1534 bool DoClean(CommandLine
&CmdL
)
1536 if (_config
->FindB("APT::Get::Simulate") == true)
1538 cout
<< "Del " << _config
->FindDir("Dir::Cache::archives") << "* " <<
1539 _config
->FindDir("Dir::Cache::archives") << "partial/*" << endl
;
1543 // Lock the archive directory
1545 if (_config
->FindB("Debug::NoLocking",false) == false)
1547 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1548 if (_error
->PendingError() == true)
1549 return _error
->Error(_("Unable to lock the download directory"));
1553 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
1554 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
1558 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
1559 // ---------------------------------------------------------------------
1560 /* This is similar to clean but it only purges things that cannot be
1561 downloaded, that is old versions of cached packages. */
1562 class LogCleaner
: public pkgArchiveCleaner
1565 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1567 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
1569 if (_config
->FindB("APT::Get::Simulate") == false)
1574 bool DoAutoClean(CommandLine
&CmdL
)
1576 // Lock the archive directory
1578 if (_config
->FindB("Debug::NoLocking",false) == false)
1580 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1581 if (_error
->PendingError() == true)
1582 return _error
->Error(_("Unable to lock the download directory"));
1586 if (Cache
.Open() == false)
1591 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1592 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1595 // DoCheck - Perform the check operation /*{{{*/
1596 // ---------------------------------------------------------------------
1597 /* Opening automatically checks the system, this command is mostly used
1599 bool DoCheck(CommandLine
&CmdL
)
1608 // DoSource - Fetch a source archive /*{{{*/
1609 // ---------------------------------------------------------------------
1610 /* Fetch souce packages */
1618 bool DoSource(CommandLine
&CmdL
)
1621 if (Cache
.Open(false) == false)
1624 if (CmdL
.FileSize() <= 1)
1625 return _error
->Error(_("Must specify at least one package to fetch source for"));
1627 // Read the source list
1629 if (List
.ReadMainList() == false)
1630 return _error
->Error(_("The list of sources could not be read."));
1632 // Create the text record parsers
1633 pkgRecords
Recs(Cache
);
1634 pkgSrcRecords
SrcRecs(List
);
1635 if (_error
->PendingError() == true)
1638 // Create the download object
1639 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1640 pkgAcquire
Fetcher(&Stat
);
1642 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
1644 // Load the requestd sources into the fetcher
1646 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1649 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1652 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1655 vector
<pkgSrcRecords::File
> Lst
;
1656 if (Last
->Files(Lst
) == false)
1659 // Load them into the fetcher
1660 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
1661 I
!= Lst
.end(); I
++)
1663 // Try to guess what sort of file it is we are getting.
1664 if (I
->Type
== "dsc")
1666 Dsc
[J
].Package
= Last
->Package();
1667 Dsc
[J
].Version
= Last
->Version();
1668 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
1671 // Diff only mode only fetches .diff files
1672 if (_config
->FindB("APT::Get::Diff-Only",false) == true &&
1676 // Tar only mode only fetches .tar files
1677 if (_config
->FindB("APT::Get::Tar-Only",false) == true &&
1681 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
1683 Last
->Index().SourceInfo(*Last
,*I
),Src
);
1687 // Display statistics
1688 double FetchBytes
= Fetcher
.FetchNeeded();
1689 double FetchPBytes
= Fetcher
.PartialPresent();
1690 double DebBytes
= Fetcher
.TotalNeeded();
1692 // Check for enough free space
1694 string OutputDir
= ".";
1695 if (statvfs(OutputDir
.c_str(),&Buf
) != 0)
1696 return _error
->Errno("statvfs","Couldn't determine free space in %s",
1698 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1699 return _error
->Error(_("Sorry, you don't have enough free space in %s"),
1703 if (DebBytes
!= FetchBytes
)
1704 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
1705 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
1707 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
1708 SizeToStr(DebBytes
).c_str());
1710 if (_config
->FindB("APT::Get::Simulate",false) == true)
1712 for (unsigned I
= 0; I
!= J
; I
++)
1713 ioprintf(cout
,_("Fetch Source %s\n"),Dsc
[I
].Package
.c_str());
1717 // Just print out the uris an exit if the --print-uris flag was used
1718 if (_config
->FindB("APT::Get::Print-URIs") == true)
1720 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1721 for (; I
!= Fetcher
.UriEnd(); I
++)
1722 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1723 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1728 if (Fetcher
.Run() == pkgAcquire::Failed
)
1731 // Print error messages
1732 bool Failed
= false;
1733 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1735 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1736 (*I
)->Complete
== true)
1739 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1740 (*I
)->ErrorText
.c_str());
1744 return _error
->Error(_("Failed to fetch some archives."));
1746 if (_config
->FindB("APT::Get::Download-only",false) == true)
1748 c1out
<< _("Download complete and in download only mode") << endl
;
1752 // Unpack the sources
1753 pid_t Process
= ExecFork();
1757 for (unsigned I
= 0; I
!= J
; I
++)
1759 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
1761 // Diff only mode only fetches .diff files
1762 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
1763 _config
->FindB("APT::Get::Tar-Only",false) == true ||
1764 Dsc
[I
].Dsc
.empty() == true)
1767 // See if the package is already unpacked
1769 if (stat(Dir
.c_str(),&Stat
) == 0 &&
1770 S_ISDIR(Stat
.st_mode
) != 0)
1772 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
1779 snprintf(S
,sizeof(S
),"%s -x %s",
1780 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
1781 Dsc
[I
].Dsc
.c_str());
1784 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
1789 // Try to compile it with dpkg-buildpackage
1790 if (_config
->FindB("APT::Get::Compile",false) == true)
1792 // Call dpkg-buildpackage
1794 snprintf(S
,sizeof(S
),"cd %s && %s %s",
1796 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
1797 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
1801 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
1810 // Wait for the subprocess
1812 while (waitpid(Process
,&Status
,0) != Process
)
1816 return _error
->Errno("waitpid","Couldn't wait for subprocess");
1819 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
1820 return _error
->Error(_("Child process failed"));
1825 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
1826 // ---------------------------------------------------------------------
1827 /* This function will look at the build depends list of the given source
1828 package and install the necessary packages to make it true, or fail. */
1829 bool DoBuildDep(CommandLine
&CmdL
)
1832 if (Cache
.Open(true) == false)
1835 if (CmdL
.FileSize() <= 1)
1836 return _error
->Error(_("Must specify at least one package to check builddeps for"));
1838 // Read the source list
1840 if (List
.ReadMainList() == false)
1841 return _error
->Error(_("The list of sources could not be read."));
1843 // Create the text record parsers
1844 pkgRecords
Recs(Cache
);
1845 pkgSrcRecords
SrcRecs(List
);
1846 if (_error
->PendingError() == true)
1849 // Create the download object
1850 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1851 pkgAcquire
Fetcher(&Stat
);
1854 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1857 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1859 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1861 // Process the build-dependencies
1862 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
1863 if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only",false)) == false)
1864 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
1866 if (BuildDeps
.size() == 0)
1868 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
1872 // Install the requested packages
1873 unsigned int ExpectedInst
= 0;
1874 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
1875 pkgProblemResolver
Fix(Cache
);
1876 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); D
++)
1878 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
1879 if (Pkg
.end() == true)
1881 /* for a build-conflict; ignore unknown packages */
1882 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1883 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1886 return _error
->Error(_("%s dependency on %s cannot be satisfied because the package %s cannot be found"),
1887 Last
->BuildDepType((*D
).Type
),Src
.c_str(),(*D
).Package
.c_str());
1889 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1891 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1892 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1895 * conflict; need to remove if we have an installed version
1896 * that satisfies the version criterial
1898 if (IV
.end() == false &&
1899 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1900 TryToInstall(Pkg
,Cache
,Fix
,true,false,ExpectedInst
);
1905 * If this is a virtual package, we need to check the list of
1906 * packages that provide it and see if any of those are
1909 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
1910 for (; Prv
.end() != true; Prv
++)
1911 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
1914 if (Prv
.end() == true)
1917 * depends; need to install or upgrade if we don't have the
1918 * package installed or if the version does not satisfy the
1919 * build dep. This is complicated by the fact that if we
1920 * depend on a version lower than what we already have
1921 * installed it is not clear what should be done; in practice
1922 * this case should be rare though and right now nothing
1923 * is done about it :-(
1925 if (IV
.end() == true ||
1926 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == false)
1927 TryToInstall(Pkg
,Cache
,Fix
,false,false,ExpectedInst
);
1932 Fix
.InstallProtect();
1933 if (Fix
.Resolve(true) == false)
1936 // Now we check the state of the packages,
1937 if (Cache
->BrokenCount() != 0)
1938 return _error
->Error(_("Some broken packages were found while trying to process build-dependencies.\n"
1939 "You might want to run `apt-get -f install' to correct these."));
1942 if (InstallPackages(Cache
, false, true) == false)
1943 return _error
->Error(_("Failed to process build dependencies"));
1948 // DoMoo - Never Ask, Never Tell /*{{{*/
1949 // ---------------------------------------------------------------------
1951 bool DoMoo(CommandLine
&CmdL
)
1960 "....\"Have you mooed today?\"...\n";
1965 // ShowHelp - Show a help screen /*{{{*/
1966 // ---------------------------------------------------------------------
1968 bool ShowHelp(CommandLine
&CmdL
)
1970 ioprintf(cout
,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE
,VERSION
,
1971 COMMON_OS
,COMMON_CPU
,__DATE__
,__TIME__
);
1973 if (_config
->FindB("version") == true)
1975 cout
<< _("Supported Modules:") << endl
;
1977 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
1979 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
1980 if (_system
!= 0 && _system
->VS
== VS
)
1984 cout
<< "Ver: " << VS
->Label
<< endl
;
1986 /* Print out all the packaging systems that will work with
1988 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
1990 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
1995 if (Sys
->VS
->TestCompatibility(*VS
) == true)
1996 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
2000 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
2002 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
2003 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
2006 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
2008 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
2009 cout
<< " Idx: " << Type
->Label
<< endl
;
2016 _("Usage: apt-get [options] command\n"
2017 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
2018 " apt-get [options] source pkg1 [pkg2 ...]\n"
2020 "apt-get is a simple command line interface for downloading and\n"
2021 "installing packages. The most frequently used commands are update\n"
2025 " update - Retrieve new lists of packages\n"
2026 " upgrade - Perform an upgrade\n"
2027 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
2028 " remove - Remove packages\n"
2029 " source - Download source archives\n"
2030 " build-dep - Configure build-dependencies for source packages\n"
2031 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
2032 " dselect-upgrade - Follow dselect selections\n"
2033 " clean - Erase downloaded archive files\n"
2034 " autoclean - Erase old downloaded archive files\n"
2035 " check - Verify that there are no broken dependencies\n"
2038 " -h This help text.\n"
2039 " -q Loggable output - no progress indicator\n"
2040 " -qq No output except for errors\n"
2041 " -d Download only - do NOT install or unpack archives\n"
2042 " -s No-act. Perform ordering simulation\n"
2043 " -y Assume Yes to all queries and do not prompt\n"
2044 " -f Attempt to continue if the integrity check fails\n"
2045 " -m Attempt to continue if archives are unlocatable\n"
2046 " -u Show a list of upgraded packages as well\n"
2047 " -b Build the source package after fetching it\n"
2048 " -c=? Read this configuration file\n"
2049 " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n"
2050 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
2051 "pages for more information and options.\n"
2052 " This APT has Super Cow Powers.\n");
2056 // GetInitialize - Initialize things for apt-get /*{{{*/
2057 // ---------------------------------------------------------------------
2059 void GetInitialize()
2061 _config
->Set("quiet",0);
2062 _config
->Set("help",false);
2063 _config
->Set("APT::Get::Download-Only",false);
2064 _config
->Set("APT::Get::Simulate",false);
2065 _config
->Set("APT::Get::Assume-Yes",false);
2066 _config
->Set("APT::Get::Fix-Broken",false);
2067 _config
->Set("APT::Get::Force-Yes",false);
2068 _config
->Set("APT::Get::APT::Get::No-List-Cleanup",true);
2071 // SigWinch - Window size change signal handler /*{{{*/
2072 // ---------------------------------------------------------------------
2076 // Riped from GNU ls
2080 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
2081 ScreenWidth
= ws
.ws_col
- 1;
2086 int main(int argc
,const char *argv
[])
2088 CommandLine::Args Args
[] = {
2089 {'h',"help","help",0},
2090 {'v',"version","version",0},
2091 {'q',"quiet","quiet",CommandLine::IntLevel
},
2092 {'q',"silent","quiet",CommandLine::IntLevel
},
2093 {'d',"download-only","APT::Get::Download-Only",0},
2094 {'b',"compile","APT::Get::Compile",0},
2095 {'b',"build","APT::Get::Compile",0},
2096 {'s',"simulate","APT::Get::Simulate",0},
2097 {'s',"just-print","APT::Get::Simulate",0},
2098 {'s',"recon","APT::Get::Simulate",0},
2099 {'s',"dry-run","APT::Get::Simulate",0},
2100 {'s',"no-act","APT::Get::Simulate",0},
2101 {'y',"yes","APT::Get::Assume-Yes",0},
2102 {'y',"assume-yes","APT::Get::Assume-Yes",0},
2103 {'f',"fix-broken","APT::Get::Fix-Broken",0},
2104 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
2105 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
2106 {'t',"target-release","APT::Default-Release",CommandLine::HasArg
},
2107 {'t',"default-release","APT::Default-Release",CommandLine::HasArg
},
2108 {0,"download","APT::Get::Download",0},
2109 {0,"fix-missing","APT::Get::Fix-Missing",0},
2110 {0,"ignore-hold","APT::Ignore-Hold",0},
2111 {0,"upgrade","APT::Get::upgrade",0},
2112 {0,"force-yes","APT::Get::force-yes",0},
2113 {0,"print-uris","APT::Get::Print-URIs",0},
2114 {0,"diff-only","APT::Get::Diff-Only",0},
2115 {0,"tar-only","APT::Get::tar-Only",0},
2116 {0,"purge","APT::Get::Purge",0},
2117 {0,"list-cleanup","APT::Get::List-Cleanup",0},
2118 {0,"reinstall","APT::Get::ReInstall",0},
2119 {0,"trivial-only","APT::Get::Trivial-Only",0},
2120 {0,"remove","APT::Get::Remove",0},
2121 {0,"only-source","APT::Get::Only-Source",0},
2122 {0,"arch-only","APT::Get::Arch-Only",0},
2123 {'c',"config-file",0,CommandLine::ConfigFile
},
2124 {'o',"option",0,CommandLine::ArbItem
},
2126 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
2127 {"upgrade",&DoUpgrade
},
2128 {"install",&DoInstall
},
2129 {"remove",&DoInstall
},
2130 {"dist-upgrade",&DoDistUpgrade
},
2131 {"dselect-upgrade",&DoDSelectUpgrade
},
2132 {"build-dep",&DoBuildDep
},
2134 {"autoclean",&DoAutoClean
},
2136 {"source",&DoSource
},
2141 // Parse the command line and initialize the package library
2142 CommandLine
CmdL(Args
,_config
);
2143 if (pkgInitConfig(*_config
) == false ||
2144 CmdL
.Parse(argc
,argv
) == false ||
2145 pkgInitSystem(*_config
,_system
) == false)
2147 if (_config
->FindB("version") == true)
2150 _error
->DumpErrors();
2154 // See if the help should be shown
2155 if (_config
->FindB("help") == true ||
2156 _config
->FindB("version") == true ||
2157 CmdL
.FileSize() == 0)
2163 // Deal with stdout not being a tty
2164 if (ttyname(STDOUT_FILENO
) == 0 && _config
->FindI("quiet",0) < 1)
2165 _config
->Set("quiet","1");
2167 // Setup the output streams
2168 c0out
.rdbuf(cout
.rdbuf());
2169 c1out
.rdbuf(cout
.rdbuf());
2170 c2out
.rdbuf(cout
.rdbuf());
2171 if (_config
->FindI("quiet",0) > 0)
2172 c0out
.rdbuf(devnull
.rdbuf());
2173 if (_config
->FindI("quiet",0) > 1)
2174 c1out
.rdbuf(devnull
.rdbuf());
2176 // Setup the signals
2177 signal(SIGPIPE
,SIG_IGN
);
2178 signal(SIGWINCH
,SigWinch
);
2181 // Match the operation
2182 CmdL
.DispatchArg(Cmds
);
2184 // Print any errors or warnings found during parsing
2185 if (_error
->empty() == false)
2187 bool Errors
= _error
->PendingError();
2188 _error
->DumpErrors();
2189 return Errors
== true?100:0;