]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.121 2002/07/08 04:09:52 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"
51 #include <sys/ioctl.h>
53 #include <sys/statvfs.h>
67 ofstream
devnull("/dev/null");
68 unsigned int ScreenWidth
= 80;
70 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
71 // ---------------------------------------------------------------------
73 class CacheFile
: public pkgCacheFile
75 static pkgCache
*SortCache
;
76 static int NameComp(const void *a
,const void *b
);
79 pkgCache::Package
**List
;
82 bool CheckDeps(bool AllowBroken
= false);
83 bool BuildCaches(bool WithLock
= true)
85 OpTextProgress
Prog(*_config
);
86 if (pkgCacheFile::BuildCaches(Prog
,WithLock
) == false)
90 bool Open(bool WithLock
= true)
92 OpTextProgress
Prog(*_config
);
93 if (pkgCacheFile::Open(Prog
,WithLock
) == false)
101 if (_config
->FindB("APT::Get::Print-URIs") == true)
106 CacheFile() : List(0) {};
110 // YnPrompt - Yes No Prompt. /*{{{*/
111 // ---------------------------------------------------------------------
112 /* Returns true on a Yes.*/
115 // This needs to be a capital
116 const char *Yes
= _("Y");
118 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
120 c1out
<< Yes
<< endl
;
126 if (read(STDIN_FILENO
,&C
,1) != 1)
128 while (C
!= '\n' && Jnk
!= '\n')
129 if (read(STDIN_FILENO
,&Jnk
,1) != 1)
132 if (!(toupper(C
) == *Yes
|| C
== '\n' || C
== '\r'))
137 // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
138 // ---------------------------------------------------------------------
139 /* Returns true on a Yes.*/
140 bool AnalPrompt(const char *Text
)
143 cin
.getline(Buf
,sizeof(Buf
));
144 if (strcmp(Buf
,Text
) == 0)
149 // ShowList - Show a list /*{{{*/
150 // ---------------------------------------------------------------------
151 /* This prints out a string of space separated words with a title and
152 a two space indent line wraped to the current screen width. */
153 bool ShowList(ostream
&out
,string Title
,string List
)
155 if (List
.empty() == true)
158 // Acount for the leading space
159 int ScreenWidth
= ::ScreenWidth
- 3;
161 out
<< Title
<< endl
;
162 string::size_type Start
= 0;
163 while (Start
< List
.size())
165 string::size_type End
;
166 if (Start
+ ScreenWidth
>= List
.size())
169 End
= List
.rfind(' ',Start
+ScreenWidth
);
171 if (End
== string::npos
|| End
< Start
)
172 End
= Start
+ ScreenWidth
;
173 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
179 // ShowBroken - Debugging aide /*{{{*/
180 // ---------------------------------------------------------------------
181 /* This prints out the names of all the packages that are broken along
182 with the name of each each broken dependency and a quite version
185 The output looks like:
186 Sorry, but the following packages have unmet dependencies:
187 exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed
188 Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
189 Depends: libsasl7 but it is not going to be installed
191 void ShowBroken(ostream
&out
,CacheFile
&Cache
,bool Now
)
193 out
<< _("Sorry, but the following packages have unmet dependencies:") << endl
;
194 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
196 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
200 if (Cache
[I
].NowBroken() == false)
205 if (Cache
[I
].InstBroken() == false)
209 // Print out each package and the failed dependencies
210 out
<<" " << I
.Name() << ":";
211 unsigned Indent
= strlen(I
.Name()) + 3;
213 pkgCache::VerIterator Ver
;
216 Ver
= I
.CurrentVer();
218 Ver
= Cache
[I
].InstVerIter(Cache
);
220 if (Ver
.end() == true)
226 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false;)
228 // Compute a single dependency element (glob or)
229 pkgCache::DepIterator Start
;
230 pkgCache::DepIterator End
;
233 if (Cache
->IsImportantDep(End
) == false)
238 if ((Cache
[End
] & pkgDepCache::DepGNow
) == pkgDepCache::DepGNow
)
243 if ((Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
251 for (unsigned J
= 0; J
!= Indent
; J
++)
255 if (FirstOr
== false)
257 for (unsigned J
= 0; J
!= strlen(End
.DepType()) + 3; J
++)
261 out
<< ' ' << End
.DepType() << ": ";
264 out
<< Start
.TargetPkg().Name();
266 // Show a quick summary of the version requirements
267 if (Start
.TargetVer() != 0)
268 out
<< " (" << Start
.CompType() << " " << Start
.TargetVer() << ")";
270 /* Show a summary of the target package if possible. In the case
271 of virtual packages we show nothing */
272 pkgCache::PkgIterator Targ
= Start
.TargetPkg();
273 if (Targ
->ProvidesList
== 0)
276 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
278 Ver
= Targ
.CurrentVer();
280 if (Ver
.end() == false)
283 ioprintf(out
,_("but %s is installed"),Ver
.VerStr());
285 ioprintf(out
,_("but %s is to be installed"),Ver
.VerStr());
289 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
291 if (Targ
->ProvidesList
== 0)
292 out
<< _("but it is not installable");
294 out
<< _("but it is a virtual package");
297 out
<< (Now
?_("but it is not installed"):_("but it is not going to be installed"));
313 // ShowNew - Show packages to newly install /*{{{*/
314 // ---------------------------------------------------------------------
316 void ShowNew(ostream
&out
,CacheFile
&Cache
)
318 /* Print out a list of packages that are going to be removed extra
319 to what the user asked */
321 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
323 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
324 if (Cache
[I
].NewInstall() == true)
325 List
+= string(I
.Name()) + " ";
328 ShowList(out
,_("The following NEW packages will be installed:"),List
);
331 // ShowDel - Show packages to delete /*{{{*/
332 // ---------------------------------------------------------------------
334 void ShowDel(ostream
&out
,CacheFile
&Cache
)
336 /* Print out a list of packages that are going to be removed extra
337 to what the user asked */
339 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
341 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
342 if (Cache
[I
].Delete() == true)
344 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
345 List
+= string(I
.Name()) + "* ";
347 List
+= string(I
.Name()) + " ";
351 ShowList(out
,_("The following packages will be REMOVED:"),List
);
354 // ShowKept - Show kept packages /*{{{*/
355 // ---------------------------------------------------------------------
357 void ShowKept(ostream
&out
,CacheFile
&Cache
)
360 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
362 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
365 if (Cache
[I
].Upgrade() == true || Cache
[I
].Upgradable() == false ||
366 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
369 List
+= string(I
.Name()) + " ";
371 ShowList(out
,_("The following packages have been kept back"),List
);
374 // ShowUpgraded - Show upgraded packages /*{{{*/
375 // ---------------------------------------------------------------------
377 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
380 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
382 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
385 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
388 List
+= string(I
.Name()) + " ";
390 ShowList(out
,_("The following packages will be upgraded"),List
);
393 // ShowDowngraded - Show downgraded packages /*{{{*/
394 // ---------------------------------------------------------------------
396 bool ShowDowngraded(ostream
&out
,CacheFile
&Cache
)
399 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
401 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
404 if (Cache
[I
].Downgrade() == false || Cache
[I
].NewInstall() == true)
407 List
+= string(I
.Name()) + " ";
409 return ShowList(out
,_("The following packages will be DOWNGRADED"),List
);
412 // ShowHold - Show held but changed packages /*{{{*/
413 // ---------------------------------------------------------------------
415 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
418 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
420 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
421 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
422 I
->SelectedState
== pkgCache::State::Hold
)
423 List
+= string(I
.Name()) + " ";
426 return ShowList(out
,_("The following held packages will be changed:"),List
);
429 // ShowEssential - Show an essential package warning /*{{{*/
430 // ---------------------------------------------------------------------
431 /* This prints out a warning message that is not to be ignored. It shows
432 all essential packages and their dependents that are to be removed.
433 It is insanely risky to remove the dependents of an essential package! */
434 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
437 bool *Added
= new bool[Cache
->Head().PackageCount
];
438 for (unsigned int I
= 0; I
!= Cache
->Head().PackageCount
; I
++)
441 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
443 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
444 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
&&
445 (I
->Flags
& pkgCache::Flag::Important
) != pkgCache::Flag::Important
)
448 // The essential package is being removed
449 if (Cache
[I
].Delete() == true)
451 if (Added
[I
->ID
] == false)
454 List
+= string(I
.Name()) + " ";
458 if (I
->CurrentVer
== 0)
461 // Print out any essential package depenendents that are to be removed
462 for (pkgCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
464 // Skip everything but depends
465 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
466 D
->Type
!= pkgCache::Dep::Depends
)
469 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
470 if (Cache
[P
].Delete() == true)
472 if (Added
[P
->ID
] == true)
477 snprintf(S
,sizeof(S
),_("%s (due to %s) "),P
.Name(),I
.Name());
484 return ShowList(out
,_("WARNING: The following essential packages will be removed\n"
485 "This should NOT be done unless you know exactly what you are doing!"),List
);
488 // Stats - Show some statistics /*{{{*/
489 // ---------------------------------------------------------------------
491 void Stats(ostream
&out
,pkgDepCache
&Dep
)
493 unsigned long Upgrade
= 0;
494 unsigned long Downgrade
= 0;
495 unsigned long Install
= 0;
496 unsigned long ReInstall
= 0;
497 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
499 if (Dep
[I
].NewInstall() == true)
503 if (Dep
[I
].Upgrade() == true)
506 if (Dep
[I
].Downgrade() == true)
510 if (Dep
[I
].Delete() == false && (Dep
[I
].iFlags
& pkgDepCache::ReInstall
) == pkgDepCache::ReInstall
)
514 ioprintf(out
,_("%lu packages upgraded, %lu newly installed, "),
518 ioprintf(out
,_("%lu reinstalled, "),ReInstall
);
520 ioprintf(out
,_("%lu downgraded, "),Downgrade
);
522 ioprintf(out
,_("%lu to remove and %lu not upgraded.\n"),
523 Dep
.DelCount(),Dep
.KeepCount());
525 if (Dep
.BadCount() != 0)
526 ioprintf(out
,_("%lu packages not fully installed or removed.\n"),
531 // CacheFile::NameComp - QSort compare by name /*{{{*/
532 // ---------------------------------------------------------------------
534 pkgCache
*CacheFile::SortCache
= 0;
535 int CacheFile::NameComp(const void *a
,const void *b
)
537 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
538 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
540 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
541 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
543 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
546 // CacheFile::Sort - Sort by name /*{{{*/
547 // ---------------------------------------------------------------------
549 void CacheFile::Sort()
552 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
553 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
554 pkgCache::PkgIterator I
= Cache
->PkgBegin();
555 for (;I
.end() != true; I
++)
559 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
562 // CacheFile::CheckDeps - Open the cache file /*{{{*/
563 // ---------------------------------------------------------------------
564 /* This routine generates the caches and then opens the dependency cache
565 and verifies that the system is OK. */
566 bool CacheFile::CheckDeps(bool AllowBroken
)
568 if (_error
->PendingError() == true)
571 // Check that the system is OK
572 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
573 return _error
->Error("Internal Error, non-zero counts");
575 // Apply corrections for half-installed packages
576 if (pkgApplyStatus(*DCache
) == false)
580 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
583 // Attempt to fix broken things
584 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
586 c1out
<< _("Correcting dependencies...") << flush
;
587 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
589 c1out
<< _(" failed.") << endl
;
590 ShowBroken(c1out
,*this,true);
592 return _error
->Error(_("Unable to correct dependencies"));
594 if (pkgMinimizeUpgrade(*DCache
) == false)
595 return _error
->Error(_("Unable to minimize the upgrade set"));
597 c1out
<< _(" Done") << endl
;
601 c1out
<< _("You might want to run `apt-get -f install' to correct these.") << endl
;
602 ShowBroken(c1out
,*this,true);
604 return _error
->Error(_("Unmet dependencies. Try using -f."));
611 // InstallPackages - Actually download and install the packages /*{{{*/
612 // ---------------------------------------------------------------------
613 /* This displays the informative messages describing what is going to
614 happen and then calls the download routines */
615 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,
618 if (_config
->FindB("APT::Get::Purge",false) == true)
620 pkgCache::PkgIterator I
= Cache
->PkgBegin();
621 for (; I
.end() == false; I
++)
623 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
624 Cache
->MarkDelete(I
,true);
629 bool Essential
= false;
631 // Show all the various warning indicators
632 ShowDel(c1out
,Cache
);
633 ShowNew(c1out
,Cache
);
635 ShowKept(c1out
,Cache
);
636 Fail
|= !ShowHold(c1out
,Cache
);
637 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
638 ShowUpgraded(c1out
,Cache
);
639 Fail
|= !ShowDowngraded(c1out
,Cache
);
640 Essential
= !ShowEssential(c1out
,Cache
);
645 if (Cache
->BrokenCount() != 0)
647 ShowBroken(c1out
,Cache
,false);
648 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
651 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
652 Cache
->BadCount() == 0)
656 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::Remove",true) == false)
657 return _error
->Error(_("Packages need to be removed but Remove is disabled."));
659 // Run the simulator ..
660 if (_config
->FindB("APT::Get::Simulate") == true)
662 pkgSimulate
PM(Cache
);
663 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
664 if (Res
== pkgPackageManager::Failed
)
666 if (Res
!= pkgPackageManager::Completed
)
667 return _error
->Error("Internal Error, Ordering didn't finish");
671 // Create the text record parser
672 pkgRecords
Recs(Cache
);
673 if (_error
->PendingError() == true)
676 // Lock the archive directory
678 if (_config
->FindB("Debug::NoLocking",false) == false &&
679 _config
->FindB("APT::Get::Print-URIs") == false)
681 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
682 if (_error
->PendingError() == true)
683 return _error
->Error(_("Unable to lock the download directory"));
686 // Create the download object
687 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
688 pkgAcquire
Fetcher(&Stat
);
690 // Read the source list
692 if (List
.ReadMainList() == false)
693 return _error
->Error(_("The list of sources could not be read."));
695 // Create the package manager and prepare to download
696 SPtr
<pkgPackageManager
> PM
= _system
->CreatePM(Cache
);
697 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false ||
698 _error
->PendingError() == true)
701 // Display statistics
702 double FetchBytes
= Fetcher
.FetchNeeded();
703 double FetchPBytes
= Fetcher
.PartialPresent();
704 double DebBytes
= Fetcher
.TotalNeeded();
705 if (DebBytes
!= Cache
->DebSize())
707 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
708 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
712 if (DebBytes
!= FetchBytes
)
713 ioprintf(c1out
,_("Need to get %sB/%sB of archives. "),
714 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
716 ioprintf(c1out
,_("Need to get %sB of archives. "),
717 SizeToStr(DebBytes
).c_str());
720 if (Cache
->UsrSize() >= 0)
721 ioprintf(c1out
,_("After unpacking %sB will be used.\n"),
722 SizeToStr(Cache
->UsrSize()).c_str());
724 ioprintf(c1out
,_("After unpacking %sB will be freed.\n"),
725 SizeToStr(-1*Cache
->UsrSize()).c_str());
727 if (_error
->PendingError() == true)
730 /* Check for enough free space, but only if we are actually going to
732 if (_config
->FindB("APT::Get::Print-URIs") == false &&
733 _config
->FindB("APT::Get::Download",true) == true)
736 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
737 if (statvfs(OutputDir
.c_str(),&Buf
) != 0)
738 return _error
->Errno("statvfs","Couldn't determine free space in %s",
740 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
741 return _error
->Error(_("Sorry, you don't have enough free space in %s to hold all the .debs."),
746 if (_config
->FindI("quiet",0) >= 2 ||
747 _config
->FindB("APT::Get::Assume-Yes",false) == true)
749 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
750 return _error
->Error(_("There are problems and -y was used without --force-yes"));
753 if (Essential
== true && Saftey
== true)
755 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
756 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
758 const char *Prompt
= _("Yes, do as I say!");
760 _("You are about to do something potentially harmful\n"
761 "To continue type in the phrase '%s'\n"
764 if (AnalPrompt(Prompt
) == false)
766 c2out
<< _("Abort.") << endl
;
772 // Prompt to continue
773 if (Ask
== true || Fail
== true)
775 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
776 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
778 if (_config
->FindI("quiet",0) < 2 &&
779 _config
->FindB("APT::Get::Assume-Yes",false) == false)
781 c2out
<< _("Do you want to continue? [Y/n] ") << flush
;
783 if (YnPrompt() == false)
785 c2out
<< _("Abort.") << endl
;
792 // Just print out the uris an exit if the --print-uris flag was used
793 if (_config
->FindB("APT::Get::Print-URIs") == true)
795 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
796 for (; I
!= Fetcher
.UriEnd(); I
++)
797 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
798 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
802 /* Unlock the dpkg lock if we are not going to be doing an install
804 if (_config
->FindB("APT::Get::Download-Only",false) == true)
810 bool Transient
= false;
811 if (_config
->FindB("APT::Get::Download",true) == false)
813 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
815 if ((*I
)->Local
== true)
821 // Close the item and check if it was found in cache
823 if ((*I
)->Complete
== false)
826 // Clear it out of the fetch list
828 I
= Fetcher
.ItemsBegin();
832 if (Fetcher
.Run() == pkgAcquire::Failed
)
837 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
839 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
840 (*I
)->Complete
== true)
843 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
850 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
851 (*I
)->ErrorText
.c_str());
855 /* If we are in no download mode and missing files and there were
856 'failures' then the user must specify -m. Furthermore, there
857 is no such thing as a transient error in no-download mode! */
858 if (Transient
== true &&
859 _config
->FindB("APT::Get::Download",true) == false)
865 if (_config
->FindB("APT::Get::Download-Only",false) == true)
867 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
868 return _error
->Error(_("Some files failed to download"));
869 c1out
<< _("Download complete and in download only mode") << endl
;
873 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
875 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
878 if (Transient
== true && Failed
== true)
879 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
881 // Try to deal with missing package files
882 if (Failed
== true && PM
->FixMissing() == false)
884 cerr
<< _("Unable to correct missing packages.") << endl
;
885 return _error
->Error(_("Aborting Install."));
889 pkgPackageManager::OrderResult Res
= PM
->DoInstall();
890 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
892 if (Res
== pkgPackageManager::Completed
)
895 // Reload the fetcher object and loop again for media swapping
897 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false)
904 // TryToInstall - Try to install a single package /*{{{*/
905 // ---------------------------------------------------------------------
906 /* This used to be inlined in DoInstall, but with the advent of regex package
907 name matching it was split out.. */
908 bool TryToInstall(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
909 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
910 unsigned int &ExpectedInst
,bool AllowFail
= true)
912 /* This is a pure virtual package and there is a single available
914 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0 &&
915 Pkg
.ProvidesList()->NextProvides
== 0)
917 pkgCache::PkgIterator Tmp
= Pkg
.ProvidesList().OwnerPkg();
918 ioprintf(c1out
,_("Note, selecting %s instead of %s\n"),
919 Tmp
.Name(),Pkg
.Name());
923 // Handle the no-upgrade case
924 if (_config
->FindB("APT::Get::upgrade",true) == false &&
925 Pkg
->CurrentVer
!= 0)
927 if (AllowFail
== true)
928 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
933 // Check if there is something at all to install
934 pkgDepCache::StateCache
&State
= Cache
[Pkg
];
935 if (Remove
== true && Pkg
->CurrentVer
== 0)
941 /* We want to continue searching for regex hits, so we return false here
942 otherwise this is not really an error. */
943 if (AllowFail
== false)
946 ioprintf(c1out
,_("Package %s is not installed, so not removed\n"),Pkg
.Name());
950 if (State
.CandidateVer
== 0 && Remove
== false)
952 if (AllowFail
== false)
955 if (Pkg
->ProvidesList
!= 0)
957 ioprintf(c1out
,_("Package %s is a virtual package provided by:\n"),
960 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
961 for (; I
.end() == false; I
++)
963 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
965 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer())
967 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
968 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
969 _(" [Installed]") << endl
;
971 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
974 c1out
<< _("You should explicitly select one to install.") << endl
;
979 _("Package %s has no available version, but exists in the database.\n"
980 "This typically means that the package was mentioned in a dependency and\n"
981 "never uploaded, has been obsoleted or is not available with the contents\n"
982 "of sources.list\n"),Pkg
.Name());
985 SPtrArray
<bool> Seen
= new bool[Cache
.Head().PackageCount
];
986 memset(Seen
,0,Cache
.Head().PackageCount
*sizeof(*Seen
));
987 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
988 for (; Dep
.end() == false; Dep
++)
990 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
992 if (Seen
[Dep
.ParentPkg()->ID
] == true)
994 Seen
[Dep
.ParentPkg()->ID
] = true;
995 List
+= string(Dep
.ParentPkg().Name()) + " ";
997 ShowList(c1out
,_("However the following packages replace it:"),List
);
1000 _error
->Error(_("Package %s has no installation candidate"),Pkg
.Name());
1009 Cache
.MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
1014 Cache
.MarkInstall(Pkg
,false);
1015 if (State
.Install() == false)
1017 if (_config
->FindB("APT::Get::ReInstall",false) == true)
1019 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
1020 ioprintf(c1out
,_("Sorry, re-installation of %s is not possible, it cannot be downloaded.\n"),
1023 Cache
.SetReInstall(Pkg
,true);
1027 if (AllowFail
== true)
1028 ioprintf(c1out
,_("Sorry, %s is already the newest version.\n"),
1035 // Install it with autoinstalling enabled.
1036 if (State
.InstBroken() == true && BrokenFix
== false)
1037 Cache
.MarkInstall(Pkg
,true);
1041 // TryToChangeVer - Try to change a candidate version /*{{{*/
1042 // ---------------------------------------------------------------------
1044 bool TryToChangeVer(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
1045 const char *VerTag
,bool IsRel
)
1047 pkgVersionMatch
Match(VerTag
,(IsRel
== true?pkgVersionMatch::Release
:
1048 pkgVersionMatch::Version
));
1050 pkgCache::VerIterator Ver
= Match
.Find(Pkg
);
1052 if (Ver
.end() == true)
1055 return _error
->Error(_("Release '%s' for '%s' was not found"),
1057 return _error
->Error(_("Version '%s' for '%s' was not found"),
1061 if (strcmp(VerTag
,Ver
.VerStr()) != 0)
1063 ioprintf(c1out
,_("Selected version %s (%s) for %s\n"),
1064 Ver
.VerStr(),Ver
.RelStr().c_str(),Pkg
.Name());
1067 Cache
.SetCandidateVersion(Ver
);
1071 // FindSrc - Find a source record /*{{{*/
1072 // ---------------------------------------------------------------------
1074 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
1075 pkgSrcRecords
&SrcRecs
,string
&Src
,
1078 // We want to pull the version off the package specification..
1080 string TmpSrc
= Name
;
1081 string::size_type Slash
= TmpSrc
.rfind('=');
1082 if (Slash
!= string::npos
)
1084 VerTag
= string(TmpSrc
.begin() + Slash
+ 1,TmpSrc
.end());
1085 TmpSrc
= string(TmpSrc
.begin(),TmpSrc
.begin() + Slash
);
1088 /* Lookup the version of the package we would install if we were to
1089 install a version and determine the source package name, then look
1090 in the archive for a source package of the same name. In theory
1091 we could stash the version string as well and match that too but
1092 today there aren't multi source versions in the archive. */
1093 if (_config
->FindB("APT::Get::Only-Source") == false &&
1094 VerTag
.empty() == true)
1096 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(TmpSrc
);
1097 if (Pkg
.end() == false)
1099 pkgCache::VerIterator Ver
= Cache
.GetCandidateVer(Pkg
);
1100 if (Ver
.end() == false)
1102 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1103 Src
= Parse
.SourcePkg();
1108 // No source package name..
1109 if (Src
.empty() == true)
1113 pkgSrcRecords::Parser
*Last
= 0;
1114 unsigned long Offset
= 0;
1116 bool IsMatch
= false;
1118 // If we are matching by version then we need exact matches to be happy
1119 if (VerTag
.empty() == false)
1122 /* Iterate over all of the hits, which includes the resulting
1123 binary packages in the search */
1124 pkgSrcRecords::Parser
*Parse
;
1126 while ((Parse
= SrcRecs
.Find(Src
.c_str(),false)) != 0)
1128 string Ver
= Parse
->Version();
1130 // Skip name mismatches
1131 if (IsMatch
== true && Parse
->Package() != Src
)
1134 if (VerTag
.empty() == false)
1136 /* Don't want to fall through because we are doing exact version
1138 if (Cache
.VS().CmpVersion(VerTag
,Ver
) != 0)
1142 Offset
= Parse
->Offset();
1146 // Newer version or an exact match
1147 if (Last
== 0 || Cache
.VS().CmpVersion(Version
,Ver
) < 0 ||
1148 (Parse
->Package() == Src
&& IsMatch
== false))
1150 IsMatch
= Parse
->Package() == Src
;
1152 Offset
= Parse
->Offset();
1160 if (Last
->Jump(Offset
) == false)
1167 // DoUpdate - Update the package lists /*{{{*/
1168 // ---------------------------------------------------------------------
1170 bool DoUpdate(CommandLine
&CmdL
)
1172 if (CmdL
.FileSize() != 1)
1173 return _error
->Error(_("The update command takes no arguments"));
1175 // Get the source list
1177 if (List
.ReadMainList() == false)
1180 // Lock the list directory
1182 if (_config
->FindB("Debug::NoLocking",false) == false)
1184 Lock
.Fd(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
1185 if (_error
->PendingError() == true)
1186 return _error
->Error(_("Unable to lock the list directory"));
1189 // Create the download object
1190 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1191 pkgAcquire
Fetcher(&Stat
);
1193 // Populate it with the source selection
1194 if (List
.GetIndexes(&Fetcher
) == false)
1197 // Just print out the uris an exit if the --print-uris flag was used
1198 if (_config
->FindB("APT::Get::Print-URIs") == true)
1200 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1201 for (; I
!= Fetcher
.UriEnd(); I
++)
1202 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1203 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1208 if (Fetcher
.Run() == pkgAcquire::Failed
)
1211 bool Failed
= false;
1212 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1214 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
1219 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1220 (*I
)->ErrorText
.c_str());
1224 // Clean out any old list files
1225 if (_config
->FindB("APT::Get::List-Cleanup",true) == true)
1227 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
1228 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
1232 // Prepare the cache.
1234 if (Cache
.BuildCaches() == false)
1238 return _error
->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
1243 // DoUpgrade - Upgrade all packages /*{{{*/
1244 // ---------------------------------------------------------------------
1245 /* Upgrade all packages without installing new packages or erasing old
1247 bool DoUpgrade(CommandLine
&CmdL
)
1250 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1254 if (pkgAllUpgrade(Cache
) == false)
1256 ShowBroken(c1out
,Cache
,false);
1257 return _error
->Error(_("Internal Error, AllUpgrade broke stuff"));
1260 return InstallPackages(Cache
,true);
1263 // DoInstall - Install packages from the command line /*{{{*/
1264 // ---------------------------------------------------------------------
1265 /* Install named packages */
1266 bool DoInstall(CommandLine
&CmdL
)
1269 if (Cache
.OpenForInstall() == false ||
1270 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
1273 // Enter the special broken fixing mode if the user specified arguments
1274 bool BrokenFix
= false;
1275 if (Cache
->BrokenCount() != 0)
1278 unsigned int ExpectedInst
= 0;
1279 unsigned int Packages
= 0;
1280 pkgProblemResolver
Fix(Cache
);
1282 bool DefRemove
= false;
1283 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
1286 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1288 // Duplicate the string
1289 unsigned int Length
= strlen(*I
);
1291 if (Length
>= sizeof(S
))
1295 // See if we are removing and special indicators..
1296 bool Remove
= DefRemove
;
1298 bool VerIsRel
= false;
1299 while (Cache
->FindPkg(S
).end() == true)
1301 // Handle an optional end tag indicating what to do
1302 if (S
[Length
- 1] == '-')
1309 if (S
[Length
- 1] == '+')
1316 char *Slash
= strchr(S
,'=');
1324 Slash
= strchr(S
,'/');
1335 // Locate the package
1336 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
1338 if (Pkg
.end() == true)
1340 // Check if the name is a regex
1342 for (I
= S
; *I
!= 0; I
++)
1343 if (*I
== '?' || *I
== '*' || *I
== '|' ||
1344 *I
== '[' || *I
== '^' || *I
== '$')
1347 return _error
->Error(_("Couldn't find package %s"),S
);
1349 // Regexs must always be confirmed
1350 ExpectedInst
+= 1000;
1352 // Compile the regex pattern
1355 if ((Res
= regcomp(&Pattern
,S
,REG_EXTENDED
| REG_ICASE
|
1359 regerror(Res
,&Pattern
,Error
,sizeof(Error
));
1360 return _error
->Error(_("Regex compilation error - %s"),Error
);
1363 // Run over the matches
1365 for (Pkg
= Cache
->PkgBegin(); Pkg
.end() == false; Pkg
++)
1367 if (regexec(&Pattern
,Pkg
.Name(),0,0,0) != 0)
1370 ioprintf(c1out
,_("Note, selecting %s for regex '%s'\n"),
1374 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1377 Hit
|= TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,
1378 ExpectedInst
,false);
1383 return _error
->Error(_("Couldn't find package %s"),S
);
1388 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1390 if (TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,ExpectedInst
) == false)
1395 /* If we are in the Broken fixing mode we do not attempt to fix the
1396 problems. This is if the user invoked install without -f and gave
1398 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1400 c1out
<< _("You might want to run `apt-get -f install' to correct these:") << endl
;
1401 ShowBroken(c1out
,Cache
,false);
1403 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1406 // Call the scored problem resolver
1407 Fix
.InstallProtect();
1408 if (Fix
.Resolve(true) == false)
1411 // Now we check the state of the packages,
1412 if (Cache
->BrokenCount() != 0)
1415 _("Some packages could not be installed. This may mean that you have\n"
1416 "requested an impossible situation or if you are using the unstable\n"
1417 "distribution that some required packages have not yet been created\n"
1418 "or been moved out of Incoming.") << endl
;
1423 _("Since you only requested a single operation it is extremely likely that\n"
1424 "the package is simply not installable and a bug report against\n"
1425 "that package should be filed.") << endl
;
1428 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1430 ShowBroken(c1out
,Cache
,false);
1431 return _error
->Error(_("Sorry, broken packages"));
1434 /* Print out a list of packages that are going to be installed extra
1435 to what the user asked */
1436 if (Cache
->InstCount() != ExpectedInst
)
1439 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1441 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1442 if ((*Cache
)[I
].Install() == false)
1446 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1447 if (strcmp(*J
,I
.Name()) == 0)
1451 List
+= string(I
.Name()) + " ";
1454 ShowList(c1out
,_("The following extra packages will be installed:"),List
);
1457 // See if we need to prompt
1458 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
1459 return InstallPackages(Cache
,false,false);
1461 return InstallPackages(Cache
,false);
1464 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1465 // ---------------------------------------------------------------------
1466 /* Intelligent upgrader that will install and remove packages at will */
1467 bool DoDistUpgrade(CommandLine
&CmdL
)
1470 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1473 c0out
<< _("Calculating Upgrade... ") << flush
;
1474 if (pkgDistUpgrade(*Cache
) == false)
1476 c0out
<< _("Failed") << endl
;
1477 ShowBroken(c1out
,Cache
,false);
1481 c0out
<< _("Done") << endl
;
1483 return InstallPackages(Cache
,true);
1486 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1487 // ---------------------------------------------------------------------
1488 /* Follows dselect's selections */
1489 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1492 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1495 // Install everything with the install flag set
1496 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1497 for (;I
.end() != true; I
++)
1499 /* Install the package only if it is a new install, the autoupgrader
1500 will deal with the rest */
1501 if (I
->SelectedState
== pkgCache::State::Install
)
1502 Cache
->MarkInstall(I
,false);
1505 /* Now install their deps too, if we do this above then order of
1506 the status file is significant for | groups */
1507 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1509 /* Install the package only if it is a new install, the autoupgrader
1510 will deal with the rest */
1511 if (I
->SelectedState
== pkgCache::State::Install
)
1512 Cache
->MarkInstall(I
,true);
1515 // Apply erasures now, they override everything else.
1516 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1519 if (I
->SelectedState
== pkgCache::State::DeInstall
||
1520 I
->SelectedState
== pkgCache::State::Purge
)
1521 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
1524 /* Resolve any problems that dselect created, allupgrade cannot handle
1525 such things. We do so quite agressively too.. */
1526 if (Cache
->BrokenCount() != 0)
1528 pkgProblemResolver
Fix(Cache
);
1530 // Hold back held packages.
1531 if (_config
->FindB("APT::Ignore-Hold",false) == false)
1533 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
1535 if (I
->SelectedState
== pkgCache::State::Hold
)
1543 if (Fix
.Resolve() == false)
1545 ShowBroken(c1out
,Cache
,false);
1546 return _error
->Error("Internal Error, problem resolver broke stuff");
1550 // Now upgrade everything
1551 if (pkgAllUpgrade(Cache
) == false)
1553 ShowBroken(c1out
,Cache
,false);
1554 return _error
->Error("Internal Error, problem resolver broke stuff");
1557 return InstallPackages(Cache
,false);
1560 // DoClean - Remove download archives /*{{{*/
1561 // ---------------------------------------------------------------------
1563 bool DoClean(CommandLine
&CmdL
)
1565 if (_config
->FindB("APT::Get::Simulate") == true)
1567 cout
<< "Del " << _config
->FindDir("Dir::Cache::archives") << "* " <<
1568 _config
->FindDir("Dir::Cache::archives") << "partial/*" << endl
;
1572 // Lock the archive directory
1574 if (_config
->FindB("Debug::NoLocking",false) == false)
1576 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1577 if (_error
->PendingError() == true)
1578 return _error
->Error(_("Unable to lock the download directory"));
1582 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
1583 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
1587 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
1588 // ---------------------------------------------------------------------
1589 /* This is similar to clean but it only purges things that cannot be
1590 downloaded, that is old versions of cached packages. */
1591 class LogCleaner
: public pkgArchiveCleaner
1594 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1596 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
1598 if (_config
->FindB("APT::Get::Simulate") == false)
1603 bool DoAutoClean(CommandLine
&CmdL
)
1605 // Lock the archive directory
1607 if (_config
->FindB("Debug::NoLocking",false) == false)
1609 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1610 if (_error
->PendingError() == true)
1611 return _error
->Error(_("Unable to lock the download directory"));
1615 if (Cache
.Open() == false)
1620 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1621 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1624 // DoCheck - Perform the check operation /*{{{*/
1625 // ---------------------------------------------------------------------
1626 /* Opening automatically checks the system, this command is mostly used
1628 bool DoCheck(CommandLine
&CmdL
)
1637 // DoSource - Fetch a source archive /*{{{*/
1638 // ---------------------------------------------------------------------
1639 /* Fetch souce packages */
1647 bool DoSource(CommandLine
&CmdL
)
1650 if (Cache
.Open(false) == false)
1653 if (CmdL
.FileSize() <= 1)
1654 return _error
->Error(_("Must specify at least one package to fetch source for"));
1656 // Read the source list
1658 if (List
.ReadMainList() == false)
1659 return _error
->Error(_("The list of sources could not be read."));
1661 // Create the text record parsers
1662 pkgRecords
Recs(Cache
);
1663 pkgSrcRecords
SrcRecs(List
);
1664 if (_error
->PendingError() == true)
1667 // Create the download object
1668 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1669 pkgAcquire
Fetcher(&Stat
);
1671 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
1673 // Load the requestd sources into the fetcher
1675 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1678 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1681 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1684 vector
<pkgSrcRecords::File
> Lst
;
1685 if (Last
->Files(Lst
) == false)
1688 // Load them into the fetcher
1689 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
1690 I
!= Lst
.end(); I
++)
1692 // Try to guess what sort of file it is we are getting.
1693 if (I
->Type
== "dsc")
1695 Dsc
[J
].Package
= Last
->Package();
1696 Dsc
[J
].Version
= Last
->Version();
1697 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
1700 // Diff only mode only fetches .diff files
1701 if (_config
->FindB("APT::Get::Diff-Only",false) == true &&
1705 // Tar only mode only fetches .tar files
1706 if (_config
->FindB("APT::Get::Tar-Only",false) == true &&
1710 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
1712 Last
->Index().SourceInfo(*Last
,*I
),Src
);
1716 // Display statistics
1717 double FetchBytes
= Fetcher
.FetchNeeded();
1718 double FetchPBytes
= Fetcher
.PartialPresent();
1719 double DebBytes
= Fetcher
.TotalNeeded();
1721 // Check for enough free space
1723 string OutputDir
= ".";
1724 if (statvfs(OutputDir
.c_str(),&Buf
) != 0)
1725 return _error
->Errno("statvfs","Couldn't determine free space in %s",
1727 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1728 return _error
->Error(_("Sorry, you don't have enough free space in %s"),
1732 if (DebBytes
!= FetchBytes
)
1733 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
1734 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
1736 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
1737 SizeToStr(DebBytes
).c_str());
1739 if (_config
->FindB("APT::Get::Simulate",false) == true)
1741 for (unsigned I
= 0; I
!= J
; I
++)
1742 ioprintf(cout
,_("Fetch Source %s\n"),Dsc
[I
].Package
.c_str());
1746 // Just print out the uris an exit if the --print-uris flag was used
1747 if (_config
->FindB("APT::Get::Print-URIs") == true)
1749 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1750 for (; I
!= Fetcher
.UriEnd(); I
++)
1751 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1752 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1757 if (Fetcher
.Run() == pkgAcquire::Failed
)
1760 // Print error messages
1761 bool Failed
= false;
1762 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1764 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1765 (*I
)->Complete
== true)
1768 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1769 (*I
)->ErrorText
.c_str());
1773 return _error
->Error(_("Failed to fetch some archives."));
1775 if (_config
->FindB("APT::Get::Download-only",false) == true)
1777 c1out
<< _("Download complete and in download only mode") << endl
;
1781 // Unpack the sources
1782 pid_t Process
= ExecFork();
1786 for (unsigned I
= 0; I
!= J
; I
++)
1788 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
1790 // Diff only mode only fetches .diff files
1791 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
1792 _config
->FindB("APT::Get::Tar-Only",false) == true ||
1793 Dsc
[I
].Dsc
.empty() == true)
1796 // See if the package is already unpacked
1798 if (stat(Dir
.c_str(),&Stat
) == 0 &&
1799 S_ISDIR(Stat
.st_mode
) != 0)
1801 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
1808 snprintf(S
,sizeof(S
),"%s -x %s",
1809 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
1810 Dsc
[I
].Dsc
.c_str());
1813 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
1818 // Try to compile it with dpkg-buildpackage
1819 if (_config
->FindB("APT::Get::Compile",false) == true)
1821 // Call dpkg-buildpackage
1823 snprintf(S
,sizeof(S
),"cd %s && %s %s",
1825 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
1826 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
1830 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
1839 // Wait for the subprocess
1841 while (waitpid(Process
,&Status
,0) != Process
)
1845 return _error
->Errno("waitpid","Couldn't wait for subprocess");
1848 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
1849 return _error
->Error(_("Child process failed"));
1854 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
1855 // ---------------------------------------------------------------------
1856 /* This function will look at the build depends list of the given source
1857 package and install the necessary packages to make it true, or fail. */
1858 bool DoBuildDep(CommandLine
&CmdL
)
1861 if (Cache
.Open(true) == false)
1864 if (CmdL
.FileSize() <= 1)
1865 return _error
->Error(_("Must specify at least one package to check builddeps for"));
1867 // Read the source list
1869 if (List
.ReadMainList() == false)
1870 return _error
->Error(_("The list of sources could not be read."));
1872 // Create the text record parsers
1873 pkgRecords
Recs(Cache
);
1874 pkgSrcRecords
SrcRecs(List
);
1875 if (_error
->PendingError() == true)
1878 // Create the download object
1879 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1880 pkgAcquire
Fetcher(&Stat
);
1883 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1886 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1888 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1890 // Process the build-dependencies
1891 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
1892 if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only",false)) == false)
1893 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
1895 // Also ensure that build-essential packages are present
1896 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
1899 for (; Opts
; Opts
= Opts
->Next
)
1901 if (Opts
->Value
.empty() == true)
1904 pkgSrcRecords::Parser::BuildDepRec rec
;
1905 rec
.Package
= Opts
->Value
;
1906 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
1908 BuildDeps
.insert(BuildDeps
.begin(), rec
);
1911 if (BuildDeps
.size() == 0)
1913 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
1917 // Install the requested packages
1918 unsigned int ExpectedInst
= 0;
1919 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
1920 pkgProblemResolver
Fix(Cache
);
1921 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); D
++)
1923 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
1924 if (Pkg
.end() == true)
1926 /* for a build-conflict; ignore unknown packages */
1927 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1928 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1931 return _error
->Error(_("%s dependency on %s cannot be satisfied because the package %s cannot be found"),
1932 Last
->BuildDepType((*D
).Type
),Src
.c_str(),(*D
).Package
.c_str());
1934 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1936 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1937 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1940 * conflict; need to remove if we have an installed version
1941 * that satisfies the version criterial
1943 if (IV
.end() == false &&
1944 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1945 TryToInstall(Pkg
,Cache
,Fix
,true,false,ExpectedInst
);
1950 * If this is a virtual package, we need to check the list of
1951 * packages that provide it and see if any of those are
1954 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
1955 for (; Prv
.end() != true; Prv
++)
1956 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
1959 if (Prv
.end() == true)
1962 * depends; need to install or upgrade if we don't have the
1963 * package installed or if the version does not satisfy the
1964 * build dep. This is complicated by the fact that if we
1965 * depend on a version lower than what we already have
1966 * installed it is not clear what should be done; in practice
1967 * this case should be rare though and right now nothing
1968 * is done about it :-(
1970 if (IV
.end() == true ||
1971 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == false)
1972 TryToInstall(Pkg
,Cache
,Fix
,false,false,ExpectedInst
);
1977 Fix
.InstallProtect();
1978 if (Fix
.Resolve(true) == false)
1981 // Now we check the state of the packages,
1982 if (Cache
->BrokenCount() != 0)
1983 return _error
->Error(_("Some broken packages were found while trying to process build-dependencies.\n"
1984 "You might want to run `apt-get -f install' to correct these."));
1987 if (InstallPackages(Cache
, false, true) == false)
1988 return _error
->Error(_("Failed to process build dependencies"));
1993 // DoMoo - Never Ask, Never Tell /*{{{*/
1994 // ---------------------------------------------------------------------
1996 bool DoMoo(CommandLine
&CmdL
)
2005 "....\"Have you mooed today?\"...\n";
2010 // ShowHelp - Show a help screen /*{{{*/
2011 // ---------------------------------------------------------------------
2013 bool ShowHelp(CommandLine
&CmdL
)
2015 ioprintf(cout
,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE
,VERSION
,
2016 COMMON_OS
,COMMON_CPU
,__DATE__
,__TIME__
);
2018 if (_config
->FindB("version") == true)
2020 cout
<< _("Supported Modules:") << endl
;
2022 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
2024 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
2025 if (_system
!= 0 && _system
->VS
== VS
)
2029 cout
<< "Ver: " << VS
->Label
<< endl
;
2031 /* Print out all the packaging systems that will work with
2033 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
2035 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
2040 if (Sys
->VS
->TestCompatibility(*VS
) == true)
2041 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
2045 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
2047 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
2048 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
2051 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
2053 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
2054 cout
<< " Idx: " << Type
->Label
<< endl
;
2061 _("Usage: apt-get [options] command\n"
2062 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
2063 " apt-get [options] source pkg1 [pkg2 ...]\n"
2065 "apt-get is a simple command line interface for downloading and\n"
2066 "installing packages. The most frequently used commands are update\n"
2070 " update - Retrieve new lists of packages\n"
2071 " upgrade - Perform an upgrade\n"
2072 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
2073 " remove - Remove packages\n"
2074 " source - Download source archives\n"
2075 " build-dep - Configure build-dependencies for source packages\n"
2076 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
2077 " dselect-upgrade - Follow dselect selections\n"
2078 " clean - Erase downloaded archive files\n"
2079 " autoclean - Erase old downloaded archive files\n"
2080 " check - Verify that there are no broken dependencies\n"
2083 " -h This help text.\n"
2084 " -q Loggable output - no progress indicator\n"
2085 " -qq No output except for errors\n"
2086 " -d Download only - do NOT install or unpack archives\n"
2087 " -s No-act. Perform ordering simulation\n"
2088 " -y Assume Yes to all queries and do not prompt\n"
2089 " -f Attempt to continue if the integrity check fails\n"
2090 " -m Attempt to continue if archives are unlocatable\n"
2091 " -u Show a list of upgraded packages as well\n"
2092 " -b Build the source package after fetching it\n"
2093 " -c=? Read this configuration file\n"
2094 " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n"
2095 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
2096 "pages for more information and options.\n"
2097 " This APT has Super Cow Powers.\n");
2101 // GetInitialize - Initialize things for apt-get /*{{{*/
2102 // ---------------------------------------------------------------------
2104 void GetInitialize()
2106 _config
->Set("quiet",0);
2107 _config
->Set("help",false);
2108 _config
->Set("APT::Get::Download-Only",false);
2109 _config
->Set("APT::Get::Simulate",false);
2110 _config
->Set("APT::Get::Assume-Yes",false);
2111 _config
->Set("APT::Get::Fix-Broken",false);
2112 _config
->Set("APT::Get::Force-Yes",false);
2113 _config
->Set("APT::Get::APT::Get::No-List-Cleanup",true);
2116 // SigWinch - Window size change signal handler /*{{{*/
2117 // ---------------------------------------------------------------------
2121 // Riped from GNU ls
2125 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
2126 ScreenWidth
= ws
.ws_col
- 1;
2131 int main(int argc
,const char *argv
[])
2133 CommandLine::Args Args
[] = {
2134 {'h',"help","help",0},
2135 {'v',"version","version",0},
2136 {'q',"quiet","quiet",CommandLine::IntLevel
},
2137 {'q',"silent","quiet",CommandLine::IntLevel
},
2138 {'d',"download-only","APT::Get::Download-Only",0},
2139 {'b',"compile","APT::Get::Compile",0},
2140 {'b',"build","APT::Get::Compile",0},
2141 {'s',"simulate","APT::Get::Simulate",0},
2142 {'s',"just-print","APT::Get::Simulate",0},
2143 {'s',"recon","APT::Get::Simulate",0},
2144 {'s',"dry-run","APT::Get::Simulate",0},
2145 {'s',"no-act","APT::Get::Simulate",0},
2146 {'y',"yes","APT::Get::Assume-Yes",0},
2147 {'y',"assume-yes","APT::Get::Assume-Yes",0},
2148 {'f',"fix-broken","APT::Get::Fix-Broken",0},
2149 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
2150 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
2151 {'t',"target-release","APT::Default-Release",CommandLine::HasArg
},
2152 {'t',"default-release","APT::Default-Release",CommandLine::HasArg
},
2153 {0,"download","APT::Get::Download",0},
2154 {0,"fix-missing","APT::Get::Fix-Missing",0},
2155 {0,"ignore-hold","APT::Ignore-Hold",0},
2156 {0,"upgrade","APT::Get::upgrade",0},
2157 {0,"force-yes","APT::Get::force-yes",0},
2158 {0,"print-uris","APT::Get::Print-URIs",0},
2159 {0,"diff-only","APT::Get::Diff-Only",0},
2160 {0,"tar-only","APT::Get::tar-Only",0},
2161 {0,"purge","APT::Get::Purge",0},
2162 {0,"list-cleanup","APT::Get::List-Cleanup",0},
2163 {0,"reinstall","APT::Get::ReInstall",0},
2164 {0,"trivial-only","APT::Get::Trivial-Only",0},
2165 {0,"remove","APT::Get::Remove",0},
2166 {0,"only-source","APT::Get::Only-Source",0},
2167 {0,"arch-only","APT::Get::Arch-Only",0},
2168 {'c',"config-file",0,CommandLine::ConfigFile
},
2169 {'o',"option",0,CommandLine::ArbItem
},
2171 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
2172 {"upgrade",&DoUpgrade
},
2173 {"install",&DoInstall
},
2174 {"remove",&DoInstall
},
2175 {"dist-upgrade",&DoDistUpgrade
},
2176 {"dselect-upgrade",&DoDSelectUpgrade
},
2177 {"build-dep",&DoBuildDep
},
2179 {"autoclean",&DoAutoClean
},
2181 {"source",&DoSource
},
2186 // Set up gettext support
2187 setlocale(LC_ALL
,"");
2188 textdomain(PACKAGE
);
2190 // Parse the command line and initialize the package library
2191 CommandLine
CmdL(Args
,_config
);
2192 if (pkgInitConfig(*_config
) == false ||
2193 CmdL
.Parse(argc
,argv
) == false ||
2194 pkgInitSystem(*_config
,_system
) == false)
2196 if (_config
->FindB("version") == true)
2199 _error
->DumpErrors();
2203 // See if the help should be shown
2204 if (_config
->FindB("help") == true ||
2205 _config
->FindB("version") == true ||
2206 CmdL
.FileSize() == 0)
2212 // Deal with stdout not being a tty
2213 if (ttyname(STDOUT_FILENO
) == 0 && _config
->FindI("quiet",0) < 1)
2214 _config
->Set("quiet","1");
2216 // Setup the output streams
2217 c0out
.rdbuf(cout
.rdbuf());
2218 c1out
.rdbuf(cout
.rdbuf());
2219 c2out
.rdbuf(cout
.rdbuf());
2220 if (_config
->FindI("quiet",0) > 0)
2221 c0out
.rdbuf(devnull
.rdbuf());
2222 if (_config
->FindI("quiet",0) > 1)
2223 c1out
.rdbuf(devnull
.rdbuf());
2225 // Setup the signals
2226 signal(SIGPIPE
,SIG_IGN
);
2227 signal(SIGWINCH
,SigWinch
);
2230 // Match the operation
2231 CmdL
.DispatchArg(Cmds
);
2233 // Print any errors or warnings found during parsing
2234 if (_error
->empty() == false)
2236 bool Errors
= _error
->PendingError();
2237 _error
->DumpErrors();
2238 return Errors
== true?100:0;