]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.107 2001/05/27 04:45:49 jgg Exp $
4 /* ######################################################################
6 apt-get - Cover for dpkg
8 This is an allout cover for dpkg implementing a safer front end. It is
9 based largely on libapt-pkg.
11 The syntax is different,
12 apt-get [opt] command [things]
14 update - Resyncronize the package files from their sources
15 upgrade - Smart-Download the newest versions of all packages
16 dselect-upgrade - Follows dselect's changes to the Status: field
17 and installes new and removes old packages
18 dist-upgrade - Powerfull upgrader designed to handle the issues with
20 install - Download and install a given package (by name, not by .deb)
21 check - Update the package cache and check for broken packages
22 clean - Erase the .debs downloaded to /var/cache/apt/archives and
25 ##################################################################### */
27 // Include Files /*{{{*/
28 #include <apt-pkg/error.h>
29 #include <apt-pkg/cmndline.h>
30 #include <apt-pkg/init.h>
31 #include <apt-pkg/depcache.h>
32 #include <apt-pkg/sourcelist.h>
33 #include <apt-pkg/algorithms.h>
34 #include <apt-pkg/acquire-item.h>
35 #include <apt-pkg/strutl.h>
36 #include <apt-pkg/clean.h>
37 #include <apt-pkg/srcrecords.h>
38 #include <apt-pkg/version.h>
39 #include <apt-pkg/cachefile.h>
40 #include <apt-pkg/sptr.h>
41 #include <apt-pkg/versionmatch.h>
46 #include "acqprogress.h"
50 #include <sys/ioctl.h>
52 #include <sys/statvfs.h>
66 ofstream
devnull("/dev/null");
67 unsigned int ScreenWidth
= 80;
69 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
70 // ---------------------------------------------------------------------
72 class CacheFile
: public pkgCacheFile
74 static pkgCache
*SortCache
;
75 static int NameComp(const void *a
,const void *b
);
78 pkgCache::Package
**List
;
81 bool CheckDeps(bool AllowBroken
= false);
82 bool Open(bool WithLock
= true)
84 OpTextProgress
Prog(*_config
);
85 if (pkgCacheFile::Open(Prog
,WithLock
) == false)
91 CacheFile() : List(0) {};
95 // YnPrompt - Yes No Prompt. /*{{{*/
96 // ---------------------------------------------------------------------
97 /* Returns true on a Yes.*/
100 // This needs to be a capital
101 const char *Yes
= _("Y");
103 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
105 c1out
<< Yes
<< endl
;
111 if (read(STDIN_FILENO
,&C
,1) != 1)
113 while (C
!= '\n' && Jnk
!= '\n')
114 if (read(STDIN_FILENO
,&Jnk
,1) != 1)
117 if (!(toupper(C
) == *Yes
|| C
== '\n' || C
== '\r'))
122 // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
123 // ---------------------------------------------------------------------
124 /* Returns true on a Yes.*/
125 bool AnalPrompt(const char *Text
)
128 cin
.getline(Buf
,sizeof(Buf
));
129 if (strcmp(Buf
,Text
) == 0)
134 // ShowList - Show a list /*{{{*/
135 // ---------------------------------------------------------------------
136 /* This prints out a string of space separated words with a title and
137 a two space indent line wraped to the current screen width. */
138 bool ShowList(ostream
&out
,string Title
,string List
)
140 if (List
.empty() == true)
143 // Acount for the leading space
144 int ScreenWidth
= ::ScreenWidth
- 3;
146 out
<< Title
<< endl
;
147 string::size_type Start
= 0;
148 while (Start
< List
.size())
150 string::size_type End
;
151 if (Start
+ ScreenWidth
>= List
.size())
154 End
= List
.rfind(' ',Start
+ScreenWidth
);
156 if (End
== string::npos
|| End
< Start
)
157 End
= Start
+ ScreenWidth
;
158 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
164 // ShowBroken - Debugging aide /*{{{*/
165 // ---------------------------------------------------------------------
166 /* This prints out the names of all the packages that are broken along
167 with the name of each each broken dependency and a quite version
170 The output looks like:
171 Sorry, but the following packages have unmet dependencies:
172 exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed
173 Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
174 Depends: libsasl7 but it is not going to be installed
176 void ShowBroken(ostream
&out
,CacheFile
&Cache
,bool Now
)
178 out
<< _("Sorry, but the following packages have unmet dependencies:") << endl
;
179 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
181 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
183 if (Cache
[I
].InstBroken() == false)
186 // Print out each package and the failed dependencies
187 out
<<" " << I
.Name() << ":";
188 unsigned Indent
= strlen(I
.Name()) + 3;
190 if (Cache
[I
].InstVerIter(Cache
).end() == true)
196 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
198 // Compute a single dependency element (glob or)
199 pkgCache::DepIterator Start
;
200 pkgCache::DepIterator End
;
203 if (Cache
->IsImportantDep(End
) == false ||
204 (Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
211 for (unsigned J
= 0; J
!= Indent
; J
++)
215 if (FirstOr
== false)
217 for (unsigned J
= 0; J
!= strlen(End
.DepType()) + 3; J
++)
221 out
<< ' ' << End
.DepType() << ": ";
224 out
<< Start
.TargetPkg().Name();
226 // Show a quick summary of the version requirements
227 if (Start
.TargetVer() != 0)
228 out
<< " (" << Start
.CompType() << " " << Start
.TargetVer() << ")";
230 /* Show a summary of the target package if possible. In the case
231 of virtual packages we show nothing */
232 pkgCache::PkgIterator Targ
= Start
.TargetPkg();
233 if (Targ
->ProvidesList
== 0)
236 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
238 Ver
= Targ
.CurrentVer();
240 if (Ver
.end() == false)
243 ioprintf(out
,_("but %s is installed"),Ver
.VerStr());
245 ioprintf(out
,_("but %s is to be installed"),Ver
.VerStr());
249 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
251 if (Targ
->ProvidesList
== 0)
252 out
<< _("but it is not installable");
254 out
<< _("but it is a virtual package");
257 out
<< (Now
?_("but it is not installed"):_("but it is not going to be installed"));
273 // ShowNew - Show packages to newly install /*{{{*/
274 // ---------------------------------------------------------------------
276 void ShowNew(ostream
&out
,CacheFile
&Cache
)
278 /* Print out a list of packages that are going to be removed extra
279 to what the user asked */
281 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
283 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
284 if (Cache
[I
].NewInstall() == true)
285 List
+= string(I
.Name()) + " ";
288 ShowList(out
,_("The following NEW packages will be installed:"),List
);
291 // ShowDel - Show packages to delete /*{{{*/
292 // ---------------------------------------------------------------------
294 void ShowDel(ostream
&out
,CacheFile
&Cache
)
296 /* Print out a list of packages that are going to be removed extra
297 to what the user asked */
299 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
301 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
302 if (Cache
[I
].Delete() == true)
304 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
305 List
+= string(I
.Name()) + "* ";
307 List
+= string(I
.Name()) + " ";
311 ShowList(out
,_("The following packages will be REMOVED:"),List
);
314 // ShowKept - Show kept packages /*{{{*/
315 // ---------------------------------------------------------------------
317 void ShowKept(ostream
&out
,CacheFile
&Cache
)
320 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
322 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
325 if (Cache
[I
].Upgrade() == true || Cache
[I
].Upgradable() == false ||
326 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
329 List
+= string(I
.Name()) + " ";
331 ShowList(out
,_("The following packages have been kept back"),List
);
334 // ShowUpgraded - Show upgraded packages /*{{{*/
335 // ---------------------------------------------------------------------
337 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
340 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
342 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
345 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
348 List
+= string(I
.Name()) + " ";
350 ShowList(out
,_("The following packages will be upgraded"),List
);
353 // ShowDowngraded - Show downgraded packages /*{{{*/
354 // ---------------------------------------------------------------------
356 bool ShowDowngraded(ostream
&out
,CacheFile
&Cache
)
359 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
361 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
364 if (Cache
[I
].Downgrade() == false || Cache
[I
].NewInstall() == true)
367 List
+= string(I
.Name()) + " ";
369 return ShowList(out
,_("The following packages will be DOWNGRADED"),List
);
372 // ShowHold - Show held but changed packages /*{{{*/
373 // ---------------------------------------------------------------------
375 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
378 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
380 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
381 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
382 I
->SelectedState
== pkgCache::State::Hold
)
383 List
+= string(I
.Name()) + " ";
386 return ShowList(out
,_("The following held packages will be changed:"),List
);
389 // ShowEssential - Show an essential package warning /*{{{*/
390 // ---------------------------------------------------------------------
391 /* This prints out a warning message that is not to be ignored. It shows
392 all essential packages and their dependents that are to be removed.
393 It is insanely risky to remove the dependents of an essential package! */
394 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
397 bool *Added
= new bool[Cache
->Head().PackageCount
];
398 for (unsigned int I
= 0; I
!= Cache
->Head().PackageCount
; I
++)
401 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
403 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
404 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
&&
405 (I
->Flags
& pkgCache::Flag::Important
) != pkgCache::Flag::Important
)
408 // The essential package is being removed
409 if (Cache
[I
].Delete() == true)
411 if (Added
[I
->ID
] == false)
414 List
+= string(I
.Name()) + " ";
418 if (I
->CurrentVer
== 0)
421 // Print out any essential package depenendents that are to be removed
422 for (pkgCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
424 // Skip everything but depends
425 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
426 D
->Type
!= pkgCache::Dep::Depends
)
429 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
430 if (Cache
[P
].Delete() == true)
432 if (Added
[P
->ID
] == true)
437 snprintf(S
,sizeof(S
),_("%s (due to %s) "),P
.Name(),I
.Name());
444 return ShowList(out
,_("WARNING: The following essential packages will be removed\n"
445 "This should NOT be done unless you know exactly what you are doing!"),List
);
448 // Stats - Show some statistics /*{{{*/
449 // ---------------------------------------------------------------------
451 void Stats(ostream
&out
,pkgDepCache
&Dep
)
453 unsigned long Upgrade
= 0;
454 unsigned long Downgrade
= 0;
455 unsigned long Install
= 0;
456 unsigned long ReInstall
= 0;
457 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
459 if (Dep
[I
].NewInstall() == true)
463 if (Dep
[I
].Upgrade() == true)
466 if (Dep
[I
].Downgrade() == true)
470 if (Dep
[I
].Delete() == false && (Dep
[I
].iFlags
& pkgDepCache::ReInstall
) == pkgDepCache::ReInstall
)
474 ioprintf(out
,_("%lu packages upgraded, %lu newly installed, "),
478 ioprintf(out
,_("%lu reinstalled, "),ReInstall
);
480 ioprintf(out
,_("%lu downgraded, "),Downgrade
);
482 ioprintf(out
,_("%lu to remove and %lu not upgraded.\n"),
483 Dep
.DelCount(),Dep
.KeepCount());
485 if (Dep
.BadCount() != 0)
486 ioprintf(out
,_("%lu packages not fully installed or removed.\n"),
491 // CacheFile::NameComp - QSort compare by name /*{{{*/
492 // ---------------------------------------------------------------------
494 pkgCache
*CacheFile::SortCache
= 0;
495 int CacheFile::NameComp(const void *a
,const void *b
)
497 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
498 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
500 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
501 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
503 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
506 // CacheFile::Sort - Sort by name /*{{{*/
507 // ---------------------------------------------------------------------
509 void CacheFile::Sort()
512 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
513 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
514 pkgCache::PkgIterator I
= Cache
->PkgBegin();
515 for (;I
.end() != true; I
++)
519 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
522 // CacheFile::CheckDeps - Open the cache file /*{{{*/
523 // ---------------------------------------------------------------------
524 /* This routine generates the caches and then opens the dependency cache
525 and verifies that the system is OK. */
526 bool CacheFile::CheckDeps(bool AllowBroken
)
528 if (_error
->PendingError() == true)
531 // Check that the system is OK
532 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
533 return _error
->Error("Internal Error, non-zero counts");
535 // Apply corrections for half-installed packages
536 if (pkgApplyStatus(*DCache
) == false)
540 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
543 // Attempt to fix broken things
544 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
546 c1out
<< _("Correcting dependencies...") << flush
;
547 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
549 c1out
<< _(" failed.") << endl
;
550 ShowBroken(c1out
,*this,true);
552 return _error
->Error(_("Unable to correct dependencies"));
554 if (pkgMinimizeUpgrade(*DCache
) == false)
555 return _error
->Error(_("Unable to minimize the upgrade set"));
557 c1out
<< _(" Done") << endl
;
561 c1out
<< _("You might want to run `apt-get -f install' to correct these.") << endl
;
562 ShowBroken(c1out
,*this,true);
564 return _error
->Error(_("Unmet dependencies. Try using -f."));
571 // InstallPackages - Actually download and install the packages /*{{{*/
572 // ---------------------------------------------------------------------
573 /* This displays the informative messages describing what is going to
574 happen and then calls the download routines */
575 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,
578 if (_config
->FindB("APT::Get::Purge",false) == true)
580 pkgCache::PkgIterator I
= Cache
->PkgBegin();
581 for (; I
.end() == false; I
++)
583 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
584 Cache
->MarkDelete(I
,true);
589 bool Essential
= false;
591 // Show all the various warning indicators
592 ShowDel(c1out
,Cache
);
593 ShowNew(c1out
,Cache
);
595 ShowKept(c1out
,Cache
);
596 Fail
|= !ShowHold(c1out
,Cache
);
597 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
598 ShowUpgraded(c1out
,Cache
);
599 Fail
|= !ShowDowngraded(c1out
,Cache
);
600 Essential
= !ShowEssential(c1out
,Cache
);
605 if (Cache
->BrokenCount() != 0)
607 ShowBroken(c1out
,Cache
,false);
608 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
611 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
612 Cache
->BadCount() == 0)
616 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::Remove",true) == false)
617 return _error
->Error(_("Packages need to be removed but Remove is disabled."));
619 // Run the simulator ..
620 if (_config
->FindB("APT::Get::Simulate") == true)
622 pkgSimulate
PM(Cache
);
623 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
624 if (Res
== pkgPackageManager::Failed
)
626 if (Res
!= pkgPackageManager::Completed
)
627 return _error
->Error("Internal Error, Ordering didn't finish");
631 // Create the text record parser
632 pkgRecords
Recs(Cache
);
633 if (_error
->PendingError() == true)
636 // Lock the archive directory
638 if (_config
->FindB("Debug::NoLocking",false) == false)
640 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
641 if (_error
->PendingError() == true)
642 return _error
->Error(_("Unable to lock the download directory"));
645 // Create the download object
646 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
647 pkgAcquire
Fetcher(&Stat
);
649 // Read the source list
651 if (List
.ReadMainList() == false)
652 return _error
->Error(_("The list of sources could not be read."));
654 // Create the package manager and prepare to download
655 SPtr
<pkgPackageManager
> PM
= _system
->CreatePM(Cache
);
656 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false ||
657 _error
->PendingError() == true)
660 // Display statistics
661 double FetchBytes
= Fetcher
.FetchNeeded();
662 double FetchPBytes
= Fetcher
.PartialPresent();
663 double DebBytes
= Fetcher
.TotalNeeded();
664 if (DebBytes
!= Cache
->DebSize())
666 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
667 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
671 if (DebBytes
!= FetchBytes
)
672 ioprintf(c1out
,_("Need to get %sB/%sB of archives. "),
673 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
675 ioprintf(c1out
,_("Need to get %sB of archives. "),
676 SizeToStr(DebBytes
).c_str());
679 if (Cache
->UsrSize() >= 0)
680 ioprintf(c1out
,_("After unpacking %sB will be used.\n"),
681 SizeToStr(Cache
->UsrSize()).c_str());
683 ioprintf(c1out
,_("After unpacking %sB will be freed.\n"),
684 SizeToStr(-1*Cache
->UsrSize()).c_str());
686 if (_error
->PendingError() == true)
689 /* Check for enough free space, but only if we are actually going to
691 if (_config
->FindB("APT::Get::Print-URIs") == false)
694 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
695 if (statvfs(OutputDir
.c_str(),&Buf
) != 0)
696 return _error
->Errno("statvfs","Couldn't determine free space in %s",
698 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
699 return _error
->Error(_("Sorry, you don't have enough free space in %s to hold all the .debs."),
704 if (_config
->FindI("quiet",0) >= 2 ||
705 _config
->FindB("APT::Get::Assume-Yes",false) == true)
707 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
708 return _error
->Error(_("There are problems and -y was used without --force-yes"));
711 if (Essential
== true && Saftey
== true)
713 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
714 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
716 const char *Prompt
= _("Yes, do as I say!");
718 _("You are about to do something potentially harmful\n"
719 "To continue type in the phrase '%s'\n"
722 if (AnalPrompt(Prompt
) == false)
724 c2out
<< _("Abort.") << endl
;
730 // Prompt to continue
731 if (Ask
== true || Fail
== true)
733 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
734 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
736 if (_config
->FindI("quiet",0) < 2 &&
737 _config
->FindB("APT::Get::Assume-Yes",false) == false)
739 c2out
<< _("Do you want to continue? [Y/n] ") << flush
;
741 if (YnPrompt() == false)
743 c2out
<< _("Abort.") << endl
;
750 // Just print out the uris an exit if the --print-uris flag was used
751 if (_config
->FindB("APT::Get::Print-URIs") == true)
753 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
754 for (; I
!= Fetcher
.UriEnd(); I
++)
755 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
756 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
760 /* Unlock the dpkg lock if we are not going to be doing an install
762 if (_config
->FindB("APT::Get::Download-Only",false) == true)
768 bool Transient
= false;
769 if (_config
->FindB("APT::Get::Download",true) == false)
771 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
773 if ((*I
)->Local
== true)
779 // Close the item and check if it was found in cache
781 if ((*I
)->Complete
== false)
784 // Clear it out of the fetch list
786 I
= Fetcher
.ItemsBegin();
790 if (Fetcher
.Run() == pkgAcquire::Failed
)
795 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
797 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
798 (*I
)->Complete
== true)
801 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
808 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
809 (*I
)->ErrorText
.c_str());
813 /* If we are in no download mode and missing files and there were
814 'failures' then the user must specify -m. Furthermore, there
815 is no such thing as a transient error in no-download mode! */
816 if (Transient
== true &&
817 _config
->FindB("APT::Get::Download",true) == false)
823 if (_config
->FindB("APT::Get::Download-Only",false) == true)
825 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
826 return _error
->Error(_("Some files failed to download"));
827 c1out
<< _("Download complete and in download only mode") << endl
;
831 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
833 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
836 if (Transient
== true && Failed
== true)
837 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
839 // Try to deal with missing package files
840 if (Failed
== true && PM
->FixMissing() == false)
842 cerr
<< _("Unable to correct missing packages.") << endl
;
843 return _error
->Error(_("Aborting Install."));
847 pkgPackageManager::OrderResult Res
= PM
->DoInstall();
848 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
850 if (Res
== pkgPackageManager::Completed
)
853 // Reload the fetcher object and loop again for media swapping
855 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false)
862 // TryToInstall - Try to install a single package /*{{{*/
863 // ---------------------------------------------------------------------
864 /* This used to be inlined in DoInstall, but with the advent of regex package
865 name matching it was split out.. */
866 bool TryToInstall(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
867 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
868 unsigned int &ExpectedInst
,bool AllowFail
= true)
870 /* This is a pure virtual package and there is a single available
872 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0 &&
873 Pkg
.ProvidesList()->NextProvides
== 0)
875 pkgCache::PkgIterator Tmp
= Pkg
.ProvidesList().OwnerPkg();
876 ioprintf(c1out
,_("Note, selecting %s instead of %s\n"),
877 Tmp
.Name(),Pkg
.Name());
881 // Handle the no-upgrade case
882 if (_config
->FindB("APT::Get::upgrade",true) == false &&
883 Pkg
->CurrentVer
!= 0)
885 if (AllowFail
== true)
886 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
891 // Check if there is something at all to install
892 pkgDepCache::StateCache
&State
= Cache
[Pkg
];
893 if (Remove
== true && Pkg
->CurrentVer
== 0)
895 /* We want to continue searching for regex hits, so we return false here
896 otherwise this is not really an error. */
897 if (AllowFail
== false)
899 ioprintf(c1out
,_("Package %s is not installed, so not removed\n"),Pkg
.Name());
903 if (State
.CandidateVer
== 0 && Remove
== false)
905 if (AllowFail
== false)
908 if (Pkg
->ProvidesList
!= 0)
910 ioprintf(c1out
,_("Package %s is a virtual package provided by:\n"),
913 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
914 for (; I
.end() == false; I
++)
916 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
918 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer())
920 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
921 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
922 _(" [Installed]") << endl
;
924 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
927 c1out
<< _("You should explicitly select one to install.") << endl
;
932 _("Package %s has no available version, but exists in the database.\n"
933 "This typically means that the package was mentioned in a dependency and\n"
934 "never uploaded, has been obsoleted or is not available with the contents\n"
935 "of sources.list\n"),Pkg
.Name());
938 SPtrArray
<bool> Seen
= new bool[Cache
.Head().PackageCount
];
939 memset(Seen
,0,Cache
.Head().PackageCount
*sizeof(*Seen
));
940 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
941 for (; Dep
.end() == false; Dep
++)
943 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
945 if (Seen
[Dep
.ParentPkg()->ID
] == true)
947 Seen
[Dep
.ParentPkg()->ID
] = true;
948 List
+= string(Dep
.ParentPkg().Name()) + " ";
950 ShowList(c1out
,_("However the following packages replace it:"),List
);
953 _error
->Error(_("Package %s has no installation candidate"),Pkg
.Name());
962 Cache
.MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
967 Cache
.MarkInstall(Pkg
,false);
968 if (State
.Install() == false)
970 if (_config
->FindB("APT::Get::ReInstall",false) == true)
972 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
973 ioprintf(c1out
,_("Sorry, re-installation of %s is not possible, it cannot be downloaded.\n"),
976 Cache
.SetReInstall(Pkg
,true);
980 if (AllowFail
== true)
981 ioprintf(c1out
,_("Sorry, %s is already the newest version.\n"),
988 // Install it with autoinstalling enabled.
989 if (State
.InstBroken() == true && BrokenFix
== false)
990 Cache
.MarkInstall(Pkg
,true);
994 // TryToChangeVer - Try to change a candidate version /*{{{*/
995 // ---------------------------------------------------------------------
997 bool TryToChangeVer(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
998 const char *VerTag
,bool IsRel
)
1000 pkgVersionMatch
Match(VerTag
,(IsRel
== true?pkgVersionMatch::Release
:pkgVersionMatch::Version
));
1002 pkgCache::VerIterator Ver
= Match
.Find(Pkg
);
1004 if (Ver
.end() == true)
1007 return _error
->Error(_("Release '%s' for '%s' was not found"),
1009 return _error
->Error(_("Version '%s' for '%s' was not found"),
1013 if (strcmp(VerTag
,Ver
.VerStr()) != 0)
1015 ioprintf(c1out
,_("Selected version %s (%s) for %s\n"),
1016 Ver
.VerStr(),Ver
.RelStr().c_str(),Pkg
.Name());
1019 Cache
.SetCandidateVersion(Ver
);
1023 // FindSrc - Find a source record /*{{{*/
1024 // ---------------------------------------------------------------------
1026 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
1027 pkgSrcRecords
&SrcRecs
,string
&Src
,
1030 // We want to pull the version off the package specification..
1032 string TmpSrc
= Name
;
1033 string::size_type Slash
= TmpSrc
.rfind('=');
1034 if (Slash
!= string::npos
)
1036 VerTag
= string(TmpSrc
.begin() + Slash
+ 1,TmpSrc
.end());
1037 TmpSrc
= string(TmpSrc
.begin(),TmpSrc
.begin() + Slash
);
1040 /* Lookup the version of the package we would install if we were to
1041 install a version and determine the source package name, then look
1042 in the archive for a source package of the same name. In theory
1043 we could stash the version string as well and match that too but
1044 today there aren't multi source versions in the archive. */
1045 if (_config
->FindB("APT::Get::Only-Source") == false &&
1046 VerTag
.empty() == true)
1048 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(TmpSrc
);
1049 if (Pkg
.end() == false)
1051 pkgCache::VerIterator Ver
= Cache
.GetCandidateVer(Pkg
);
1052 if (Ver
.end() == false)
1054 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1055 Src
= Parse
.SourcePkg();
1060 // No source package name..
1061 if (Src
.empty() == true)
1065 pkgSrcRecords::Parser
*Last
= 0;
1066 unsigned long Offset
= 0;
1068 bool IsMatch
= false;
1070 // If we are matching by version then we need exact matches to be happy
1071 if (VerTag
.empty() == false)
1074 /* Iterate over all of the hits, which includes the resulting
1075 binary packages in the search */
1076 pkgSrcRecords::Parser
*Parse
;
1078 while ((Parse
= SrcRecs
.Find(Src
.c_str(),false)) != 0)
1080 string Ver
= Parse
->Version();
1082 // Skip name mismatches
1083 if (IsMatch
== true && Parse
->Package() != Src
)
1086 if (VerTag
.empty() == false)
1088 /* Don't want to fall through because we are doing exact version
1090 if (Cache
.VS().CmpVersion(VerTag
,Ver
) != 0)
1094 Offset
= Parse
->Offset();
1098 // Newer version or an exact match
1099 if (Last
== 0 || Cache
.VS().CmpVersion(Version
,Ver
) < 0 ||
1100 (Parse
->Package() == Src
&& IsMatch
== false))
1102 IsMatch
= Parse
->Package() == Src
;
1104 Offset
= Parse
->Offset();
1112 if (Last
->Jump(Offset
) == false)
1119 // DoUpdate - Update the package lists /*{{{*/
1120 // ---------------------------------------------------------------------
1122 bool DoUpdate(CommandLine
&CmdL
)
1124 if (CmdL
.FileSize() != 1)
1125 return _error
->Error(_("The update command takes no arguments"));
1127 // Get the source list
1129 if (List
.ReadMainList() == false)
1132 // Lock the list directory
1134 if (_config
->FindB("Debug::NoLocking",false) == false)
1136 Lock
.Fd(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
1137 if (_error
->PendingError() == true)
1138 return _error
->Error(_("Unable to lock the list directory"));
1141 // Create the download object
1142 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1143 pkgAcquire
Fetcher(&Stat
);
1145 // Populate it with the source selection
1146 if (List
.GetIndexes(&Fetcher
) == false)
1150 if (Fetcher
.Run() == pkgAcquire::Failed
)
1153 bool Failed
= false;
1154 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1156 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
1161 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1162 (*I
)->ErrorText
.c_str());
1166 // Clean out any old list files
1167 if (_config
->FindB("APT::Get::List-Cleanup",true) == true)
1169 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
1170 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
1174 // Prepare the cache.
1176 if (Cache
.Open() == false)
1180 return _error
->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
1185 // DoUpgrade - Upgrade all packages /*{{{*/
1186 // ---------------------------------------------------------------------
1187 /* Upgrade all packages without installing new packages or erasing old
1189 bool DoUpgrade(CommandLine
&CmdL
)
1192 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1196 if (pkgAllUpgrade(Cache
) == false)
1198 ShowBroken(c1out
,Cache
,false);
1199 return _error
->Error(_("Internal Error, AllUpgrade broke stuff"));
1202 return InstallPackages(Cache
,true);
1205 // DoInstall - Install packages from the command line /*{{{*/
1206 // ---------------------------------------------------------------------
1207 /* Install named packages */
1208 bool DoInstall(CommandLine
&CmdL
)
1211 if (Cache
.Open() == false || Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
1214 // Enter the special broken fixing mode if the user specified arguments
1215 bool BrokenFix
= false;
1216 if (Cache
->BrokenCount() != 0)
1219 unsigned int ExpectedInst
= 0;
1220 unsigned int Packages
= 0;
1221 pkgProblemResolver
Fix(Cache
);
1223 bool DefRemove
= false;
1224 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
1227 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1229 // Duplicate the string
1230 unsigned int Length
= strlen(*I
);
1232 if (Length
>= sizeof(S
))
1236 // See if we are removing and special indicators..
1237 bool Remove
= DefRemove
;
1239 bool VerIsRel
= false;
1240 while (Cache
->FindPkg(S
).end() == true)
1242 // Handle an optional end tag indicating what to do
1243 if (S
[Length
- 1] == '-')
1250 if (S
[Length
- 1] == '+')
1257 char *Slash
= strchr(S
,'=');
1265 Slash
= strchr(S
,'/');
1276 // Locate the package
1277 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
1279 if (Pkg
.end() == true)
1281 // Check if the name is a regex
1283 for (I
= S
; *I
!= 0; I
++)
1284 if (*I
== '.' || *I
== '?' || *I
== '*' || *I
== '|')
1287 return _error
->Error(_("Couldn't find package %s"),S
);
1289 // Regexs must always be confirmed
1290 ExpectedInst
+= 1000;
1292 // Compile the regex pattern
1295 if ((Res
= regcomp(&Pattern
,S
,REG_EXTENDED
| REG_ICASE
|
1299 regerror(Res
,&Pattern
,Error
,sizeof(Error
));
1300 return _error
->Error(_("Regex compilation error - %s"),Error
);
1303 // Run over the matches
1305 for (Pkg
= Cache
->PkgBegin(); Pkg
.end() == false; Pkg
++)
1307 if (regexec(&Pattern
,Pkg
.Name(),0,0,0) != 0)
1311 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1314 Hit
|= TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,
1315 ExpectedInst
,false);
1320 return _error
->Error(_("Couldn't find package %s"),S
);
1325 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1327 if (TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,ExpectedInst
) == false)
1332 /* If we are in the Broken fixing mode we do not attempt to fix the
1333 problems. This is if the user invoked install without -f and gave
1335 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1337 c1out
<< _("You might want to run `apt-get -f install' to correct these:") << endl
;
1338 ShowBroken(c1out
,Cache
,false);
1340 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1343 // Call the scored problem resolver
1344 Fix
.InstallProtect();
1345 if (Fix
.Resolve(true) == false)
1348 // Now we check the state of the packages,
1349 if (Cache
->BrokenCount() != 0)
1352 _("Some packages could not be installed. This may mean that you have\n"
1353 "requested an impossible situation or if you are using the unstable\n"
1354 "distribution that some required packages have not yet been created\n"
1355 "or been moved out of Incoming.") << endl
;
1360 _("Since you only requested a single operation it is extremely likely that\n"
1361 "the package is simply not installable and a bug report against\n"
1362 "that package should be filed.") << endl
;
1365 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1367 ShowBroken(c1out
,Cache
,false);
1368 return _error
->Error(_("Sorry, broken packages"));
1371 /* Print out a list of packages that are going to be installed extra
1372 to what the user asked */
1373 if (Cache
->InstCount() != ExpectedInst
)
1376 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1378 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1379 if ((*Cache
)[I
].Install() == false)
1383 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1384 if (strcmp(*J
,I
.Name()) == 0)
1388 List
+= string(I
.Name()) + " ";
1391 ShowList(c1out
,_("The following extra packages will be installed:"),List
);
1394 // See if we need to prompt
1395 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
1396 return InstallPackages(Cache
,false,false);
1398 return InstallPackages(Cache
,false);
1401 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1402 // ---------------------------------------------------------------------
1403 /* Intelligent upgrader that will install and remove packages at will */
1404 bool DoDistUpgrade(CommandLine
&CmdL
)
1407 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1410 c0out
<< _("Calculating Upgrade... ") << flush
;
1411 if (pkgDistUpgrade(*Cache
) == false)
1413 c0out
<< _("Failed") << endl
;
1414 ShowBroken(c1out
,Cache
,false);
1418 c0out
<< _("Done") << endl
;
1420 return InstallPackages(Cache
,true);
1423 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1424 // ---------------------------------------------------------------------
1425 /* Follows dselect's selections */
1426 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1429 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1432 // Install everything with the install flag set
1433 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1434 for (;I
.end() != true; I
++)
1436 /* Install the package only if it is a new install, the autoupgrader
1437 will deal with the rest */
1438 if (I
->SelectedState
== pkgCache::State::Install
)
1439 Cache
->MarkInstall(I
,false);
1442 /* Now install their deps too, if we do this above then order of
1443 the status file is significant for | groups */
1444 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1446 /* Install the package only if it is a new install, the autoupgrader
1447 will deal with the rest */
1448 if (I
->SelectedState
== pkgCache::State::Install
)
1449 Cache
->MarkInstall(I
,true);
1452 // Apply erasures now, they override everything else.
1453 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1456 if (I
->SelectedState
== pkgCache::State::DeInstall
||
1457 I
->SelectedState
== pkgCache::State::Purge
)
1458 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
1461 /* Resolve any problems that dselect created, allupgrade cannot handle
1462 such things. We do so quite agressively too.. */
1463 if (Cache
->BrokenCount() != 0)
1465 pkgProblemResolver
Fix(Cache
);
1467 // Hold back held packages.
1468 if (_config
->FindB("APT::Ignore-Hold",false) == false)
1470 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
1472 if (I
->SelectedState
== pkgCache::State::Hold
)
1480 if (Fix
.Resolve() == false)
1482 ShowBroken(c1out
,Cache
,false);
1483 return _error
->Error("Internal Error, problem resolver broke stuff");
1487 // Now upgrade everything
1488 if (pkgAllUpgrade(Cache
) == false)
1490 ShowBroken(c1out
,Cache
,false);
1491 return _error
->Error("Internal Error, problem resolver broke stuff");
1494 return InstallPackages(Cache
,false);
1497 // DoClean - Remove download archives /*{{{*/
1498 // ---------------------------------------------------------------------
1500 bool DoClean(CommandLine
&CmdL
)
1502 if (_config
->FindB("APT::Get::Simulate") == true)
1504 cout
<< "Del " << _config
->FindDir("Dir::Cache::archives") << "* " <<
1505 _config
->FindDir("Dir::Cache::archives") << "partial/*" << endl
;
1509 // Lock the archive directory
1511 if (_config
->FindB("Debug::NoLocking",false) == false)
1513 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1514 if (_error
->PendingError() == true)
1515 return _error
->Error(_("Unable to lock the download directory"));
1519 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
1520 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
1524 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
1525 // ---------------------------------------------------------------------
1526 /* This is similar to clean but it only purges things that cannot be
1527 downloaded, that is old versions of cached packages. */
1528 class LogCleaner
: public pkgArchiveCleaner
1531 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1533 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
1535 if (_config
->FindB("APT::Get::Simulate") == false)
1540 bool DoAutoClean(CommandLine
&CmdL
)
1542 // Lock the archive directory
1544 if (_config
->FindB("Debug::NoLocking",false) == false)
1546 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1547 if (_error
->PendingError() == true)
1548 return _error
->Error(_("Unable to lock the download directory"));
1552 if (Cache
.Open() == false)
1557 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1558 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1561 // DoCheck - Perform the check operation /*{{{*/
1562 // ---------------------------------------------------------------------
1563 /* Opening automatically checks the system, this command is mostly used
1565 bool DoCheck(CommandLine
&CmdL
)
1574 // DoSource - Fetch a source archive /*{{{*/
1575 // ---------------------------------------------------------------------
1576 /* Fetch souce packages */
1584 bool DoSource(CommandLine
&CmdL
)
1587 if (Cache
.Open(false) == false)
1590 if (CmdL
.FileSize() <= 1)
1591 return _error
->Error(_("Must specify at least one package to fetch source for"));
1593 // Read the source list
1595 if (List
.ReadMainList() == false)
1596 return _error
->Error(_("The list of sources could not be read."));
1598 // Create the text record parsers
1599 pkgRecords
Recs(Cache
);
1600 pkgSrcRecords
SrcRecs(List
);
1601 if (_error
->PendingError() == true)
1604 // Create the download object
1605 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1606 pkgAcquire
Fetcher(&Stat
);
1608 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
1610 // Load the requestd sources into the fetcher
1612 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1615 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1618 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1621 vector
<pkgSrcRecords::File
> Lst
;
1622 if (Last
->Files(Lst
) == false)
1625 // Load them into the fetcher
1626 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
1627 I
!= Lst
.end(); I
++)
1629 // Try to guess what sort of file it is we are getting.
1630 if (I
->Type
== "dsc")
1632 Dsc
[J
].Package
= Last
->Package();
1633 Dsc
[J
].Version
= Last
->Version();
1634 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
1637 // Diff only mode only fetches .diff files
1638 if (_config
->FindB("APT::Get::Diff-Only",false) == true &&
1642 // Tar only mode only fetches .tar files
1643 if (_config
->FindB("APT::Get::Tar-Only",false) == true &&
1647 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
1649 Last
->Index().SourceInfo(*Last
,*I
),Src
);
1653 // Display statistics
1654 double FetchBytes
= Fetcher
.FetchNeeded();
1655 double FetchPBytes
= Fetcher
.PartialPresent();
1656 double DebBytes
= Fetcher
.TotalNeeded();
1658 // Check for enough free space
1660 string OutputDir
= ".";
1661 if (statvfs(OutputDir
.c_str(),&Buf
) != 0)
1662 return _error
->Errno("statvfs","Couldn't determine free space in %s",
1664 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1665 return _error
->Error(_("Sorry, you don't have enough free space in %s"),
1669 if (DebBytes
!= FetchBytes
)
1670 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
1671 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
1673 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
1674 SizeToStr(DebBytes
).c_str());
1676 if (_config
->FindB("APT::Get::Simulate",false) == true)
1678 for (unsigned I
= 0; I
!= J
; I
++)
1679 ioprintf(cout
,_("Fetch Source %s\n"),Dsc
[I
].Package
.c_str());
1683 // Just print out the uris an exit if the --print-uris flag was used
1684 if (_config
->FindB("APT::Get::Print-URIs") == true)
1686 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1687 for (; I
!= Fetcher
.UriEnd(); I
++)
1688 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1689 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1694 if (Fetcher
.Run() == pkgAcquire::Failed
)
1697 // Print error messages
1698 bool Failed
= false;
1699 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1701 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1702 (*I
)->Complete
== true)
1705 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1706 (*I
)->ErrorText
.c_str());
1710 return _error
->Error(_("Failed to fetch some archives."));
1712 if (_config
->FindB("APT::Get::Download-only",false) == true)
1714 c1out
<< _("Download complete and in download only mode") << endl
;
1718 // Unpack the sources
1719 pid_t Process
= ExecFork();
1723 for (unsigned I
= 0; I
!= J
; I
++)
1725 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
1727 // Diff only mode only fetches .diff files
1728 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
1729 _config
->FindB("APT::Get::Tar-Only",false) == true ||
1730 Dsc
[I
].Dsc
.empty() == true)
1733 // See if the package is already unpacked
1735 if (stat(Dir
.c_str(),&Stat
) == 0 &&
1736 S_ISDIR(Stat
.st_mode
) != 0)
1738 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
1745 snprintf(S
,sizeof(S
),"%s -x %s",
1746 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
1747 Dsc
[I
].Dsc
.c_str());
1750 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
1755 // Try to compile it with dpkg-buildpackage
1756 if (_config
->FindB("APT::Get::Compile",false) == true)
1758 // Call dpkg-buildpackage
1760 snprintf(S
,sizeof(S
),"cd %s && %s %s",
1762 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
1763 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
1767 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
1776 // Wait for the subprocess
1778 while (waitpid(Process
,&Status
,0) != Process
)
1782 return _error
->Errno("waitpid","Couldn't wait for subprocess");
1785 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
1786 return _error
->Error(_("Child process failed"));
1791 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
1792 // ---------------------------------------------------------------------
1793 /* This function will look at the build depends list of the given source
1794 package and install the necessary packages to make it true, or fail. */
1795 bool DoBuildDep(CommandLine
&CmdL
)
1798 if (Cache
.Open(true) == false)
1801 if (CmdL
.FileSize() <= 1)
1802 return _error
->Error(_("Must specify at least one package to check builddeps for"));
1804 // Read the source list
1806 if (List
.ReadMainList() == false)
1807 return _error
->Error(_("The list of sources could not be read."));
1809 // Create the text record parsers
1810 pkgRecords
Recs(Cache
);
1811 pkgSrcRecords
SrcRecs(List
);
1812 if (_error
->PendingError() == true)
1815 // Create the download object
1816 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1817 pkgAcquire
Fetcher(&Stat
);
1820 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1823 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1825 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1827 // Process the build-dependencies
1828 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
1829 if (Last
->BuildDepends(BuildDeps
) == false)
1830 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
1832 if (BuildDeps
.size() == 0)
1834 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
1838 // Install the requested packages
1839 unsigned int ExpectedInst
= 0;
1840 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
1841 pkgProblemResolver
Fix(Cache
);
1842 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); D
++)
1844 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
1845 if (Pkg
.end() == true)
1846 return _error
->Error(_("%s dependency on %s cannot be satisfied because the package %s cannot be found"),
1847 Last
->BuildDepType((*D
).Type
),Src
.c_str(),(*D
).Package
.c_str());
1848 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1850 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1851 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1854 * conflict; need to remove if we have an installed version
1855 * that satisfies the version criterial
1857 if (IV
.end() == false &&
1858 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1859 TryToInstall(Pkg
,Cache
,Fix
,true,false,ExpectedInst
);
1864 * If this is a virtual package, we need to check the list of
1865 * packages that provide it and see if any of those are
1868 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
1869 for (; Prv
.end() != true; Prv
++)
1870 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
1873 if (Prv
.end() == true)
1876 * depends; need to install or upgrade if we don't have the
1877 * package installed or if the version does not satisfy the
1878 * build dep. This is complicated by the fact that if we
1879 * depend on a version lower than what we already have
1880 * installed it is not clear what should be done; in practice
1881 * this case should be rare though and right now nothing
1882 * is done about it :-(
1884 if (IV
.end() == true ||
1885 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == false)
1886 TryToInstall(Pkg
,Cache
,Fix
,false,false,ExpectedInst
);
1891 Fix
.InstallProtect();
1892 if (Fix
.Resolve(true) == false)
1895 // Now we check the state of the packages,
1896 if (Cache
->BrokenCount() != 0)
1897 return _error
->Error(_("Some broken packages were found while trying to process build-dependencies.\n"
1898 "You might want to run `apt-get -f install' to correct these."));
1901 if (InstallPackages(Cache
, false, true) == false)
1902 return _error
->Error(_("Failed to process build dependencies"));
1907 // DoMoo - Never Ask, Never Tell /*{{{*/
1908 // ---------------------------------------------------------------------
1910 bool DoMoo(CommandLine
&CmdL
)
1919 "....\"Have you mooed today?\"...\n";
1924 // ShowHelp - Show a help screen /*{{{*/
1925 // ---------------------------------------------------------------------
1927 bool ShowHelp(CommandLine
&CmdL
)
1929 ioprintf(cout
,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE
,VERSION
,
1930 COMMON_OS
,COMMON_CPU
,__DATE__
,__TIME__
);
1932 if (_config
->FindB("version") == true)
1934 cout
<< _("Supported Modules:") << endl
;
1936 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
1938 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
1939 if (_system
!= 0 && _system
->VS
== VS
)
1943 cout
<< "Ver: " << VS
->Label
<< endl
;
1945 /* Print out all the packaging systems that will work with
1947 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
1949 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
1954 if (Sys
->VS
->TestCompatibility(*VS
) == true)
1955 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
1959 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
1961 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
1962 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
1965 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
1967 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
1968 cout
<< " Idx: " << Type
->Label
<< endl
;
1975 _("Usage: apt-get [options] command\n"
1976 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
1977 " apt-get [options] source pkg1 [pkg2 ...]\n"
1979 "apt-get is a simple command line interface for downloading and\n"
1980 "installing packages. The most frequently used commands are update\n"
1984 " update - Retrieve new lists of packages\n"
1985 " upgrade - Perform an upgrade\n"
1986 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
1987 " remove - Remove packages\n"
1988 " source - Download source archives\n"
1989 " build-dep - Configure build-dependencies for source packages\n"
1990 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
1991 " dselect-upgrade - Follow dselect selections\n"
1992 " clean - Erase downloaded archive files\n"
1993 " autoclean - Erase old downloaded archive files\n"
1994 " check - Verify that there are no broken dependencies\n"
1997 " -h This help text.\n"
1998 " -q Loggable output - no progress indicator\n"
1999 " -qq No output except for errors\n"
2000 " -d Download only - do NOT install or unpack archives\n"
2001 " -s No-act. Perform ordering simulation\n"
2002 " -y Assume Yes to all queries and do not prompt\n"
2003 " -f Attempt to continue if the integrity check fails\n"
2004 " -m Attempt to continue if archives are unlocatable\n"
2005 " -u Show a list of upgraded packages as well\n"
2006 " -b Build the source package after fetching it\n"
2007 " -c=? Read this configuration file\n"
2008 " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n"
2009 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
2010 "pages for more information and options.\n"
2011 " This APT has Super Cow Powers.\n");
2015 // GetInitialize - Initialize things for apt-get /*{{{*/
2016 // ---------------------------------------------------------------------
2018 void GetInitialize()
2020 _config
->Set("quiet",0);
2021 _config
->Set("help",false);
2022 _config
->Set("APT::Get::Download-Only",false);
2023 _config
->Set("APT::Get::Simulate",false);
2024 _config
->Set("APT::Get::Assume-Yes",false);
2025 _config
->Set("APT::Get::Fix-Broken",false);
2026 _config
->Set("APT::Get::Force-Yes",false);
2027 _config
->Set("APT::Get::APT::Get::No-List-Cleanup",true);
2030 // SigWinch - Window size change signal handler /*{{{*/
2031 // ---------------------------------------------------------------------
2035 // Riped from GNU ls
2039 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
2040 ScreenWidth
= ws
.ws_col
- 1;
2045 int main(int argc
,const char *argv
[])
2047 CommandLine::Args Args
[] = {
2048 {'h',"help","help",0},
2049 {'v',"version","version",0},
2050 {'q',"quiet","quiet",CommandLine::IntLevel
},
2051 {'q',"silent","quiet",CommandLine::IntLevel
},
2052 {'d',"download-only","APT::Get::Download-Only",0},
2053 {'b',"compile","APT::Get::Compile",0},
2054 {'b',"build","APT::Get::Compile",0},
2055 {'s',"simulate","APT::Get::Simulate",0},
2056 {'s',"just-print","APT::Get::Simulate",0},
2057 {'s',"recon","APT::Get::Simulate",0},
2058 {'s',"dry-run","APT::Get::Simulate",0},
2059 {'s',"no-act","APT::Get::Simulate",0},
2060 {'y',"yes","APT::Get::Assume-Yes",0},
2061 {'y',"assume-yes","APT::Get::Assume-Yes",0},
2062 {'f',"fix-broken","APT::Get::Fix-Broken",0},
2063 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
2064 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
2065 {'t',"target-release","APT::Default-Release",CommandLine::HasArg
},
2066 {'t',"default-release","APT::Default-Release",CommandLine::HasArg
},
2067 {0,"download","APT::Get::Download",0},
2068 {0,"fix-missing","APT::Get::Fix-Missing",0},
2069 {0,"ignore-hold","APT::Ignore-Hold",0},
2070 {0,"upgrade","APT::Get::upgrade",0},
2071 {0,"force-yes","APT::Get::force-yes",0},
2072 {0,"print-uris","APT::Get::Print-URIs",0},
2073 {0,"diff-only","APT::Get::Diff-Only",0},
2074 {0,"tar-only","APT::Get::tar-Only",0},
2075 {0,"purge","APT::Get::Purge",0},
2076 {0,"list-cleanup","APT::Get::List-Cleanup",0},
2077 {0,"reinstall","APT::Get::ReInstall",0},
2078 {0,"trivial-only","APT::Get::Trivial-Only",0},
2079 {0,"remove","APT::Get::Remove",0},
2080 {0,"only-source","APT::Get::Only-Source",0},
2081 {'c',"config-file",0,CommandLine::ConfigFile
},
2082 {'o',"option",0,CommandLine::ArbItem
},
2084 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
2085 {"upgrade",&DoUpgrade
},
2086 {"install",&DoInstall
},
2087 {"remove",&DoInstall
},
2088 {"dist-upgrade",&DoDistUpgrade
},
2089 {"dselect-upgrade",&DoDSelectUpgrade
},
2090 {"build-dep",&DoBuildDep
},
2092 {"autoclean",&DoAutoClean
},
2094 {"source",&DoSource
},
2099 // Parse the command line and initialize the package library
2100 CommandLine
CmdL(Args
,_config
);
2101 if (pkgInitConfig(*_config
) == false ||
2102 CmdL
.Parse(argc
,argv
) == false ||
2103 pkgInitSystem(*_config
,_system
) == false)
2105 if (_config
->FindB("version") == true)
2108 _error
->DumpErrors();
2112 // See if the help should be shown
2113 if (_config
->FindB("help") == true ||
2114 _config
->FindB("version") == true ||
2115 CmdL
.FileSize() == 0)
2121 // Deal with stdout not being a tty
2122 if (ttyname(STDOUT_FILENO
) == 0 && _config
->FindI("quiet",0) < 1)
2123 _config
->Set("quiet","1");
2125 // Setup the output streams
2126 c0out
.rdbuf(cout
.rdbuf());
2127 c1out
.rdbuf(cout
.rdbuf());
2128 c2out
.rdbuf(cout
.rdbuf());
2129 if (_config
->FindI("quiet",0) > 0)
2130 c0out
.rdbuf(devnull
.rdbuf());
2131 if (_config
->FindI("quiet",0) > 1)
2132 c1out
.rdbuf(devnull
.rdbuf());
2134 // Setup the signals
2135 signal(SIGPIPE
,SIG_IGN
);
2136 signal(SIGWINCH
,SigWinch
);
2139 // Match the operation
2140 CmdL
.DispatchArg(Cmds
);
2142 // Print any errors or warnings found during parsing
2143 if (_error
->empty() == false)
2145 bool Errors
= _error
->PendingError();
2146 _error
->DumpErrors();
2147 return Errors
== true?100:0;