]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.104 2001/03/13 05:23:42 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>
64 ofstream
devnull("/dev/null");
65 unsigned int ScreenWidth
= 80;
67 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
68 // ---------------------------------------------------------------------
70 class CacheFile
: public pkgCacheFile
72 static pkgCache
*SortCache
;
73 static int NameComp(const void *a
,const void *b
);
76 pkgCache::Package
**List
;
79 bool CheckDeps(bool AllowBroken
= false);
80 bool Open(bool WithLock
= true)
82 OpTextProgress
Prog(*_config
);
83 if (pkgCacheFile::Open(Prog
,WithLock
) == false)
89 CacheFile() : List(0) {};
93 // YnPrompt - Yes No Prompt. /*{{{*/
94 // ---------------------------------------------------------------------
95 /* Returns true on a Yes.*/
98 // This needs to be a capital
99 const char *Yes
= _("Y");
101 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
103 c1out
<< Yes
<< endl
;
109 if (read(STDIN_FILENO
,&C
,1) != 1)
111 while (C
!= '\n' && Jnk
!= '\n')
112 if (read(STDIN_FILENO
,&Jnk
,1) != 1)
115 if (!(toupper(C
) == *Yes
|| C
== '\n' || C
== '\r'))
120 // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
121 // ---------------------------------------------------------------------
122 /* Returns true on a Yes.*/
123 bool AnalPrompt(const char *Text
)
126 cin
.getline(Buf
,sizeof(Buf
));
127 if (strcmp(Buf
,Text
) == 0)
132 // ShowList - Show a list /*{{{*/
133 // ---------------------------------------------------------------------
134 /* This prints out a string of space separated words with a title and
135 a two space indent line wraped to the current screen width. */
136 bool ShowList(ostream
&out
,string Title
,string List
)
138 if (List
.empty() == true)
141 // Acount for the leading space
142 int ScreenWidth
= ::ScreenWidth
- 3;
144 out
<< Title
<< endl
;
145 string::size_type Start
= 0;
146 while (Start
< List
.size())
148 string::size_type End
;
149 if (Start
+ ScreenWidth
>= List
.size())
152 End
= List
.rfind(' ',Start
+ScreenWidth
);
154 if (End
== string::npos
|| End
< Start
)
155 End
= Start
+ ScreenWidth
;
156 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
162 // ShowBroken - Debugging aide /*{{{*/
163 // ---------------------------------------------------------------------
164 /* This prints out the names of all the packages that are broken along
165 with the name of each each broken dependency and a quite version
168 The output looks like:
169 Sorry, but the following packages have unmet dependencies:
170 exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed
171 Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
172 Depends: libsasl7 but it is not going to be installed
174 void ShowBroken(ostream
&out
,CacheFile
&Cache
,bool Now
)
176 out
<< _("Sorry, but the following packages have unmet dependencies:") << endl
;
177 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
179 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
181 if (Cache
[I
].InstBroken() == false)
184 // Print out each package and the failed dependencies
185 out
<<" " << I
.Name() << ":";
186 unsigned Indent
= strlen(I
.Name()) + 3;
188 if (Cache
[I
].InstVerIter(Cache
).end() == true)
194 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
196 // Compute a single dependency element (glob or)
197 pkgCache::DepIterator Start
;
198 pkgCache::DepIterator End
;
201 if (Cache
->IsImportantDep(End
) == false ||
202 (Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
209 for (unsigned J
= 0; J
!= Indent
; J
++)
213 if (FirstOr
== false)
215 for (unsigned J
= 0; J
!= strlen(End
.DepType()) + 3; J
++)
219 out
<< ' ' << End
.DepType() << ": ";
222 out
<< Start
.TargetPkg().Name();
224 // Show a quick summary of the version requirements
225 if (Start
.TargetVer() != 0)
226 out
<< " (" << Start
.CompType() << " " << Start
.TargetVer() << ")";
228 /* Show a summary of the target package if possible. In the case
229 of virtual packages we show nothing */
230 pkgCache::PkgIterator Targ
= Start
.TargetPkg();
231 if (Targ
->ProvidesList
== 0)
234 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
235 if (Ver
.end() == false)
238 ioprintf(out
,_("but %s is installed"),Ver
.VerStr());
240 ioprintf(out
,_("but %s is to be installed"),Ver
.VerStr());
244 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
246 if (Targ
->ProvidesList
== 0)
247 out
<< _("but it is not installable");
249 out
<< _("but it is a virtual package");
252 out
<< (Now
?_("but it is not installed"):_("but it is not going to be installed"));
268 // ShowNew - Show packages to newly install /*{{{*/
269 // ---------------------------------------------------------------------
271 void ShowNew(ostream
&out
,CacheFile
&Cache
)
273 /* Print out a list of packages that are going to be removed extra
274 to what the user asked */
276 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
278 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
279 if (Cache
[I
].NewInstall() == true)
280 List
+= string(I
.Name()) + " ";
283 ShowList(out
,_("The following NEW packages will be installed:"),List
);
286 // ShowDel - Show packages to delete /*{{{*/
287 // ---------------------------------------------------------------------
289 void ShowDel(ostream
&out
,CacheFile
&Cache
)
291 /* Print out a list of packages that are going to be removed extra
292 to what the user asked */
294 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
296 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
297 if (Cache
[I
].Delete() == true)
299 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
300 List
+= string(I
.Name()) + "* ";
302 List
+= string(I
.Name()) + " ";
306 ShowList(out
,_("The following packages will be REMOVED:"),List
);
309 // ShowKept - Show kept packages /*{{{*/
310 // ---------------------------------------------------------------------
312 void ShowKept(ostream
&out
,CacheFile
&Cache
)
315 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
317 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
320 if (Cache
[I
].Upgrade() == true || Cache
[I
].Upgradable() == false ||
321 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
324 List
+= string(I
.Name()) + " ";
326 ShowList(out
,_("The following packages have been kept back"),List
);
329 // ShowUpgraded - Show upgraded packages /*{{{*/
330 // ---------------------------------------------------------------------
332 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
335 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
337 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
340 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
343 List
+= string(I
.Name()) + " ";
345 ShowList(out
,_("The following packages will be upgraded"),List
);
348 // ShowDowngraded - Show downgraded packages /*{{{*/
349 // ---------------------------------------------------------------------
351 bool ShowDowngraded(ostream
&out
,CacheFile
&Cache
)
354 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
356 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
359 if (Cache
[I
].Downgrade() == false || Cache
[I
].NewInstall() == true)
362 List
+= string(I
.Name()) + " ";
364 return ShowList(out
,_("The following packages will be DOWNGRADED"),List
);
367 // ShowHold - Show held but changed packages /*{{{*/
368 // ---------------------------------------------------------------------
370 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
373 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
375 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
376 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
377 I
->SelectedState
== pkgCache::State::Hold
)
378 List
+= string(I
.Name()) + " ";
381 return ShowList(out
,_("The following held packages will be changed:"),List
);
384 // ShowEssential - Show an essential package warning /*{{{*/
385 // ---------------------------------------------------------------------
386 /* This prints out a warning message that is not to be ignored. It shows
387 all essential packages and their dependents that are to be removed.
388 It is insanely risky to remove the dependents of an essential package! */
389 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
392 bool *Added
= new bool[Cache
->Head().PackageCount
];
393 for (unsigned int I
= 0; I
!= Cache
->Head().PackageCount
; I
++)
396 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
398 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
399 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
&&
400 (I
->Flags
& pkgCache::Flag::Important
) != pkgCache::Flag::Important
)
403 // The essential package is being removed
404 if (Cache
[I
].Delete() == true)
406 if (Added
[I
->ID
] == false)
409 List
+= string(I
.Name()) + " ";
413 if (I
->CurrentVer
== 0)
416 // Print out any essential package depenendents that are to be removed
417 for (pkgCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
419 // Skip everything but depends
420 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
421 D
->Type
!= pkgCache::Dep::Depends
)
424 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
425 if (Cache
[P
].Delete() == true)
427 if (Added
[P
->ID
] == true)
432 snprintf(S
,sizeof(S
),_("%s (due to %s) "),P
.Name(),I
.Name());
439 return ShowList(out
,_("WARNING: The following essential packages will be removed\n"
440 "This should NOT be done unless you know exactly what you are doing!"),List
);
443 // Stats - Show some statistics /*{{{*/
444 // ---------------------------------------------------------------------
446 void Stats(ostream
&out
,pkgDepCache
&Dep
)
448 unsigned long Upgrade
= 0;
449 unsigned long Downgrade
= 0;
450 unsigned long Install
= 0;
451 unsigned long ReInstall
= 0;
452 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
454 if (Dep
[I
].NewInstall() == true)
458 if (Dep
[I
].Upgrade() == true)
461 if (Dep
[I
].Downgrade() == true)
465 if (Dep
[I
].Delete() == false && (Dep
[I
].iFlags
& pkgDepCache::ReInstall
) == pkgDepCache::ReInstall
)
469 ioprintf(out
,_("%lu packages upgraded, %lu newly installed, "),
473 ioprintf(out
,_("%lu reinstalled, "),ReInstall
);
475 ioprintf(out
,_("%lu downgraded, "),Downgrade
);
477 ioprintf(out
,_("%lu to remove and %lu not upgraded.\n"),
478 Dep
.DelCount(),Dep
.KeepCount());
480 if (Dep
.BadCount() != 0)
481 ioprintf(out
,_("%lu packages not fully installed or removed.\n"),
486 // CacheFile::NameComp - QSort compare by name /*{{{*/
487 // ---------------------------------------------------------------------
489 pkgCache
*CacheFile::SortCache
= 0;
490 int CacheFile::NameComp(const void *a
,const void *b
)
492 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
493 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
495 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
496 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
498 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
501 // CacheFile::Sort - Sort by name /*{{{*/
502 // ---------------------------------------------------------------------
504 void CacheFile::Sort()
507 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
508 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
509 pkgCache::PkgIterator I
= Cache
->PkgBegin();
510 for (;I
.end() != true; I
++)
514 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
517 // CacheFile::CheckDeps - Open the cache file /*{{{*/
518 // ---------------------------------------------------------------------
519 /* This routine generates the caches and then opens the dependency cache
520 and verifies that the system is OK. */
521 bool CacheFile::CheckDeps(bool AllowBroken
)
523 if (_error
->PendingError() == true)
526 // Check that the system is OK
527 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
528 return _error
->Error("Internal Error, non-zero counts");
530 // Apply corrections for half-installed packages
531 if (pkgApplyStatus(*DCache
) == false)
535 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
538 // Attempt to fix broken things
539 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
541 c1out
<< _("Correcting dependencies...") << flush
;
542 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
544 c1out
<< _(" failed.") << endl
;
545 ShowBroken(c1out
,*this,true);
547 return _error
->Error(_("Unable to correct dependencies"));
549 if (pkgMinimizeUpgrade(*DCache
) == false)
550 return _error
->Error(_("Unable to minimize the upgrade set"));
552 c1out
<< _(" Done") << endl
;
556 c1out
<< _("You might want to run `apt-get -f install' to correct these.") << endl
;
557 ShowBroken(c1out
,*this,true);
559 return _error
->Error(_("Unmet dependencies. Try using -f."));
566 // InstallPackages - Actually download and install the packages /*{{{*/
567 // ---------------------------------------------------------------------
568 /* This displays the informative messages describing what is going to
569 happen and then calls the download routines */
570 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,
573 if (_config
->FindB("APT::Get::Purge",false) == true)
575 pkgCache::PkgIterator I
= Cache
->PkgBegin();
576 for (; I
.end() == false; I
++)
578 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
579 Cache
->MarkDelete(I
,true);
584 bool Essential
= false;
586 // Show all the various warning indicators
587 ShowDel(c1out
,Cache
);
588 ShowNew(c1out
,Cache
);
590 ShowKept(c1out
,Cache
);
591 Fail
|= !ShowHold(c1out
,Cache
);
592 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
593 ShowUpgraded(c1out
,Cache
);
594 Fail
|= !ShowDowngraded(c1out
,Cache
);
595 Essential
= !ShowEssential(c1out
,Cache
);
600 if (Cache
->BrokenCount() != 0)
602 ShowBroken(c1out
,Cache
,false);
603 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
606 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
607 Cache
->BadCount() == 0)
611 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::Remove",true) == false)
612 return _error
->Error(_("Packages need to be removed but Remove is disabled."));
614 // Run the simulator ..
615 if (_config
->FindB("APT::Get::Simulate") == true)
617 pkgSimulate
PM(Cache
);
618 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
619 if (Res
== pkgPackageManager::Failed
)
621 if (Res
!= pkgPackageManager::Completed
)
622 return _error
->Error("Internal Error, Ordering didn't finish");
626 // Create the text record parser
627 pkgRecords
Recs(Cache
);
628 if (_error
->PendingError() == true)
631 // Lock the archive directory
633 if (_config
->FindB("Debug::NoLocking",false) == false)
635 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
636 if (_error
->PendingError() == true)
637 return _error
->Error(_("Unable to lock the download directory"));
640 // Create the download object
641 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
642 pkgAcquire
Fetcher(&Stat
);
644 // Read the source list
646 if (List
.ReadMainList() == false)
647 return _error
->Error(_("The list of sources could not be read."));
649 // Create the package manager and prepare to download
650 SPtr
<pkgPackageManager
> PM
= _system
->CreatePM(Cache
);
651 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false ||
652 _error
->PendingError() == true)
655 // Display statistics
656 double FetchBytes
= Fetcher
.FetchNeeded();
657 double FetchPBytes
= Fetcher
.PartialPresent();
658 double DebBytes
= Fetcher
.TotalNeeded();
659 if (DebBytes
!= Cache
->DebSize())
661 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
662 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
666 if (DebBytes
!= FetchBytes
)
667 ioprintf(c1out
,_("Need to get %sB/%sB of archives. "),
668 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
670 ioprintf(c1out
,_("Need to get %sB of archives. "),
671 SizeToStr(DebBytes
).c_str());
674 if (Cache
->UsrSize() >= 0)
675 ioprintf(c1out
,_("After unpacking %sB will be used.\n"),
676 SizeToStr(Cache
->UsrSize()).c_str());
678 ioprintf(c1out
,_("After unpacking %sB will be freed.\n"),
679 SizeToStr(-1*Cache
->UsrSize()).c_str());
681 if (_error
->PendingError() == true)
684 /* Check for enough free space, but only if we are actually going to
686 if (_config
->FindB("APT::Get::Print-URIs") == false)
689 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
690 if (statvfs(OutputDir
.c_str(),&Buf
) != 0)
691 return _error
->Errno("statvfs","Couldn't determine free space in %s",
693 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
694 return _error
->Error(_("Sorry, you don't have enough free space in %s to hold all the .debs."),
699 if (_config
->FindI("quiet",0) >= 2 ||
700 _config
->FindB("APT::Get::Assume-Yes",false) == true)
702 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
703 return _error
->Error(_("There are problems and -y was used without --force-yes"));
706 if (Essential
== true && Saftey
== true)
708 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
709 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
711 const char *Prompt
= _("Yes, do as I say!");
713 _("You are about to do something potentially harmful\n"
714 "To continue type in the phrase '%s'\n"
717 if (AnalPrompt(Prompt
) == false)
719 c2out
<< _("Abort.") << endl
;
725 // Prompt to continue
726 if (Ask
== true || Fail
== true)
728 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
729 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
731 if (_config
->FindI("quiet",0) < 2 &&
732 _config
->FindB("APT::Get::Assume-Yes",false) == false)
734 c2out
<< _("Do you want to continue? [Y/n] ") << flush
;
736 if (YnPrompt() == false)
738 c2out
<< _("Abort.") << endl
;
745 // Just print out the uris an exit if the --print-uris flag was used
746 if (_config
->FindB("APT::Get::Print-URIs") == true)
748 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
749 for (; I
!= Fetcher
.UriEnd(); I
++)
750 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
751 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
755 /* Unlock the dpkg lock if we are not going to be doing an install
757 if (_config
->FindB("APT::Get::Download-Only",false) == true)
763 bool Transient
= false;
764 if (_config
->FindB("APT::Get::Download",true) == false)
766 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
768 if ((*I
)->Local
== true)
774 // Close the item and check if it was found in cache
776 if ((*I
)->Complete
== false)
779 // Clear it out of the fetch list
781 I
= Fetcher
.ItemsBegin();
785 if (Fetcher
.Run() == pkgAcquire::Failed
)
790 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
792 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
793 (*I
)->Complete
== true)
796 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
803 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
804 (*I
)->ErrorText
.c_str());
808 /* If we are in no download mode and missing files and there were
809 'failures' then the user must specify -m. Furthermore, there
810 is no such thing as a transient error in no-download mode! */
811 if (Transient
== true &&
812 _config
->FindB("APT::Get::Download",true) == false)
818 if (_config
->FindB("APT::Get::Download-Only",false) == true)
820 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
821 return _error
->Error(_("Some files failed to download"));
822 c1out
<< _("Download complete and in download only mode") << endl
;
826 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
828 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
831 if (Transient
== true && Failed
== true)
832 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
834 // Try to deal with missing package files
835 if (Failed
== true && PM
->FixMissing() == false)
837 cerr
<< _("Unable to correct missing packages.") << endl
;
838 return _error
->Error(_("Aborting Install."));
842 pkgPackageManager::OrderResult Res
= PM
->DoInstall();
843 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
845 if (Res
== pkgPackageManager::Completed
)
848 // Reload the fetcher object and loop again for media swapping
850 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false)
857 // TryToInstall - Try to install a single package /*{{{*/
858 // ---------------------------------------------------------------------
859 /* This used to be inlined in DoInstall, but with the advent of regex package
860 name matching it was split out.. */
861 bool TryToInstall(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
862 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
863 unsigned int &ExpectedInst
,bool AllowFail
= true)
865 /* This is a pure virtual package and there is a single available
867 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0 &&
868 Pkg
.ProvidesList()->NextProvides
== 0)
870 pkgCache::PkgIterator Tmp
= Pkg
.ProvidesList().OwnerPkg();
871 ioprintf(c1out
,_("Note, selecting %s instead of %s\n"),
872 Tmp
.Name(),Pkg
.Name());
876 // Handle the no-upgrade case
877 if (_config
->FindB("APT::Get::upgrade",true) == false &&
878 Pkg
->CurrentVer
!= 0)
880 if (AllowFail
== true)
881 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
886 // Check if there is something at all to install
887 pkgDepCache::StateCache
&State
= Cache
[Pkg
];
888 if (Remove
== true && Pkg
->CurrentVer
== 0)
890 /* We want to continue searching for regex hits, so we return false here
891 otherwise this is not really an error. */
892 if (AllowFail
== false)
894 ioprintf(c1out
,_("Package %s is not installed, so not removed\n"),Pkg
.Name());
898 if (State
.CandidateVer
== 0 && Remove
== false)
900 if (AllowFail
== false)
903 if (Pkg
->ProvidesList
!= 0)
905 ioprintf(c1out
,_("Package %s is a virtual package provided by:\n"),
908 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
909 for (; I
.end() == false; I
++)
911 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
913 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer())
915 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
916 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
917 _(" [Installed]") << endl
;
919 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
922 c1out
<< _("You should explicitly select one to install.") << endl
;
927 _("Package %s has no available version, but exists in the database.\n"
928 "This typically means that the package was mentioned in a dependency and\n"
929 "never uploaded, has been obsoleted or is not available with the contents\n"
930 "of sources.list\n"),Pkg
.Name());
933 SPtrArray
<bool> Seen
= new bool[Cache
.Head().PackageCount
];
934 memset(Seen
,0,Cache
.Head().PackageCount
*sizeof(*Seen
));
935 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
936 for (; Dep
.end() == false; Dep
++)
938 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
940 if (Seen
[Dep
.ParentPkg()->ID
] == true)
942 Seen
[Dep
.ParentPkg()->ID
] = true;
943 List
+= string(Dep
.ParentPkg().Name()) + " ";
945 ShowList(c1out
,_("However the following packages replace it:"),List
);
948 _error
->Error(_("Package %s has no installation candidate"),Pkg
.Name());
957 Cache
.MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
962 Cache
.MarkInstall(Pkg
,false);
963 if (State
.Install() == false)
965 if (_config
->FindB("APT::Get::ReInstall",false) == true)
967 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
968 ioprintf(c1out
,_("Sorry, re-installation of %s is not possible, it cannot be downloaded."),
971 Cache
.SetReInstall(Pkg
,true);
975 if (AllowFail
== true)
976 ioprintf(c1out
,_("Sorry, %s is already the newest version.\n"),
983 // Install it with autoinstalling enabled.
984 if (State
.InstBroken() == true && BrokenFix
== false)
985 Cache
.MarkInstall(Pkg
,true);
989 // TryToChangeVer - Try to change a candidate version /*{{{*/
990 // ---------------------------------------------------------------------
992 bool TryToChangeVer(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
993 const char *VerTag
,bool IsRel
)
995 pkgVersionMatch
Match(VerTag
,(IsRel
== true?pkgVersionMatch::Release
:pkgVersionMatch::Version
));
997 pkgCache::VerIterator Ver
= Match
.Find(Pkg
);
999 if (Ver
.end() == true)
1002 return _error
->Error(_("Release '%s' for '%s' was not found"),
1004 return _error
->Error(_("Version '%s' for '%s' was not found"),
1008 if (strcmp(VerTag
,Ver
.VerStr()) != 0)
1010 ioprintf(c1out
,_("Selected version %s (%s) for %s\n"),
1011 Ver
.VerStr(),Ver
.RelStr().c_str(),Pkg
.Name());
1014 Cache
.SetCandidateVersion(Ver
);
1018 // FindSrc - Find a source record /*{{{*/
1019 // ---------------------------------------------------------------------
1021 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
1022 pkgSrcRecords
&SrcRecs
,string
&Src
,
1025 // We want to pull the version off the package specification..
1027 string TmpSrc
= Name
;
1028 string::size_type Slash
= TmpSrc
.rfind('=');
1029 if (Slash
!= string::npos
)
1031 VerTag
= string(TmpSrc
.begin() + Slash
+ 1,TmpSrc
.end());
1032 TmpSrc
= string(TmpSrc
.begin(),TmpSrc
.begin() + Slash
);
1035 /* Lookup the version of the package we would install if we were to
1036 install a version and determine the source package name, then look
1037 in the archive for a source package of the same name. In theory
1038 we could stash the version string as well and match that too but
1039 today there aren't multi source versions in the archive. */
1040 if (_config
->FindB("APT::Get::Only-Source") == false &&
1041 VerTag
.empty() == true)
1043 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(TmpSrc
);
1044 if (Pkg
.end() == false)
1046 pkgCache::VerIterator Ver
= Cache
.GetCandidateVer(Pkg
);
1047 if (Ver
.end() == false)
1049 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1050 Src
= Parse
.SourcePkg();
1055 // No source package name..
1056 if (Src
.empty() == true)
1060 pkgSrcRecords::Parser
*Last
= 0;
1061 unsigned long Offset
= 0;
1063 bool IsMatch
= false;
1065 // If we are matching by version then we need exact matches to be happy
1066 if (VerTag
.empty() == false)
1069 /* Iterate over all of the hits, which includes the resulting
1070 binary packages in the search */
1071 pkgSrcRecords::Parser
*Parse
;
1073 while ((Parse
= SrcRecs
.Find(Src
.c_str(),false)) != 0)
1075 string Ver
= Parse
->Version();
1077 // Skip name mismatches
1078 if (IsMatch
== true && Parse
->Package() != Src
)
1081 if (VerTag
.empty() == false)
1083 /* Don't want to fall through because we are doing exact version
1085 if (Cache
.VS().CmpVersion(VerTag
,Ver
) != 0)
1089 Offset
= Parse
->Offset();
1093 // Newer version or an exact match
1094 if (Last
== 0 || Cache
.VS().CmpVersion(Version
,Ver
) < 0 ||
1095 (Parse
->Package() == Src
&& IsMatch
== false))
1097 IsMatch
= Parse
->Package() == Src
;
1099 Offset
= Parse
->Offset();
1107 if (Last
->Jump(Offset
) == false)
1114 // DoUpdate - Update the package lists /*{{{*/
1115 // ---------------------------------------------------------------------
1117 bool DoUpdate(CommandLine
&CmdL
)
1119 if (CmdL
.FileSize() != 1)
1120 return _error
->Error(_("The update command takes no arguments"));
1122 // Get the source list
1124 if (List
.ReadMainList() == false)
1127 // Lock the list directory
1129 if (_config
->FindB("Debug::NoLocking",false) == false)
1131 Lock
.Fd(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
1132 if (_error
->PendingError() == true)
1133 return _error
->Error(_("Unable to lock the list directory"));
1136 // Create the download object
1137 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1138 pkgAcquire
Fetcher(&Stat
);
1140 // Populate it with the source selection
1141 if (List
.GetIndexes(&Fetcher
) == false)
1145 if (Fetcher
.Run() == pkgAcquire::Failed
)
1148 bool Failed
= false;
1149 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1151 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
1156 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1157 (*I
)->ErrorText
.c_str());
1161 // Clean out any old list files
1162 if (_config
->FindB("APT::Get::List-Cleanup",true) == true)
1164 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
1165 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
1169 // Prepare the cache.
1171 if (Cache
.Open() == false)
1175 return _error
->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
1180 // DoUpgrade - Upgrade all packages /*{{{*/
1181 // ---------------------------------------------------------------------
1182 /* Upgrade all packages without installing new packages or erasing old
1184 bool DoUpgrade(CommandLine
&CmdL
)
1187 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1191 if (pkgAllUpgrade(Cache
) == false)
1193 ShowBroken(c1out
,Cache
,false);
1194 return _error
->Error(_("Internal Error, AllUpgrade broke stuff"));
1197 return InstallPackages(Cache
,true);
1200 // DoInstall - Install packages from the command line /*{{{*/
1201 // ---------------------------------------------------------------------
1202 /* Install named packages */
1203 bool DoInstall(CommandLine
&CmdL
)
1206 if (Cache
.Open() == false || Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
1209 // Enter the special broken fixing mode if the user specified arguments
1210 bool BrokenFix
= false;
1211 if (Cache
->BrokenCount() != 0)
1214 unsigned int ExpectedInst
= 0;
1215 unsigned int Packages
= 0;
1216 pkgProblemResolver
Fix(Cache
);
1218 bool DefRemove
= false;
1219 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
1222 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1224 // Duplicate the string
1225 unsigned int Length
= strlen(*I
);
1227 if (Length
>= sizeof(S
))
1231 // See if we are removing and special indicators..
1232 bool Remove
= DefRemove
;
1234 bool VerIsRel
= false;
1235 while (Cache
->FindPkg(S
).end() == true)
1237 // Handle an optional end tag indicating what to do
1238 if (S
[Length
- 1] == '-')
1245 if (S
[Length
- 1] == '+')
1252 char *Slash
= strchr(S
,'=');
1260 Slash
= strchr(S
,'/');
1271 // Locate the package
1272 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
1274 if (Pkg
.end() == true)
1276 // Check if the name is a regex
1278 for (I
= S
; *I
!= 0; I
++)
1279 if (*I
== '.' || *I
== '?' || *I
== '*' || *I
== '|')
1282 return _error
->Error(_("Couldn't find package %s"),S
);
1284 // Regexs must always be confirmed
1285 ExpectedInst
+= 1000;
1287 // Compile the regex pattern
1290 if ((Res
= regcomp(&Pattern
,S
,REG_EXTENDED
| REG_ICASE
|
1294 regerror(Res
,&Pattern
,Error
,sizeof(Error
));
1295 return _error
->Error(_("Regex compilation error - %s"),Error
);
1298 // Run over the matches
1300 for (Pkg
= Cache
->PkgBegin(); Pkg
.end() == false; Pkg
++)
1302 if (regexec(&Pattern
,Pkg
.Name(),0,0,0) != 0)
1306 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1309 Hit
|= TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,
1310 ExpectedInst
,false);
1315 return _error
->Error(_("Couldn't find package %s"),S
);
1320 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1322 if (TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,ExpectedInst
) == false)
1327 /* If we are in the Broken fixing mode we do not attempt to fix the
1328 problems. This is if the user invoked install without -f and gave
1330 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1332 c1out
<< _("You might want to run `apt-get -f install' to correct these:") << endl
;
1333 ShowBroken(c1out
,Cache
,false);
1335 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1338 // Call the scored problem resolver
1339 Fix
.InstallProtect();
1340 if (Fix
.Resolve(true) == false)
1343 // Now we check the state of the packages,
1344 if (Cache
->BrokenCount() != 0)
1347 _("Some packages could not be installed. This may mean that you have\n"
1348 "requested an impossible situation or if you are using the unstable\n"
1349 "distribution that some required packages have not yet been created\n"
1350 "or been moved out of Incoming.") << endl
;
1355 _("Since you only requested a single operation it is extremely likely that\n"
1356 "the package is simply not installable and a bug report against\n"
1357 "that package should be filed.") << endl
;
1360 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1362 ShowBroken(c1out
,Cache
,false);
1363 return _error
->Error(_("Sorry, broken packages"));
1366 /* Print out a list of packages that are going to be installed extra
1367 to what the user asked */
1368 if (Cache
->InstCount() != ExpectedInst
)
1371 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1373 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1374 if ((*Cache
)[I
].Install() == false)
1378 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1379 if (strcmp(*J
,I
.Name()) == 0)
1383 List
+= string(I
.Name()) + " ";
1386 ShowList(c1out
,_("The following extra packages will be installed:"),List
);
1389 // See if we need to prompt
1390 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
1391 return InstallPackages(Cache
,false,false);
1393 return InstallPackages(Cache
,false);
1396 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1397 // ---------------------------------------------------------------------
1398 /* Intelligent upgrader that will install and remove packages at will */
1399 bool DoDistUpgrade(CommandLine
&CmdL
)
1402 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1405 c0out
<< _("Calculating Upgrade... ") << flush
;
1406 if (pkgDistUpgrade(*Cache
) == false)
1408 c0out
<< _("Failed") << endl
;
1409 ShowBroken(c1out
,Cache
,false);
1413 c0out
<< _("Done") << endl
;
1415 return InstallPackages(Cache
,true);
1418 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1419 // ---------------------------------------------------------------------
1420 /* Follows dselect's selections */
1421 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1424 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1427 // Install everything with the install flag set
1428 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1429 for (;I
.end() != true; I
++)
1431 /* Install the package only if it is a new install, the autoupgrader
1432 will deal with the rest */
1433 if (I
->SelectedState
== pkgCache::State::Install
)
1434 Cache
->MarkInstall(I
,false);
1437 /* Now install their deps too, if we do this above then order of
1438 the status file is significant for | groups */
1439 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1441 /* Install the package only if it is a new install, the autoupgrader
1442 will deal with the rest */
1443 if (I
->SelectedState
== pkgCache::State::Install
)
1444 Cache
->MarkInstall(I
,true);
1447 // Apply erasures now, they override everything else.
1448 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1451 if (I
->SelectedState
== pkgCache::State::DeInstall
||
1452 I
->SelectedState
== pkgCache::State::Purge
)
1453 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
1456 /* Resolve any problems that dselect created, allupgrade cannot handle
1457 such things. We do so quite agressively too.. */
1458 if (Cache
->BrokenCount() != 0)
1460 pkgProblemResolver
Fix(Cache
);
1462 // Hold back held packages.
1463 if (_config
->FindB("APT::Ignore-Hold",false) == false)
1465 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
1467 if (I
->SelectedState
== pkgCache::State::Hold
)
1475 if (Fix
.Resolve() == false)
1477 ShowBroken(c1out
,Cache
,false);
1478 return _error
->Error("Internal Error, problem resolver broke stuff");
1482 // Now upgrade everything
1483 if (pkgAllUpgrade(Cache
) == false)
1485 ShowBroken(c1out
,Cache
,false);
1486 return _error
->Error("Internal Error, problem resolver broke stuff");
1489 return InstallPackages(Cache
,false);
1492 // DoClean - Remove download archives /*{{{*/
1493 // ---------------------------------------------------------------------
1495 bool DoClean(CommandLine
&CmdL
)
1497 if (_config
->FindB("APT::Get::Simulate") == true)
1499 cout
<< "Del " << _config
->FindDir("Dir::Cache::archives") << "* " <<
1500 _config
->FindDir("Dir::Cache::archives") << "partial/*" << endl
;
1504 // Lock the archive directory
1506 if (_config
->FindB("Debug::NoLocking",false) == false)
1508 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1509 if (_error
->PendingError() == true)
1510 return _error
->Error(_("Unable to lock the download directory"));
1514 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
1515 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
1519 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
1520 // ---------------------------------------------------------------------
1521 /* This is similar to clean but it only purges things that cannot be
1522 downloaded, that is old versions of cached packages. */
1523 class LogCleaner
: public pkgArchiveCleaner
1526 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1528 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
1530 if (_config
->FindB("APT::Get::Simulate") == false)
1535 bool DoAutoClean(CommandLine
&CmdL
)
1537 // Lock the archive directory
1539 if (_config
->FindB("Debug::NoLocking",false) == false)
1541 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1542 if (_error
->PendingError() == true)
1543 return _error
->Error(_("Unable to lock the download directory"));
1547 if (Cache
.Open() == false)
1552 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1553 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1556 // DoCheck - Perform the check operation /*{{{*/
1557 // ---------------------------------------------------------------------
1558 /* Opening automatically checks the system, this command is mostly used
1560 bool DoCheck(CommandLine
&CmdL
)
1569 // DoSource - Fetch a source archive /*{{{*/
1570 // ---------------------------------------------------------------------
1571 /* Fetch souce packages */
1579 bool DoSource(CommandLine
&CmdL
)
1582 if (Cache
.Open(false) == false)
1585 if (CmdL
.FileSize() <= 1)
1586 return _error
->Error(_("Must specify at least one package to fetch source for"));
1588 // Read the source list
1590 if (List
.ReadMainList() == false)
1591 return _error
->Error(_("The list of sources could not be read."));
1593 // Create the text record parsers
1594 pkgRecords
Recs(Cache
);
1595 pkgSrcRecords
SrcRecs(List
);
1596 if (_error
->PendingError() == true)
1599 // Create the download object
1600 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1601 pkgAcquire
Fetcher(&Stat
);
1603 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
1605 // Load the requestd sources into the fetcher
1607 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1610 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1613 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1616 vector
<pkgSrcRecords::File
> Lst
;
1617 if (Last
->Files(Lst
) == false)
1620 // Load them into the fetcher
1621 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
1622 I
!= Lst
.end(); I
++)
1624 // Try to guess what sort of file it is we are getting.
1625 if (I
->Type
== "dsc")
1627 Dsc
[J
].Package
= Last
->Package();
1628 Dsc
[J
].Version
= Last
->Version();
1629 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
1632 // Diff only mode only fetches .diff files
1633 if (_config
->FindB("APT::Get::Diff-Only",false) == true &&
1637 // Tar only mode only fetches .tar files
1638 if (_config
->FindB("APT::Get::Tar-Only",false) == true &&
1642 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
1644 Last
->Index().SourceInfo(*Last
,*I
),Src
);
1648 // Display statistics
1649 double FetchBytes
= Fetcher
.FetchNeeded();
1650 double FetchPBytes
= Fetcher
.PartialPresent();
1651 double DebBytes
= Fetcher
.TotalNeeded();
1653 // Check for enough free space
1655 string OutputDir
= ".";
1656 if (statvfs(OutputDir
.c_str(),&Buf
) != 0)
1657 return _error
->Errno("statvfs","Couldn't determine free space in %s",
1659 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1660 return _error
->Error(_("Sorry, you don't have enough free space in %s"),
1664 if (DebBytes
!= FetchBytes
)
1665 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
1666 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
1668 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
1669 SizeToStr(DebBytes
).c_str());
1671 if (_config
->FindB("APT::Get::Simulate",false) == true)
1673 for (unsigned I
= 0; I
!= J
; I
++)
1674 ioprintf(cout
,_("Fetch Source %s\n"),Dsc
[I
].Package
.c_str());
1678 // Just print out the uris an exit if the --print-uris flag was used
1679 if (_config
->FindB("APT::Get::Print-URIs") == true)
1681 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1682 for (; I
!= Fetcher
.UriEnd(); I
++)
1683 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1684 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1689 if (Fetcher
.Run() == pkgAcquire::Failed
)
1692 // Print error messages
1693 bool Failed
= false;
1694 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1696 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1697 (*I
)->Complete
== true)
1700 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1701 (*I
)->ErrorText
.c_str());
1705 return _error
->Error(_("Failed to fetch some archives."));
1707 if (_config
->FindB("APT::Get::Download-only",false) == true)
1709 c1out
<< _("Download complete and in download only mode") << endl
;
1713 // Unpack the sources
1714 pid_t Process
= ExecFork();
1718 for (unsigned I
= 0; I
!= J
; I
++)
1720 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
1722 // Diff only mode only fetches .diff files
1723 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
1724 _config
->FindB("APT::Get::Tar-Only",false) == true ||
1725 Dsc
[I
].Dsc
.empty() == true)
1728 // See if the package is already unpacked
1730 if (stat(Dir
.c_str(),&Stat
) == 0 &&
1731 S_ISDIR(Stat
.st_mode
) != 0)
1733 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
1740 snprintf(S
,sizeof(S
),"%s -x %s",
1741 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
1742 Dsc
[I
].Dsc
.c_str());
1745 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
1750 // Try to compile it with dpkg-buildpackage
1751 if (_config
->FindB("APT::Get::Compile",false) == true)
1753 // Call dpkg-buildpackage
1755 snprintf(S
,sizeof(S
),"cd %s && %s %s",
1757 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
1758 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
1762 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
1771 // Wait for the subprocess
1773 while (waitpid(Process
,&Status
,0) != Process
)
1777 return _error
->Errno("waitpid","Couldn't wait for subprocess");
1780 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
1781 return _error
->Error(_("Child process failed"));
1786 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
1787 // ---------------------------------------------------------------------
1788 /* This function will look at the build depends list of the given source
1789 package and install the necessary packages to make it true, or fail. */
1790 bool DoBuildDep(CommandLine
&CmdL
)
1793 if (Cache
.Open(true) == false)
1796 if (CmdL
.FileSize() <= 1)
1797 return _error
->Error(_("Must specify at least one package to check builddeps for"));
1799 // Read the source list
1801 if (List
.ReadMainList() == false)
1802 return _error
->Error(_("The list of sources could not be read."));
1804 // Create the text record parsers
1805 pkgRecords
Recs(Cache
);
1806 pkgSrcRecords
SrcRecs(List
);
1807 if (_error
->PendingError() == true)
1810 // Create the download object
1811 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1812 pkgAcquire
Fetcher(&Stat
);
1815 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1818 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1820 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1822 // Process the build-dependencies
1823 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
1824 if (Last
->BuildDepends(BuildDeps
) == false)
1825 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
1827 if (BuildDeps
.size() == 0)
1829 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
1833 // Install the requested packages
1834 unsigned int ExpectedInst
= 0;
1835 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
1836 pkgProblemResolver
Fix(Cache
);
1837 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); D
++)
1839 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
1840 if (Pkg
.end() == true)
1841 return _error
->Error(_("%s dependency on %s cannot be satisfied because the package %s cannot be found"),
1842 Last
->BuildDepType((*D
).Type
),Src
.c_str(),(*D
).Package
.c_str());
1843 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1845 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1846 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1849 * conflict; need to remove if we have an installed version
1850 * that satisfies the version criterial
1852 if (IV
.end() == false &&
1853 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1854 TryToInstall(Pkg
,Cache
,Fix
,true,false,ExpectedInst
);
1859 * If this is a virtual package, we need to check the list of
1860 * packages that provide it and see if any of those are
1863 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
1864 for (; Prv
.end() != true; Prv
++)
1865 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
1868 if (Prv
.end() == true)
1871 * depends; need to install or upgrade if we don't have the
1872 * package installed or if the version does not satisfy the
1873 * build dep. This is complicated by the fact that if we
1874 * depend on a version lower than what we already have
1875 * installed it is not clear what should be done; in practice
1876 * this case should be rare though and right now nothing
1877 * is done about it :-(
1879 if (IV
.end() == true ||
1880 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == false)
1881 TryToInstall(Pkg
,Cache
,Fix
,false,false,ExpectedInst
);
1886 Fix
.InstallProtect();
1887 if (Fix
.Resolve(true) == false)
1890 // Now we check the state of the packages,
1891 if (Cache
->BrokenCount() != 0)
1892 return _error
->Error(_("Some broken packages were found while trying to process build-dependencies.\n"
1893 "You might want to run `apt-get -f install' to correct these."));
1896 if (InstallPackages(Cache
, false, true) == false)
1897 return _error
->Error(_("Failed to process build dependencies"));
1902 // DoMoo - Never Ask, Never Tell /*{{{*/
1903 // ---------------------------------------------------------------------
1905 bool DoMoo(CommandLine
&CmdL
)
1914 "....\"Have you mooed today?\"...\n";
1919 // ShowHelp - Show a help screen /*{{{*/
1920 // ---------------------------------------------------------------------
1922 bool ShowHelp(CommandLine
&CmdL
)
1924 ioprintf(cout
,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE
,VERSION
,
1925 COMMON_OS
,COMMON_CPU
,__DATE__
,__TIME__
);
1927 if (_config
->FindB("version") == true)
1929 cout
<< _("Supported Modules:") << endl
;
1931 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
1933 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
1934 if (_system
!= 0 && _system
->VS
== VS
)
1938 cout
<< "Ver: " << VS
->Label
<< endl
;
1940 /* Print out all the packaging systems that will work with
1942 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
1944 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
1949 if (Sys
->VS
->TestCompatibility(*VS
) == true)
1950 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
1954 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
1956 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
1957 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
1960 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
1962 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
1963 cout
<< " Idx: " << Type
->Label
<< endl
;
1970 _("Usage: apt-get [options] command\n"
1971 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
1972 " apt-get [options] source pkg1 [pkg2 ...]\n"
1974 "apt-get is a simple command line interface for downloading and\n"
1975 "installing packages. The most frequently used commands are update\n"
1979 " update - Retrieve new lists of packages\n"
1980 " upgrade - Perform an upgrade\n"
1981 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
1982 " remove - Remove packages\n"
1983 " source - Download source archives\n"
1984 " build-dep - Configure build-dependencies for source packages\n"
1985 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
1986 " dselect-upgrade - Follow dselect selections\n"
1987 " clean - Erase downloaded archive files\n"
1988 " autoclean - Erase old downloaded archive files\n"
1989 " check - Verify that there are no broken dependencies\n"
1992 " -h This help text.\n"
1993 " -q Loggable output - no progress indicator\n"
1994 " -qq No output except for errors\n"
1995 " -d Download only - do NOT install or unpack archives\n"
1996 " -s No-act. Perform ordering simulation\n"
1997 " -y Assume Yes to all queries and do not prompt\n"
1998 " -f Attempt to continue if the integrity check fails\n"
1999 " -m Attempt to continue if archives are unlocatable\n"
2000 " -u Show a list of upgraded packages as well\n"
2001 " -b Build the source package after fetching it\n"
2002 " -c=? Read this configuration file\n"
2003 " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n"
2004 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
2005 "pages for more information and options.\n"
2006 " This APT has Super Cow Powers.\n");
2010 // GetInitialize - Initialize things for apt-get /*{{{*/
2011 // ---------------------------------------------------------------------
2013 void GetInitialize()
2015 _config
->Set("quiet",0);
2016 _config
->Set("help",false);
2017 _config
->Set("APT::Get::Download-Only",false);
2018 _config
->Set("APT::Get::Simulate",false);
2019 _config
->Set("APT::Get::Assume-Yes",false);
2020 _config
->Set("APT::Get::Fix-Broken",false);
2021 _config
->Set("APT::Get::Force-Yes",false);
2022 _config
->Set("APT::Get::APT::Get::No-List-Cleanup",true);
2025 // SigWinch - Window size change signal handler /*{{{*/
2026 // ---------------------------------------------------------------------
2030 // Riped from GNU ls
2034 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
2035 ScreenWidth
= ws
.ws_col
- 1;
2040 int main(int argc
,const char *argv
[])
2042 CommandLine::Args Args
[] = {
2043 {'h',"help","help",0},
2044 {'v',"version","version",0},
2045 {'q',"quiet","quiet",CommandLine::IntLevel
},
2046 {'q',"silent","quiet",CommandLine::IntLevel
},
2047 {'d',"download-only","APT::Get::Download-Only",0},
2048 {'b',"compile","APT::Get::Compile",0},
2049 {'b',"build","APT::Get::Compile",0},
2050 {'s',"simulate","APT::Get::Simulate",0},
2051 {'s',"just-print","APT::Get::Simulate",0},
2052 {'s',"recon","APT::Get::Simulate",0},
2053 {'s',"dry-run","APT::Get::Simulate",0},
2054 {'s',"no-act","APT::Get::Simulate",0},
2055 {'y',"yes","APT::Get::Assume-Yes",0},
2056 {'y',"assume-yes","APT::Get::Assume-Yes",0},
2057 {'f',"fix-broken","APT::Get::Fix-Broken",0},
2058 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
2059 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
2060 {'t',"target-release","APT::Default-Release",CommandLine::HasArg
},
2061 {'t',"default-release","APT::Default-Release",CommandLine::HasArg
},
2062 {0,"download","APT::Get::Download",0},
2063 {0,"fix-missing","APT::Get::Fix-Missing",0},
2064 {0,"ignore-hold","APT::Ignore-Hold",0},
2065 {0,"upgrade","APT::Get::upgrade",0},
2066 {0,"force-yes","APT::Get::force-yes",0},
2067 {0,"print-uris","APT::Get::Print-URIs",0},
2068 {0,"diff-only","APT::Get::Diff-Only",0},
2069 {0,"tar-only","APT::Get::tar-Only",0},
2070 {0,"purge","APT::Get::Purge",0},
2071 {0,"list-cleanup","APT::Get::List-Cleanup",0},
2072 {0,"reinstall","APT::Get::ReInstall",0},
2073 {0,"trivial-only","APT::Get::Trivial-Only",0},
2074 {0,"remove","APT::Get::Remove",0},
2075 {0,"only-source","APT::Get::Only-Source",0},
2076 {'c',"config-file",0,CommandLine::ConfigFile
},
2077 {'o',"option",0,CommandLine::ArbItem
},
2079 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
2080 {"upgrade",&DoUpgrade
},
2081 {"install",&DoInstall
},
2082 {"remove",&DoInstall
},
2083 {"dist-upgrade",&DoDistUpgrade
},
2084 {"dselect-upgrade",&DoDSelectUpgrade
},
2085 {"build-dep",&DoBuildDep
},
2087 {"autoclean",&DoAutoClean
},
2089 {"source",&DoSource
},
2094 // Parse the command line and initialize the package library
2095 CommandLine
CmdL(Args
,_config
);
2096 if (pkgInitConfig(*_config
) == false ||
2097 CmdL
.Parse(argc
,argv
) == false ||
2098 pkgInitSystem(*_config
,_system
) == false)
2100 if (_config
->FindB("version") == true)
2103 _error
->DumpErrors();
2107 // See if the help should be shown
2108 if (_config
->FindB("help") == true ||
2109 _config
->FindB("version") == true ||
2110 CmdL
.FileSize() == 0)
2116 // Deal with stdout not being a tty
2117 if (ttyname(STDOUT_FILENO
) == 0 && _config
->FindI("quiet",0) < 1)
2118 _config
->Set("quiet","1");
2120 // Setup the output streams
2121 c0out
.rdbuf(cout
.rdbuf());
2122 c1out
.rdbuf(cout
.rdbuf());
2123 c2out
.rdbuf(cout
.rdbuf());
2124 if (_config
->FindI("quiet",0) > 0)
2125 c0out
.rdbuf(devnull
.rdbuf());
2126 if (_config
->FindI("quiet",0) > 1)
2127 c1out
.rdbuf(devnull
.rdbuf());
2129 // Setup the signals
2130 signal(SIGPIPE
,SIG_IGN
);
2131 signal(SIGWINCH
,SigWinch
);
2134 // Match the operation
2135 CmdL
.DispatchArg(Cmds
);
2137 // Print any errors or warnings found during parsing
2138 if (_error
->empty() == false)
2140 bool Errors
= _error
->PendingError();
2141 _error
->DumpErrors();
2142 return Errors
== true?100:0;