]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.120 2002/04/27 04:28:04 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
== '*' || *I
== '|')
1346 return _error
->Error(_("Couldn't find package %s"),S
);
1348 // Regexs must always be confirmed
1349 ExpectedInst
+= 1000;
1351 // Compile the regex pattern
1354 if ((Res
= regcomp(&Pattern
,S
,REG_EXTENDED
| REG_ICASE
|
1358 regerror(Res
,&Pattern
,Error
,sizeof(Error
));
1359 return _error
->Error(_("Regex compilation error - %s"),Error
);
1362 // Run over the matches
1364 for (Pkg
= Cache
->PkgBegin(); Pkg
.end() == false; Pkg
++)
1366 if (regexec(&Pattern
,Pkg
.Name(),0,0,0) != 0)
1370 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1373 Hit
|= TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,
1374 ExpectedInst
,false);
1379 return _error
->Error(_("Couldn't find package %s"),S
);
1384 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1386 if (TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,ExpectedInst
) == false)
1391 /* If we are in the Broken fixing mode we do not attempt to fix the
1392 problems. This is if the user invoked install without -f and gave
1394 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1396 c1out
<< _("You might want to run `apt-get -f install' to correct these:") << endl
;
1397 ShowBroken(c1out
,Cache
,false);
1399 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1402 // Call the scored problem resolver
1403 Fix
.InstallProtect();
1404 if (Fix
.Resolve(true) == false)
1407 // Now we check the state of the packages,
1408 if (Cache
->BrokenCount() != 0)
1411 _("Some packages could not be installed. This may mean that you have\n"
1412 "requested an impossible situation or if you are using the unstable\n"
1413 "distribution that some required packages have not yet been created\n"
1414 "or been moved out of Incoming.") << endl
;
1419 _("Since you only requested a single operation it is extremely likely that\n"
1420 "the package is simply not installable and a bug report against\n"
1421 "that package should be filed.") << endl
;
1424 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1426 ShowBroken(c1out
,Cache
,false);
1427 return _error
->Error(_("Sorry, broken packages"));
1430 /* Print out a list of packages that are going to be installed extra
1431 to what the user asked */
1432 if (Cache
->InstCount() != ExpectedInst
)
1435 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1437 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1438 if ((*Cache
)[I
].Install() == false)
1442 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1443 if (strcmp(*J
,I
.Name()) == 0)
1447 List
+= string(I
.Name()) + " ";
1450 ShowList(c1out
,_("The following extra packages will be installed:"),List
);
1453 // See if we need to prompt
1454 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
1455 return InstallPackages(Cache
,false,false);
1457 return InstallPackages(Cache
,false);
1460 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1461 // ---------------------------------------------------------------------
1462 /* Intelligent upgrader that will install and remove packages at will */
1463 bool DoDistUpgrade(CommandLine
&CmdL
)
1466 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1469 c0out
<< _("Calculating Upgrade... ") << flush
;
1470 if (pkgDistUpgrade(*Cache
) == false)
1472 c0out
<< _("Failed") << endl
;
1473 ShowBroken(c1out
,Cache
,false);
1477 c0out
<< _("Done") << endl
;
1479 return InstallPackages(Cache
,true);
1482 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1483 // ---------------------------------------------------------------------
1484 /* Follows dselect's selections */
1485 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1488 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1491 // Install everything with the install flag set
1492 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1493 for (;I
.end() != true; I
++)
1495 /* Install the package only if it is a new install, the autoupgrader
1496 will deal with the rest */
1497 if (I
->SelectedState
== pkgCache::State::Install
)
1498 Cache
->MarkInstall(I
,false);
1501 /* Now install their deps too, if we do this above then order of
1502 the status file is significant for | groups */
1503 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1505 /* Install the package only if it is a new install, the autoupgrader
1506 will deal with the rest */
1507 if (I
->SelectedState
== pkgCache::State::Install
)
1508 Cache
->MarkInstall(I
,true);
1511 // Apply erasures now, they override everything else.
1512 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1515 if (I
->SelectedState
== pkgCache::State::DeInstall
||
1516 I
->SelectedState
== pkgCache::State::Purge
)
1517 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
1520 /* Resolve any problems that dselect created, allupgrade cannot handle
1521 such things. We do so quite agressively too.. */
1522 if (Cache
->BrokenCount() != 0)
1524 pkgProblemResolver
Fix(Cache
);
1526 // Hold back held packages.
1527 if (_config
->FindB("APT::Ignore-Hold",false) == false)
1529 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
1531 if (I
->SelectedState
== pkgCache::State::Hold
)
1539 if (Fix
.Resolve() == false)
1541 ShowBroken(c1out
,Cache
,false);
1542 return _error
->Error("Internal Error, problem resolver broke stuff");
1546 // Now upgrade everything
1547 if (pkgAllUpgrade(Cache
) == false)
1549 ShowBroken(c1out
,Cache
,false);
1550 return _error
->Error("Internal Error, problem resolver broke stuff");
1553 return InstallPackages(Cache
,false);
1556 // DoClean - Remove download archives /*{{{*/
1557 // ---------------------------------------------------------------------
1559 bool DoClean(CommandLine
&CmdL
)
1561 if (_config
->FindB("APT::Get::Simulate") == true)
1563 cout
<< "Del " << _config
->FindDir("Dir::Cache::archives") << "* " <<
1564 _config
->FindDir("Dir::Cache::archives") << "partial/*" << endl
;
1568 // Lock the archive directory
1570 if (_config
->FindB("Debug::NoLocking",false) == false)
1572 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1573 if (_error
->PendingError() == true)
1574 return _error
->Error(_("Unable to lock the download directory"));
1578 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
1579 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
1583 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
1584 // ---------------------------------------------------------------------
1585 /* This is similar to clean but it only purges things that cannot be
1586 downloaded, that is old versions of cached packages. */
1587 class LogCleaner
: public pkgArchiveCleaner
1590 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1592 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
1594 if (_config
->FindB("APT::Get::Simulate") == false)
1599 bool DoAutoClean(CommandLine
&CmdL
)
1601 // Lock the archive directory
1603 if (_config
->FindB("Debug::NoLocking",false) == false)
1605 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1606 if (_error
->PendingError() == true)
1607 return _error
->Error(_("Unable to lock the download directory"));
1611 if (Cache
.Open() == false)
1616 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1617 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1620 // DoCheck - Perform the check operation /*{{{*/
1621 // ---------------------------------------------------------------------
1622 /* Opening automatically checks the system, this command is mostly used
1624 bool DoCheck(CommandLine
&CmdL
)
1633 // DoSource - Fetch a source archive /*{{{*/
1634 // ---------------------------------------------------------------------
1635 /* Fetch souce packages */
1643 bool DoSource(CommandLine
&CmdL
)
1646 if (Cache
.Open(false) == false)
1649 if (CmdL
.FileSize() <= 1)
1650 return _error
->Error(_("Must specify at least one package to fetch source for"));
1652 // Read the source list
1654 if (List
.ReadMainList() == false)
1655 return _error
->Error(_("The list of sources could not be read."));
1657 // Create the text record parsers
1658 pkgRecords
Recs(Cache
);
1659 pkgSrcRecords
SrcRecs(List
);
1660 if (_error
->PendingError() == true)
1663 // Create the download object
1664 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1665 pkgAcquire
Fetcher(&Stat
);
1667 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
1669 // Load the requestd sources into the fetcher
1671 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1674 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1677 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1680 vector
<pkgSrcRecords::File
> Lst
;
1681 if (Last
->Files(Lst
) == false)
1684 // Load them into the fetcher
1685 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
1686 I
!= Lst
.end(); I
++)
1688 // Try to guess what sort of file it is we are getting.
1689 if (I
->Type
== "dsc")
1691 Dsc
[J
].Package
= Last
->Package();
1692 Dsc
[J
].Version
= Last
->Version();
1693 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
1696 // Diff only mode only fetches .diff files
1697 if (_config
->FindB("APT::Get::Diff-Only",false) == true &&
1701 // Tar only mode only fetches .tar files
1702 if (_config
->FindB("APT::Get::Tar-Only",false) == true &&
1706 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
1708 Last
->Index().SourceInfo(*Last
,*I
),Src
);
1712 // Display statistics
1713 double FetchBytes
= Fetcher
.FetchNeeded();
1714 double FetchPBytes
= Fetcher
.PartialPresent();
1715 double DebBytes
= Fetcher
.TotalNeeded();
1717 // Check for enough free space
1719 string OutputDir
= ".";
1720 if (statvfs(OutputDir
.c_str(),&Buf
) != 0)
1721 return _error
->Errno("statvfs","Couldn't determine free space in %s",
1723 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1724 return _error
->Error(_("Sorry, you don't have enough free space in %s"),
1728 if (DebBytes
!= FetchBytes
)
1729 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
1730 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
1732 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
1733 SizeToStr(DebBytes
).c_str());
1735 if (_config
->FindB("APT::Get::Simulate",false) == true)
1737 for (unsigned I
= 0; I
!= J
; I
++)
1738 ioprintf(cout
,_("Fetch Source %s\n"),Dsc
[I
].Package
.c_str());
1742 // Just print out the uris an exit if the --print-uris flag was used
1743 if (_config
->FindB("APT::Get::Print-URIs") == true)
1745 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1746 for (; I
!= Fetcher
.UriEnd(); I
++)
1747 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1748 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1753 if (Fetcher
.Run() == pkgAcquire::Failed
)
1756 // Print error messages
1757 bool Failed
= false;
1758 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1760 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1761 (*I
)->Complete
== true)
1764 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1765 (*I
)->ErrorText
.c_str());
1769 return _error
->Error(_("Failed to fetch some archives."));
1771 if (_config
->FindB("APT::Get::Download-only",false) == true)
1773 c1out
<< _("Download complete and in download only mode") << endl
;
1777 // Unpack the sources
1778 pid_t Process
= ExecFork();
1782 for (unsigned I
= 0; I
!= J
; I
++)
1784 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
1786 // Diff only mode only fetches .diff files
1787 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
1788 _config
->FindB("APT::Get::Tar-Only",false) == true ||
1789 Dsc
[I
].Dsc
.empty() == true)
1792 // See if the package is already unpacked
1794 if (stat(Dir
.c_str(),&Stat
) == 0 &&
1795 S_ISDIR(Stat
.st_mode
) != 0)
1797 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
1804 snprintf(S
,sizeof(S
),"%s -x %s",
1805 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
1806 Dsc
[I
].Dsc
.c_str());
1809 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
1814 // Try to compile it with dpkg-buildpackage
1815 if (_config
->FindB("APT::Get::Compile",false) == true)
1817 // Call dpkg-buildpackage
1819 snprintf(S
,sizeof(S
),"cd %s && %s %s",
1821 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
1822 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
1826 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
1835 // Wait for the subprocess
1837 while (waitpid(Process
,&Status
,0) != Process
)
1841 return _error
->Errno("waitpid","Couldn't wait for subprocess");
1844 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
1845 return _error
->Error(_("Child process failed"));
1850 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
1851 // ---------------------------------------------------------------------
1852 /* This function will look at the build depends list of the given source
1853 package and install the necessary packages to make it true, or fail. */
1854 bool DoBuildDep(CommandLine
&CmdL
)
1857 if (Cache
.Open(true) == false)
1860 if (CmdL
.FileSize() <= 1)
1861 return _error
->Error(_("Must specify at least one package to check builddeps for"));
1863 // Read the source list
1865 if (List
.ReadMainList() == false)
1866 return _error
->Error(_("The list of sources could not be read."));
1868 // Create the text record parsers
1869 pkgRecords
Recs(Cache
);
1870 pkgSrcRecords
SrcRecs(List
);
1871 if (_error
->PendingError() == true)
1874 // Create the download object
1875 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1876 pkgAcquire
Fetcher(&Stat
);
1879 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1882 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1884 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1886 // Process the build-dependencies
1887 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
1888 if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only",false)) == false)
1889 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
1891 // Also ensure that build-essential packages are present
1892 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
1895 for (; Opts
; Opts
= Opts
->Next
)
1897 if (Opts
->Value
.empty() == true)
1900 pkgSrcRecords::Parser::BuildDepRec rec
;
1901 rec
.Package
= Opts
->Value
;
1902 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
1904 BuildDeps
.insert(BuildDeps
.begin(), rec
);
1907 if (BuildDeps
.size() == 0)
1909 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
1913 // Install the requested packages
1914 unsigned int ExpectedInst
= 0;
1915 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
1916 pkgProblemResolver
Fix(Cache
);
1917 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); D
++)
1919 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
1920 if (Pkg
.end() == true)
1922 /* for a build-conflict; ignore unknown packages */
1923 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1924 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1927 return _error
->Error(_("%s dependency on %s cannot be satisfied because the package %s cannot be found"),
1928 Last
->BuildDepType((*D
).Type
),Src
.c_str(),(*D
).Package
.c_str());
1930 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1932 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1933 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1936 * conflict; need to remove if we have an installed version
1937 * that satisfies the version criterial
1939 if (IV
.end() == false &&
1940 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1941 TryToInstall(Pkg
,Cache
,Fix
,true,false,ExpectedInst
);
1946 * If this is a virtual package, we need to check the list of
1947 * packages that provide it and see if any of those are
1950 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
1951 for (; Prv
.end() != true; Prv
++)
1952 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
1955 if (Prv
.end() == true)
1958 * depends; need to install or upgrade if we don't have the
1959 * package installed or if the version does not satisfy the
1960 * build dep. This is complicated by the fact that if we
1961 * depend on a version lower than what we already have
1962 * installed it is not clear what should be done; in practice
1963 * this case should be rare though and right now nothing
1964 * is done about it :-(
1966 if (IV
.end() == true ||
1967 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == false)
1968 TryToInstall(Pkg
,Cache
,Fix
,false,false,ExpectedInst
);
1973 Fix
.InstallProtect();
1974 if (Fix
.Resolve(true) == false)
1977 // Now we check the state of the packages,
1978 if (Cache
->BrokenCount() != 0)
1979 return _error
->Error(_("Some broken packages were found while trying to process build-dependencies.\n"
1980 "You might want to run `apt-get -f install' to correct these."));
1983 if (InstallPackages(Cache
, false, true) == false)
1984 return _error
->Error(_("Failed to process build dependencies"));
1989 // DoMoo - Never Ask, Never Tell /*{{{*/
1990 // ---------------------------------------------------------------------
1992 bool DoMoo(CommandLine
&CmdL
)
2001 "....\"Have you mooed today?\"...\n";
2006 // ShowHelp - Show a help screen /*{{{*/
2007 // ---------------------------------------------------------------------
2009 bool ShowHelp(CommandLine
&CmdL
)
2011 ioprintf(cout
,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE
,VERSION
,
2012 COMMON_OS
,COMMON_CPU
,__DATE__
,__TIME__
);
2014 if (_config
->FindB("version") == true)
2016 cout
<< _("Supported Modules:") << endl
;
2018 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
2020 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
2021 if (_system
!= 0 && _system
->VS
== VS
)
2025 cout
<< "Ver: " << VS
->Label
<< endl
;
2027 /* Print out all the packaging systems that will work with
2029 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
2031 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
2036 if (Sys
->VS
->TestCompatibility(*VS
) == true)
2037 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
2041 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
2043 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
2044 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
2047 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
2049 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
2050 cout
<< " Idx: " << Type
->Label
<< endl
;
2057 _("Usage: apt-get [options] command\n"
2058 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
2059 " apt-get [options] source pkg1 [pkg2 ...]\n"
2061 "apt-get is a simple command line interface for downloading and\n"
2062 "installing packages. The most frequently used commands are update\n"
2066 " update - Retrieve new lists of packages\n"
2067 " upgrade - Perform an upgrade\n"
2068 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
2069 " remove - Remove packages\n"
2070 " source - Download source archives\n"
2071 " build-dep - Configure build-dependencies for source packages\n"
2072 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
2073 " dselect-upgrade - Follow dselect selections\n"
2074 " clean - Erase downloaded archive files\n"
2075 " autoclean - Erase old downloaded archive files\n"
2076 " check - Verify that there are no broken dependencies\n"
2079 " -h This help text.\n"
2080 " -q Loggable output - no progress indicator\n"
2081 " -qq No output except for errors\n"
2082 " -d Download only - do NOT install or unpack archives\n"
2083 " -s No-act. Perform ordering simulation\n"
2084 " -y Assume Yes to all queries and do not prompt\n"
2085 " -f Attempt to continue if the integrity check fails\n"
2086 " -m Attempt to continue if archives are unlocatable\n"
2087 " -u Show a list of upgraded packages as well\n"
2088 " -b Build the source package after fetching it\n"
2089 " -c=? Read this configuration file\n"
2090 " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n"
2091 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
2092 "pages for more information and options.\n"
2093 " This APT has Super Cow Powers.\n");
2097 // GetInitialize - Initialize things for apt-get /*{{{*/
2098 // ---------------------------------------------------------------------
2100 void GetInitialize()
2102 _config
->Set("quiet",0);
2103 _config
->Set("help",false);
2104 _config
->Set("APT::Get::Download-Only",false);
2105 _config
->Set("APT::Get::Simulate",false);
2106 _config
->Set("APT::Get::Assume-Yes",false);
2107 _config
->Set("APT::Get::Fix-Broken",false);
2108 _config
->Set("APT::Get::Force-Yes",false);
2109 _config
->Set("APT::Get::APT::Get::No-List-Cleanup",true);
2112 // SigWinch - Window size change signal handler /*{{{*/
2113 // ---------------------------------------------------------------------
2117 // Riped from GNU ls
2121 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
2122 ScreenWidth
= ws
.ws_col
- 1;
2127 int main(int argc
,const char *argv
[])
2129 CommandLine::Args Args
[] = {
2130 {'h',"help","help",0},
2131 {'v',"version","version",0},
2132 {'q',"quiet","quiet",CommandLine::IntLevel
},
2133 {'q',"silent","quiet",CommandLine::IntLevel
},
2134 {'d',"download-only","APT::Get::Download-Only",0},
2135 {'b',"compile","APT::Get::Compile",0},
2136 {'b',"build","APT::Get::Compile",0},
2137 {'s',"simulate","APT::Get::Simulate",0},
2138 {'s',"just-print","APT::Get::Simulate",0},
2139 {'s',"recon","APT::Get::Simulate",0},
2140 {'s',"dry-run","APT::Get::Simulate",0},
2141 {'s',"no-act","APT::Get::Simulate",0},
2142 {'y',"yes","APT::Get::Assume-Yes",0},
2143 {'y',"assume-yes","APT::Get::Assume-Yes",0},
2144 {'f',"fix-broken","APT::Get::Fix-Broken",0},
2145 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
2146 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
2147 {'t',"target-release","APT::Default-Release",CommandLine::HasArg
},
2148 {'t',"default-release","APT::Default-Release",CommandLine::HasArg
},
2149 {0,"download","APT::Get::Download",0},
2150 {0,"fix-missing","APT::Get::Fix-Missing",0},
2151 {0,"ignore-hold","APT::Ignore-Hold",0},
2152 {0,"upgrade","APT::Get::upgrade",0},
2153 {0,"force-yes","APT::Get::force-yes",0},
2154 {0,"print-uris","APT::Get::Print-URIs",0},
2155 {0,"diff-only","APT::Get::Diff-Only",0},
2156 {0,"tar-only","APT::Get::tar-Only",0},
2157 {0,"purge","APT::Get::Purge",0},
2158 {0,"list-cleanup","APT::Get::List-Cleanup",0},
2159 {0,"reinstall","APT::Get::ReInstall",0},
2160 {0,"trivial-only","APT::Get::Trivial-Only",0},
2161 {0,"remove","APT::Get::Remove",0},
2162 {0,"only-source","APT::Get::Only-Source",0},
2163 {0,"arch-only","APT::Get::Arch-Only",0},
2164 {'c',"config-file",0,CommandLine::ConfigFile
},
2165 {'o',"option",0,CommandLine::ArbItem
},
2167 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
2168 {"upgrade",&DoUpgrade
},
2169 {"install",&DoInstall
},
2170 {"remove",&DoInstall
},
2171 {"dist-upgrade",&DoDistUpgrade
},
2172 {"dselect-upgrade",&DoDSelectUpgrade
},
2173 {"build-dep",&DoBuildDep
},
2175 {"autoclean",&DoAutoClean
},
2177 {"source",&DoSource
},
2182 // Set up gettext support
2183 setlocale(LC_ALL
,"");
2184 textdomain(PACKAGE
);
2186 // Parse the command line and initialize the package library
2187 CommandLine
CmdL(Args
,_config
);
2188 if (pkgInitConfig(*_config
) == false ||
2189 CmdL
.Parse(argc
,argv
) == false ||
2190 pkgInitSystem(*_config
,_system
) == false)
2192 if (_config
->FindB("version") == true)
2195 _error
->DumpErrors();
2199 // See if the help should be shown
2200 if (_config
->FindB("help") == true ||
2201 _config
->FindB("version") == true ||
2202 CmdL
.FileSize() == 0)
2208 // Deal with stdout not being a tty
2209 if (ttyname(STDOUT_FILENO
) == 0 && _config
->FindI("quiet",0) < 1)
2210 _config
->Set("quiet","1");
2212 // Setup the output streams
2213 c0out
.rdbuf(cout
.rdbuf());
2214 c1out
.rdbuf(cout
.rdbuf());
2215 c2out
.rdbuf(cout
.rdbuf());
2216 if (_config
->FindI("quiet",0) > 0)
2217 c0out
.rdbuf(devnull
.rdbuf());
2218 if (_config
->FindI("quiet",0) > 1)
2219 c1out
.rdbuf(devnull
.rdbuf());
2221 // Setup the signals
2222 signal(SIGPIPE
,SIG_IGN
);
2223 signal(SIGWINCH
,SigWinch
);
2226 // Match the operation
2227 CmdL
.DispatchArg(Cmds
);
2229 // Print any errors or warnings found during parsing
2230 if (_error
->empty() == false)
2232 bool Errors
= _error
->PendingError();
2233 _error
->DumpErrors();
2234 return Errors
== true?100:0;