]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.119 2002/04/26 05:36:43 jgg Exp $
4 /* ######################################################################
6 apt-get - Cover for dpkg
8 This is an allout cover for dpkg implementing a safer front end. It is
9 based largely on libapt-pkg.
11 The syntax is different,
12 apt-get [opt] command [things]
14 update - Resyncronize the package files from their sources
15 upgrade - Smart-Download the newest versions of all packages
16 dselect-upgrade - Follows dselect's changes to the Status: field
17 and installes new and removes old packages
18 dist-upgrade - Powerfull upgrader designed to handle the issues with
20 install - Download and install a given package (by name, not by .deb)
21 check - Update the package cache and check for broken packages
22 clean - Erase the .debs downloaded to /var/cache/apt/archives and
25 ##################################################################### */
27 // Include Files /*{{{*/
28 #include <apt-pkg/error.h>
29 #include <apt-pkg/cmndline.h>
30 #include <apt-pkg/init.h>
31 #include <apt-pkg/depcache.h>
32 #include <apt-pkg/sourcelist.h>
33 #include <apt-pkg/algorithms.h>
34 #include <apt-pkg/acquire-item.h>
35 #include <apt-pkg/strutl.h>
36 #include <apt-pkg/clean.h>
37 #include <apt-pkg/srcrecords.h>
38 #include <apt-pkg/version.h>
39 #include <apt-pkg/cachefile.h>
40 #include <apt-pkg/sptr.h>
41 #include <apt-pkg/versionmatch.h>
46 #include "acqprogress.h"
51 #include <sys/ioctl.h>
53 #include <sys/statvfs.h>
67 ofstream
devnull("/dev/null");
68 unsigned int ScreenWidth
= 80;
70 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
71 // ---------------------------------------------------------------------
73 class CacheFile
: public pkgCacheFile
75 static pkgCache
*SortCache
;
76 static int NameComp(const void *a
,const void *b
);
79 pkgCache::Package
**List
;
82 bool CheckDeps(bool AllowBroken
= false);
83 bool Open(bool WithLock
= true)
85 OpTextProgress
Prog(*_config
);
86 if (pkgCacheFile::Open(Prog
,WithLock
) == false)
94 if (_config
->FindB("APT::Get::Print-URIs") == true)
99 CacheFile() : List(0) {};
103 // YnPrompt - Yes No Prompt. /*{{{*/
104 // ---------------------------------------------------------------------
105 /* Returns true on a Yes.*/
108 // This needs to be a capital
109 const char *Yes
= _("Y");
111 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
113 c1out
<< Yes
<< endl
;
119 if (read(STDIN_FILENO
,&C
,1) != 1)
121 while (C
!= '\n' && Jnk
!= '\n')
122 if (read(STDIN_FILENO
,&Jnk
,1) != 1)
125 if (!(toupper(C
) == *Yes
|| C
== '\n' || C
== '\r'))
130 // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
131 // ---------------------------------------------------------------------
132 /* Returns true on a Yes.*/
133 bool AnalPrompt(const char *Text
)
136 cin
.getline(Buf
,sizeof(Buf
));
137 if (strcmp(Buf
,Text
) == 0)
142 // ShowList - Show a list /*{{{*/
143 // ---------------------------------------------------------------------
144 /* This prints out a string of space separated words with a title and
145 a two space indent line wraped to the current screen width. */
146 bool ShowList(ostream
&out
,string Title
,string List
)
148 if (List
.empty() == true)
151 // Acount for the leading space
152 int ScreenWidth
= ::ScreenWidth
- 3;
154 out
<< Title
<< endl
;
155 string::size_type Start
= 0;
156 while (Start
< List
.size())
158 string::size_type End
;
159 if (Start
+ ScreenWidth
>= List
.size())
162 End
= List
.rfind(' ',Start
+ScreenWidth
);
164 if (End
== string::npos
|| End
< Start
)
165 End
= Start
+ ScreenWidth
;
166 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
172 // ShowBroken - Debugging aide /*{{{*/
173 // ---------------------------------------------------------------------
174 /* This prints out the names of all the packages that are broken along
175 with the name of each each broken dependency and a quite version
178 The output looks like:
179 Sorry, but the following packages have unmet dependencies:
180 exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed
181 Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
182 Depends: libsasl7 but it is not going to be installed
184 void ShowBroken(ostream
&out
,CacheFile
&Cache
,bool Now
)
186 out
<< _("Sorry, but the following packages have unmet dependencies:") << endl
;
187 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
189 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
193 if (Cache
[I
].NowBroken() == false)
198 if (Cache
[I
].InstBroken() == false)
202 // Print out each package and the failed dependencies
203 out
<<" " << I
.Name() << ":";
204 unsigned Indent
= strlen(I
.Name()) + 3;
206 pkgCache::VerIterator Ver
;
209 Ver
= I
.CurrentVer();
211 Ver
= Cache
[I
].InstVerIter(Cache
);
213 if (Ver
.end() == true)
219 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false;)
221 // Compute a single dependency element (glob or)
222 pkgCache::DepIterator Start
;
223 pkgCache::DepIterator End
;
226 if (Cache
->IsImportantDep(End
) == false)
231 if ((Cache
[End
] & pkgDepCache::DepGNow
) == pkgDepCache::DepGNow
)
236 if ((Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
244 for (unsigned J
= 0; J
!= Indent
; J
++)
248 if (FirstOr
== false)
250 for (unsigned J
= 0; J
!= strlen(End
.DepType()) + 3; J
++)
254 out
<< ' ' << End
.DepType() << ": ";
257 out
<< Start
.TargetPkg().Name();
259 // Show a quick summary of the version requirements
260 if (Start
.TargetVer() != 0)
261 out
<< " (" << Start
.CompType() << " " << Start
.TargetVer() << ")";
263 /* Show a summary of the target package if possible. In the case
264 of virtual packages we show nothing */
265 pkgCache::PkgIterator Targ
= Start
.TargetPkg();
266 if (Targ
->ProvidesList
== 0)
269 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
271 Ver
= Targ
.CurrentVer();
273 if (Ver
.end() == false)
276 ioprintf(out
,_("but %s is installed"),Ver
.VerStr());
278 ioprintf(out
,_("but %s is to be installed"),Ver
.VerStr());
282 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
284 if (Targ
->ProvidesList
== 0)
285 out
<< _("but it is not installable");
287 out
<< _("but it is a virtual package");
290 out
<< (Now
?_("but it is not installed"):_("but it is not going to be installed"));
306 // ShowNew - Show packages to newly install /*{{{*/
307 // ---------------------------------------------------------------------
309 void ShowNew(ostream
&out
,CacheFile
&Cache
)
311 /* Print out a list of packages that are going to be removed extra
312 to what the user asked */
314 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
316 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
317 if (Cache
[I
].NewInstall() == true)
318 List
+= string(I
.Name()) + " ";
321 ShowList(out
,_("The following NEW packages will be installed:"),List
);
324 // ShowDel - Show packages to delete /*{{{*/
325 // ---------------------------------------------------------------------
327 void ShowDel(ostream
&out
,CacheFile
&Cache
)
329 /* Print out a list of packages that are going to be removed extra
330 to what the user asked */
332 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
334 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
335 if (Cache
[I
].Delete() == true)
337 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
338 List
+= string(I
.Name()) + "* ";
340 List
+= string(I
.Name()) + " ";
344 ShowList(out
,_("The following packages will be REMOVED:"),List
);
347 // ShowKept - Show kept packages /*{{{*/
348 // ---------------------------------------------------------------------
350 void ShowKept(ostream
&out
,CacheFile
&Cache
)
353 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
355 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
358 if (Cache
[I
].Upgrade() == true || Cache
[I
].Upgradable() == false ||
359 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
362 List
+= string(I
.Name()) + " ";
364 ShowList(out
,_("The following packages have been kept back"),List
);
367 // ShowUpgraded - Show upgraded packages /*{{{*/
368 // ---------------------------------------------------------------------
370 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
373 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
375 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
378 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
381 List
+= string(I
.Name()) + " ";
383 ShowList(out
,_("The following packages will be upgraded"),List
);
386 // ShowDowngraded - Show downgraded packages /*{{{*/
387 // ---------------------------------------------------------------------
389 bool ShowDowngraded(ostream
&out
,CacheFile
&Cache
)
392 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
394 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
397 if (Cache
[I
].Downgrade() == false || Cache
[I
].NewInstall() == true)
400 List
+= string(I
.Name()) + " ";
402 return ShowList(out
,_("The following packages will be DOWNGRADED"),List
);
405 // ShowHold - Show held but changed packages /*{{{*/
406 // ---------------------------------------------------------------------
408 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
411 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
413 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
414 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
415 I
->SelectedState
== pkgCache::State::Hold
)
416 List
+= string(I
.Name()) + " ";
419 return ShowList(out
,_("The following held packages will be changed:"),List
);
422 // ShowEssential - Show an essential package warning /*{{{*/
423 // ---------------------------------------------------------------------
424 /* This prints out a warning message that is not to be ignored. It shows
425 all essential packages and their dependents that are to be removed.
426 It is insanely risky to remove the dependents of an essential package! */
427 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
430 bool *Added
= new bool[Cache
->Head().PackageCount
];
431 for (unsigned int I
= 0; I
!= Cache
->Head().PackageCount
; I
++)
434 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
436 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
437 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
&&
438 (I
->Flags
& pkgCache::Flag::Important
) != pkgCache::Flag::Important
)
441 // The essential package is being removed
442 if (Cache
[I
].Delete() == true)
444 if (Added
[I
->ID
] == false)
447 List
+= string(I
.Name()) + " ";
451 if (I
->CurrentVer
== 0)
454 // Print out any essential package depenendents that are to be removed
455 for (pkgCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
457 // Skip everything but depends
458 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
459 D
->Type
!= pkgCache::Dep::Depends
)
462 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
463 if (Cache
[P
].Delete() == true)
465 if (Added
[P
->ID
] == true)
470 snprintf(S
,sizeof(S
),_("%s (due to %s) "),P
.Name(),I
.Name());
477 return ShowList(out
,_("WARNING: The following essential packages will be removed\n"
478 "This should NOT be done unless you know exactly what you are doing!"),List
);
481 // Stats - Show some statistics /*{{{*/
482 // ---------------------------------------------------------------------
484 void Stats(ostream
&out
,pkgDepCache
&Dep
)
486 unsigned long Upgrade
= 0;
487 unsigned long Downgrade
= 0;
488 unsigned long Install
= 0;
489 unsigned long ReInstall
= 0;
490 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
492 if (Dep
[I
].NewInstall() == true)
496 if (Dep
[I
].Upgrade() == true)
499 if (Dep
[I
].Downgrade() == true)
503 if (Dep
[I
].Delete() == false && (Dep
[I
].iFlags
& pkgDepCache::ReInstall
) == pkgDepCache::ReInstall
)
507 ioprintf(out
,_("%lu packages upgraded, %lu newly installed, "),
511 ioprintf(out
,_("%lu reinstalled, "),ReInstall
);
513 ioprintf(out
,_("%lu downgraded, "),Downgrade
);
515 ioprintf(out
,_("%lu to remove and %lu not upgraded.\n"),
516 Dep
.DelCount(),Dep
.KeepCount());
518 if (Dep
.BadCount() != 0)
519 ioprintf(out
,_("%lu packages not fully installed or removed.\n"),
524 // CacheFile::NameComp - QSort compare by name /*{{{*/
525 // ---------------------------------------------------------------------
527 pkgCache
*CacheFile::SortCache
= 0;
528 int CacheFile::NameComp(const void *a
,const void *b
)
530 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
531 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
533 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
534 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
536 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
539 // CacheFile::Sort - Sort by name /*{{{*/
540 // ---------------------------------------------------------------------
542 void CacheFile::Sort()
545 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
546 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
547 pkgCache::PkgIterator I
= Cache
->PkgBegin();
548 for (;I
.end() != true; I
++)
552 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
555 // CacheFile::CheckDeps - Open the cache file /*{{{*/
556 // ---------------------------------------------------------------------
557 /* This routine generates the caches and then opens the dependency cache
558 and verifies that the system is OK. */
559 bool CacheFile::CheckDeps(bool AllowBroken
)
561 if (_error
->PendingError() == true)
564 // Check that the system is OK
565 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
566 return _error
->Error("Internal Error, non-zero counts");
568 // Apply corrections for half-installed packages
569 if (pkgApplyStatus(*DCache
) == false)
573 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
576 // Attempt to fix broken things
577 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
579 c1out
<< _("Correcting dependencies...") << flush
;
580 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
582 c1out
<< _(" failed.") << endl
;
583 ShowBroken(c1out
,*this,true);
585 return _error
->Error(_("Unable to correct dependencies"));
587 if (pkgMinimizeUpgrade(*DCache
) == false)
588 return _error
->Error(_("Unable to minimize the upgrade set"));
590 c1out
<< _(" Done") << endl
;
594 c1out
<< _("You might want to run `apt-get -f install' to correct these.") << endl
;
595 ShowBroken(c1out
,*this,true);
597 return _error
->Error(_("Unmet dependencies. Try using -f."));
604 // InstallPackages - Actually download and install the packages /*{{{*/
605 // ---------------------------------------------------------------------
606 /* This displays the informative messages describing what is going to
607 happen and then calls the download routines */
608 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,
611 if (_config
->FindB("APT::Get::Purge",false) == true)
613 pkgCache::PkgIterator I
= Cache
->PkgBegin();
614 for (; I
.end() == false; I
++)
616 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
617 Cache
->MarkDelete(I
,true);
622 bool Essential
= false;
624 // Show all the various warning indicators
625 ShowDel(c1out
,Cache
);
626 ShowNew(c1out
,Cache
);
628 ShowKept(c1out
,Cache
);
629 Fail
|= !ShowHold(c1out
,Cache
);
630 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
631 ShowUpgraded(c1out
,Cache
);
632 Fail
|= !ShowDowngraded(c1out
,Cache
);
633 Essential
= !ShowEssential(c1out
,Cache
);
638 if (Cache
->BrokenCount() != 0)
640 ShowBroken(c1out
,Cache
,false);
641 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
644 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
645 Cache
->BadCount() == 0)
649 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::Remove",true) == false)
650 return _error
->Error(_("Packages need to be removed but Remove is disabled."));
652 // Run the simulator ..
653 if (_config
->FindB("APT::Get::Simulate") == true)
655 pkgSimulate
PM(Cache
);
656 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
657 if (Res
== pkgPackageManager::Failed
)
659 if (Res
!= pkgPackageManager::Completed
)
660 return _error
->Error("Internal Error, Ordering didn't finish");
664 // Create the text record parser
665 pkgRecords
Recs(Cache
);
666 if (_error
->PendingError() == true)
669 // Lock the archive directory
671 if (_config
->FindB("Debug::NoLocking",false) == false &&
672 _config
->FindB("APT::Get::Print-URIs") == false)
674 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
675 if (_error
->PendingError() == true)
676 return _error
->Error(_("Unable to lock the download directory"));
679 // Create the download object
680 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
681 pkgAcquire
Fetcher(&Stat
);
683 // Read the source list
685 if (List
.ReadMainList() == false)
686 return _error
->Error(_("The list of sources could not be read."));
688 // Create the package manager and prepare to download
689 SPtr
<pkgPackageManager
> PM
= _system
->CreatePM(Cache
);
690 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false ||
691 _error
->PendingError() == true)
694 // Display statistics
695 double FetchBytes
= Fetcher
.FetchNeeded();
696 double FetchPBytes
= Fetcher
.PartialPresent();
697 double DebBytes
= Fetcher
.TotalNeeded();
698 if (DebBytes
!= Cache
->DebSize())
700 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
701 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
705 if (DebBytes
!= FetchBytes
)
706 ioprintf(c1out
,_("Need to get %sB/%sB of archives. "),
707 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
709 ioprintf(c1out
,_("Need to get %sB of archives. "),
710 SizeToStr(DebBytes
).c_str());
713 if (Cache
->UsrSize() >= 0)
714 ioprintf(c1out
,_("After unpacking %sB will be used.\n"),
715 SizeToStr(Cache
->UsrSize()).c_str());
717 ioprintf(c1out
,_("After unpacking %sB will be freed.\n"),
718 SizeToStr(-1*Cache
->UsrSize()).c_str());
720 if (_error
->PendingError() == true)
723 /* Check for enough free space, but only if we are actually going to
725 if (_config
->FindB("APT::Get::Print-URIs") == false &&
726 _config
->FindB("APT::Get::Download",true) == true)
729 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
730 if (statvfs(OutputDir
.c_str(),&Buf
) != 0)
731 return _error
->Errno("statvfs","Couldn't determine free space in %s",
733 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
734 return _error
->Error(_("Sorry, you don't have enough free space in %s to hold all the .debs."),
739 if (_config
->FindI("quiet",0) >= 2 ||
740 _config
->FindB("APT::Get::Assume-Yes",false) == true)
742 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
743 return _error
->Error(_("There are problems and -y was used without --force-yes"));
746 if (Essential
== true && Saftey
== true)
748 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
749 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
751 const char *Prompt
= _("Yes, do as I say!");
753 _("You are about to do something potentially harmful\n"
754 "To continue type in the phrase '%s'\n"
757 if (AnalPrompt(Prompt
) == false)
759 c2out
<< _("Abort.") << endl
;
765 // Prompt to continue
766 if (Ask
== true || Fail
== true)
768 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
769 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
771 if (_config
->FindI("quiet",0) < 2 &&
772 _config
->FindB("APT::Get::Assume-Yes",false) == false)
774 c2out
<< _("Do you want to continue? [Y/n] ") << flush
;
776 if (YnPrompt() == false)
778 c2out
<< _("Abort.") << endl
;
785 // Just print out the uris an exit if the --print-uris flag was used
786 if (_config
->FindB("APT::Get::Print-URIs") == true)
788 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
789 for (; I
!= Fetcher
.UriEnd(); I
++)
790 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
791 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
795 /* Unlock the dpkg lock if we are not going to be doing an install
797 if (_config
->FindB("APT::Get::Download-Only",false) == true)
803 bool Transient
= false;
804 if (_config
->FindB("APT::Get::Download",true) == false)
806 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
808 if ((*I
)->Local
== true)
814 // Close the item and check if it was found in cache
816 if ((*I
)->Complete
== false)
819 // Clear it out of the fetch list
821 I
= Fetcher
.ItemsBegin();
825 if (Fetcher
.Run() == pkgAcquire::Failed
)
830 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
832 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
833 (*I
)->Complete
== true)
836 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
843 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
844 (*I
)->ErrorText
.c_str());
848 /* If we are in no download mode and missing files and there were
849 'failures' then the user must specify -m. Furthermore, there
850 is no such thing as a transient error in no-download mode! */
851 if (Transient
== true &&
852 _config
->FindB("APT::Get::Download",true) == false)
858 if (_config
->FindB("APT::Get::Download-Only",false) == true)
860 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
861 return _error
->Error(_("Some files failed to download"));
862 c1out
<< _("Download complete and in download only mode") << endl
;
866 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
868 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
871 if (Transient
== true && Failed
== true)
872 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
874 // Try to deal with missing package files
875 if (Failed
== true && PM
->FixMissing() == false)
877 cerr
<< _("Unable to correct missing packages.") << endl
;
878 return _error
->Error(_("Aborting Install."));
882 pkgPackageManager::OrderResult Res
= PM
->DoInstall();
883 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
885 if (Res
== pkgPackageManager::Completed
)
888 // Reload the fetcher object and loop again for media swapping
890 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false)
897 // TryToInstall - Try to install a single package /*{{{*/
898 // ---------------------------------------------------------------------
899 /* This used to be inlined in DoInstall, but with the advent of regex package
900 name matching it was split out.. */
901 bool TryToInstall(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
902 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
903 unsigned int &ExpectedInst
,bool AllowFail
= true)
905 /* This is a pure virtual package and there is a single available
907 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0 &&
908 Pkg
.ProvidesList()->NextProvides
== 0)
910 pkgCache::PkgIterator Tmp
= Pkg
.ProvidesList().OwnerPkg();
911 ioprintf(c1out
,_("Note, selecting %s instead of %s\n"),
912 Tmp
.Name(),Pkg
.Name());
916 // Handle the no-upgrade case
917 if (_config
->FindB("APT::Get::upgrade",true) == false &&
918 Pkg
->CurrentVer
!= 0)
920 if (AllowFail
== true)
921 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
926 // Check if there is something at all to install
927 pkgDepCache::StateCache
&State
= Cache
[Pkg
];
928 if (Remove
== true && Pkg
->CurrentVer
== 0)
934 /* We want to continue searching for regex hits, so we return false here
935 otherwise this is not really an error. */
936 if (AllowFail
== false)
939 ioprintf(c1out
,_("Package %s is not installed, so not removed\n"),Pkg
.Name());
943 if (State
.CandidateVer
== 0 && Remove
== false)
945 if (AllowFail
== false)
948 if (Pkg
->ProvidesList
!= 0)
950 ioprintf(c1out
,_("Package %s is a virtual package provided by:\n"),
953 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
954 for (; I
.end() == false; I
++)
956 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
958 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer())
960 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
961 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
962 _(" [Installed]") << endl
;
964 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
967 c1out
<< _("You should explicitly select one to install.") << endl
;
972 _("Package %s has no available version, but exists in the database.\n"
973 "This typically means that the package was mentioned in a dependency and\n"
974 "never uploaded, has been obsoleted or is not available with the contents\n"
975 "of sources.list\n"),Pkg
.Name());
978 SPtrArray
<bool> Seen
= new bool[Cache
.Head().PackageCount
];
979 memset(Seen
,0,Cache
.Head().PackageCount
*sizeof(*Seen
));
980 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
981 for (; Dep
.end() == false; Dep
++)
983 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
985 if (Seen
[Dep
.ParentPkg()->ID
] == true)
987 Seen
[Dep
.ParentPkg()->ID
] = true;
988 List
+= string(Dep
.ParentPkg().Name()) + " ";
990 ShowList(c1out
,_("However the following packages replace it:"),List
);
993 _error
->Error(_("Package %s has no installation candidate"),Pkg
.Name());
1002 Cache
.MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
1007 Cache
.MarkInstall(Pkg
,false);
1008 if (State
.Install() == false)
1010 if (_config
->FindB("APT::Get::ReInstall",false) == true)
1012 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
1013 ioprintf(c1out
,_("Sorry, re-installation of %s is not possible, it cannot be downloaded.\n"),
1016 Cache
.SetReInstall(Pkg
,true);
1020 if (AllowFail
== true)
1021 ioprintf(c1out
,_("Sorry, %s is already the newest version.\n"),
1028 // Install it with autoinstalling enabled.
1029 if (State
.InstBroken() == true && BrokenFix
== false)
1030 Cache
.MarkInstall(Pkg
,true);
1034 // TryToChangeVer - Try to change a candidate version /*{{{*/
1035 // ---------------------------------------------------------------------
1037 bool TryToChangeVer(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
1038 const char *VerTag
,bool IsRel
)
1040 pkgVersionMatch
Match(VerTag
,(IsRel
== true?pkgVersionMatch::Release
:
1041 pkgVersionMatch::Version
));
1043 pkgCache::VerIterator Ver
= Match
.Find(Pkg
);
1045 if (Ver
.end() == true)
1048 return _error
->Error(_("Release '%s' for '%s' was not found"),
1050 return _error
->Error(_("Version '%s' for '%s' was not found"),
1054 if (strcmp(VerTag
,Ver
.VerStr()) != 0)
1056 ioprintf(c1out
,_("Selected version %s (%s) for %s\n"),
1057 Ver
.VerStr(),Ver
.RelStr().c_str(),Pkg
.Name());
1060 Cache
.SetCandidateVersion(Ver
);
1064 // FindSrc - Find a source record /*{{{*/
1065 // ---------------------------------------------------------------------
1067 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
1068 pkgSrcRecords
&SrcRecs
,string
&Src
,
1071 // We want to pull the version off the package specification..
1073 string TmpSrc
= Name
;
1074 string::size_type Slash
= TmpSrc
.rfind('=');
1075 if (Slash
!= string::npos
)
1077 VerTag
= string(TmpSrc
.begin() + Slash
+ 1,TmpSrc
.end());
1078 TmpSrc
= string(TmpSrc
.begin(),TmpSrc
.begin() + Slash
);
1081 /* Lookup the version of the package we would install if we were to
1082 install a version and determine the source package name, then look
1083 in the archive for a source package of the same name. In theory
1084 we could stash the version string as well and match that too but
1085 today there aren't multi source versions in the archive. */
1086 if (_config
->FindB("APT::Get::Only-Source") == false &&
1087 VerTag
.empty() == true)
1089 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(TmpSrc
);
1090 if (Pkg
.end() == false)
1092 pkgCache::VerIterator Ver
= Cache
.GetCandidateVer(Pkg
);
1093 if (Ver
.end() == false)
1095 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1096 Src
= Parse
.SourcePkg();
1101 // No source package name..
1102 if (Src
.empty() == true)
1106 pkgSrcRecords::Parser
*Last
= 0;
1107 unsigned long Offset
= 0;
1109 bool IsMatch
= false;
1111 // If we are matching by version then we need exact matches to be happy
1112 if (VerTag
.empty() == false)
1115 /* Iterate over all of the hits, which includes the resulting
1116 binary packages in the search */
1117 pkgSrcRecords::Parser
*Parse
;
1119 while ((Parse
= SrcRecs
.Find(Src
.c_str(),false)) != 0)
1121 string Ver
= Parse
->Version();
1123 // Skip name mismatches
1124 if (IsMatch
== true && Parse
->Package() != Src
)
1127 if (VerTag
.empty() == false)
1129 /* Don't want to fall through because we are doing exact version
1131 if (Cache
.VS().CmpVersion(VerTag
,Ver
) != 0)
1135 Offset
= Parse
->Offset();
1139 // Newer version or an exact match
1140 if (Last
== 0 || Cache
.VS().CmpVersion(Version
,Ver
) < 0 ||
1141 (Parse
->Package() == Src
&& IsMatch
== false))
1143 IsMatch
= Parse
->Package() == Src
;
1145 Offset
= Parse
->Offset();
1153 if (Last
->Jump(Offset
) == false)
1160 // DoUpdate - Update the package lists /*{{{*/
1161 // ---------------------------------------------------------------------
1163 bool DoUpdate(CommandLine
&CmdL
)
1165 if (CmdL
.FileSize() != 1)
1166 return _error
->Error(_("The update command takes no arguments"));
1168 // Get the source list
1170 if (List
.ReadMainList() == false)
1173 // Lock the list directory
1175 if (_config
->FindB("Debug::NoLocking",false) == false)
1177 Lock
.Fd(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
1178 if (_error
->PendingError() == true)
1179 return _error
->Error(_("Unable to lock the list directory"));
1182 // Create the download object
1183 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1184 pkgAcquire
Fetcher(&Stat
);
1186 // Populate it with the source selection
1187 if (List
.GetIndexes(&Fetcher
) == false)
1190 // Just print out the uris an exit if the --print-uris flag was used
1191 if (_config
->FindB("APT::Get::Print-URIs") == true)
1193 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1194 for (; I
!= Fetcher
.UriEnd(); I
++)
1195 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1196 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1201 if (Fetcher
.Run() == pkgAcquire::Failed
)
1204 bool Failed
= false;
1205 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1207 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
1212 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1213 (*I
)->ErrorText
.c_str());
1217 // Clean out any old list files
1218 if (_config
->FindB("APT::Get::List-Cleanup",true) == true)
1220 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
1221 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
1225 // Prepare the cache.
1227 if (Cache
.Open() == false)
1231 return _error
->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
1236 // DoUpgrade - Upgrade all packages /*{{{*/
1237 // ---------------------------------------------------------------------
1238 /* Upgrade all packages without installing new packages or erasing old
1240 bool DoUpgrade(CommandLine
&CmdL
)
1243 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1247 if (pkgAllUpgrade(Cache
) == false)
1249 ShowBroken(c1out
,Cache
,false);
1250 return _error
->Error(_("Internal Error, AllUpgrade broke stuff"));
1253 return InstallPackages(Cache
,true);
1256 // DoInstall - Install packages from the command line /*{{{*/
1257 // ---------------------------------------------------------------------
1258 /* Install named packages */
1259 bool DoInstall(CommandLine
&CmdL
)
1262 if (Cache
.OpenForInstall() == false ||
1263 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
1266 // Enter the special broken fixing mode if the user specified arguments
1267 bool BrokenFix
= false;
1268 if (Cache
->BrokenCount() != 0)
1271 unsigned int ExpectedInst
= 0;
1272 unsigned int Packages
= 0;
1273 pkgProblemResolver
Fix(Cache
);
1275 bool DefRemove
= false;
1276 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
1279 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1281 // Duplicate the string
1282 unsigned int Length
= strlen(*I
);
1284 if (Length
>= sizeof(S
))
1288 // See if we are removing and special indicators..
1289 bool Remove
= DefRemove
;
1291 bool VerIsRel
= false;
1292 while (Cache
->FindPkg(S
).end() == true)
1294 // Handle an optional end tag indicating what to do
1295 if (S
[Length
- 1] == '-')
1302 if (S
[Length
- 1] == '+')
1309 char *Slash
= strchr(S
,'=');
1317 Slash
= strchr(S
,'/');
1328 // Locate the package
1329 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
1331 if (Pkg
.end() == true)
1333 // Check if the name is a regex
1335 for (I
= S
; *I
!= 0; I
++)
1336 if (*I
== '.' || *I
== '?' || *I
== '*' || *I
== '|')
1339 return _error
->Error(_("Couldn't find package %s"),S
);
1341 // Regexs must always be confirmed
1342 ExpectedInst
+= 1000;
1344 // Compile the regex pattern
1347 if ((Res
= regcomp(&Pattern
,S
,REG_EXTENDED
| REG_ICASE
|
1351 regerror(Res
,&Pattern
,Error
,sizeof(Error
));
1352 return _error
->Error(_("Regex compilation error - %s"),Error
);
1355 // Run over the matches
1357 for (Pkg
= Cache
->PkgBegin(); Pkg
.end() == false; Pkg
++)
1359 if (regexec(&Pattern
,Pkg
.Name(),0,0,0) != 0)
1363 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1366 Hit
|= TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,
1367 ExpectedInst
,false);
1372 return _error
->Error(_("Couldn't find package %s"),S
);
1377 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1379 if (TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,ExpectedInst
) == false)
1384 /* If we are in the Broken fixing mode we do not attempt to fix the
1385 problems. This is if the user invoked install without -f and gave
1387 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1389 c1out
<< _("You might want to run `apt-get -f install' to correct these:") << endl
;
1390 ShowBroken(c1out
,Cache
,false);
1392 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1395 // Call the scored problem resolver
1396 Fix
.InstallProtect();
1397 if (Fix
.Resolve(true) == false)
1400 // Now we check the state of the packages,
1401 if (Cache
->BrokenCount() != 0)
1404 _("Some packages could not be installed. This may mean that you have\n"
1405 "requested an impossible situation or if you are using the unstable\n"
1406 "distribution that some required packages have not yet been created\n"
1407 "or been moved out of Incoming.") << endl
;
1412 _("Since you only requested a single operation it is extremely likely that\n"
1413 "the package is simply not installable and a bug report against\n"
1414 "that package should be filed.") << endl
;
1417 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1419 ShowBroken(c1out
,Cache
,false);
1420 return _error
->Error(_("Sorry, broken packages"));
1423 /* Print out a list of packages that are going to be installed extra
1424 to what the user asked */
1425 if (Cache
->InstCount() != ExpectedInst
)
1428 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1430 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1431 if ((*Cache
)[I
].Install() == false)
1435 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1436 if (strcmp(*J
,I
.Name()) == 0)
1440 List
+= string(I
.Name()) + " ";
1443 ShowList(c1out
,_("The following extra packages will be installed:"),List
);
1446 // See if we need to prompt
1447 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
1448 return InstallPackages(Cache
,false,false);
1450 return InstallPackages(Cache
,false);
1453 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1454 // ---------------------------------------------------------------------
1455 /* Intelligent upgrader that will install and remove packages at will */
1456 bool DoDistUpgrade(CommandLine
&CmdL
)
1459 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1462 c0out
<< _("Calculating Upgrade... ") << flush
;
1463 if (pkgDistUpgrade(*Cache
) == false)
1465 c0out
<< _("Failed") << endl
;
1466 ShowBroken(c1out
,Cache
,false);
1470 c0out
<< _("Done") << endl
;
1472 return InstallPackages(Cache
,true);
1475 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1476 // ---------------------------------------------------------------------
1477 /* Follows dselect's selections */
1478 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1481 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1484 // Install everything with the install flag set
1485 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1486 for (;I
.end() != true; I
++)
1488 /* Install the package only if it is a new install, the autoupgrader
1489 will deal with the rest */
1490 if (I
->SelectedState
== pkgCache::State::Install
)
1491 Cache
->MarkInstall(I
,false);
1494 /* Now install their deps too, if we do this above then order of
1495 the status file is significant for | groups */
1496 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1498 /* Install the package only if it is a new install, the autoupgrader
1499 will deal with the rest */
1500 if (I
->SelectedState
== pkgCache::State::Install
)
1501 Cache
->MarkInstall(I
,true);
1504 // Apply erasures now, they override everything else.
1505 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1508 if (I
->SelectedState
== pkgCache::State::DeInstall
||
1509 I
->SelectedState
== pkgCache::State::Purge
)
1510 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
1513 /* Resolve any problems that dselect created, allupgrade cannot handle
1514 such things. We do so quite agressively too.. */
1515 if (Cache
->BrokenCount() != 0)
1517 pkgProblemResolver
Fix(Cache
);
1519 // Hold back held packages.
1520 if (_config
->FindB("APT::Ignore-Hold",false) == false)
1522 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
1524 if (I
->SelectedState
== pkgCache::State::Hold
)
1532 if (Fix
.Resolve() == false)
1534 ShowBroken(c1out
,Cache
,false);
1535 return _error
->Error("Internal Error, problem resolver broke stuff");
1539 // Now upgrade everything
1540 if (pkgAllUpgrade(Cache
) == false)
1542 ShowBroken(c1out
,Cache
,false);
1543 return _error
->Error("Internal Error, problem resolver broke stuff");
1546 return InstallPackages(Cache
,false);
1549 // DoClean - Remove download archives /*{{{*/
1550 // ---------------------------------------------------------------------
1552 bool DoClean(CommandLine
&CmdL
)
1554 if (_config
->FindB("APT::Get::Simulate") == true)
1556 cout
<< "Del " << _config
->FindDir("Dir::Cache::archives") << "* " <<
1557 _config
->FindDir("Dir::Cache::archives") << "partial/*" << endl
;
1561 // Lock the archive directory
1563 if (_config
->FindB("Debug::NoLocking",false) == false)
1565 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1566 if (_error
->PendingError() == true)
1567 return _error
->Error(_("Unable to lock the download directory"));
1571 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
1572 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
1576 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
1577 // ---------------------------------------------------------------------
1578 /* This is similar to clean but it only purges things that cannot be
1579 downloaded, that is old versions of cached packages. */
1580 class LogCleaner
: public pkgArchiveCleaner
1583 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1585 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
1587 if (_config
->FindB("APT::Get::Simulate") == false)
1592 bool DoAutoClean(CommandLine
&CmdL
)
1594 // Lock the archive directory
1596 if (_config
->FindB("Debug::NoLocking",false) == false)
1598 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1599 if (_error
->PendingError() == true)
1600 return _error
->Error(_("Unable to lock the download directory"));
1604 if (Cache
.Open() == false)
1609 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1610 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1613 // DoCheck - Perform the check operation /*{{{*/
1614 // ---------------------------------------------------------------------
1615 /* Opening automatically checks the system, this command is mostly used
1617 bool DoCheck(CommandLine
&CmdL
)
1626 // DoSource - Fetch a source archive /*{{{*/
1627 // ---------------------------------------------------------------------
1628 /* Fetch souce packages */
1636 bool DoSource(CommandLine
&CmdL
)
1639 if (Cache
.Open(false) == false)
1642 if (CmdL
.FileSize() <= 1)
1643 return _error
->Error(_("Must specify at least one package to fetch source for"));
1645 // Read the source list
1647 if (List
.ReadMainList() == false)
1648 return _error
->Error(_("The list of sources could not be read."));
1650 // Create the text record parsers
1651 pkgRecords
Recs(Cache
);
1652 pkgSrcRecords
SrcRecs(List
);
1653 if (_error
->PendingError() == true)
1656 // Create the download object
1657 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1658 pkgAcquire
Fetcher(&Stat
);
1660 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
1662 // Load the requestd sources into the fetcher
1664 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1667 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1670 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1673 vector
<pkgSrcRecords::File
> Lst
;
1674 if (Last
->Files(Lst
) == false)
1677 // Load them into the fetcher
1678 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
1679 I
!= Lst
.end(); I
++)
1681 // Try to guess what sort of file it is we are getting.
1682 if (I
->Type
== "dsc")
1684 Dsc
[J
].Package
= Last
->Package();
1685 Dsc
[J
].Version
= Last
->Version();
1686 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
1689 // Diff only mode only fetches .diff files
1690 if (_config
->FindB("APT::Get::Diff-Only",false) == true &&
1694 // Tar only mode only fetches .tar files
1695 if (_config
->FindB("APT::Get::Tar-Only",false) == true &&
1699 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
1701 Last
->Index().SourceInfo(*Last
,*I
),Src
);
1705 // Display statistics
1706 double FetchBytes
= Fetcher
.FetchNeeded();
1707 double FetchPBytes
= Fetcher
.PartialPresent();
1708 double DebBytes
= Fetcher
.TotalNeeded();
1710 // Check for enough free space
1712 string OutputDir
= ".";
1713 if (statvfs(OutputDir
.c_str(),&Buf
) != 0)
1714 return _error
->Errno("statvfs","Couldn't determine free space in %s",
1716 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1717 return _error
->Error(_("Sorry, you don't have enough free space in %s"),
1721 if (DebBytes
!= FetchBytes
)
1722 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
1723 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
1725 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
1726 SizeToStr(DebBytes
).c_str());
1728 if (_config
->FindB("APT::Get::Simulate",false) == true)
1730 for (unsigned I
= 0; I
!= J
; I
++)
1731 ioprintf(cout
,_("Fetch Source %s\n"),Dsc
[I
].Package
.c_str());
1735 // Just print out the uris an exit if the --print-uris flag was used
1736 if (_config
->FindB("APT::Get::Print-URIs") == true)
1738 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1739 for (; I
!= Fetcher
.UriEnd(); I
++)
1740 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1741 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1746 if (Fetcher
.Run() == pkgAcquire::Failed
)
1749 // Print error messages
1750 bool Failed
= false;
1751 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1753 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1754 (*I
)->Complete
== true)
1757 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1758 (*I
)->ErrorText
.c_str());
1762 return _error
->Error(_("Failed to fetch some archives."));
1764 if (_config
->FindB("APT::Get::Download-only",false) == true)
1766 c1out
<< _("Download complete and in download only mode") << endl
;
1770 // Unpack the sources
1771 pid_t Process
= ExecFork();
1775 for (unsigned I
= 0; I
!= J
; I
++)
1777 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
1779 // Diff only mode only fetches .diff files
1780 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
1781 _config
->FindB("APT::Get::Tar-Only",false) == true ||
1782 Dsc
[I
].Dsc
.empty() == true)
1785 // See if the package is already unpacked
1787 if (stat(Dir
.c_str(),&Stat
) == 0 &&
1788 S_ISDIR(Stat
.st_mode
) != 0)
1790 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
1797 snprintf(S
,sizeof(S
),"%s -x %s",
1798 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
1799 Dsc
[I
].Dsc
.c_str());
1802 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
1807 // Try to compile it with dpkg-buildpackage
1808 if (_config
->FindB("APT::Get::Compile",false) == true)
1810 // Call dpkg-buildpackage
1812 snprintf(S
,sizeof(S
),"cd %s && %s %s",
1814 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
1815 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
1819 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
1828 // Wait for the subprocess
1830 while (waitpid(Process
,&Status
,0) != Process
)
1834 return _error
->Errno("waitpid","Couldn't wait for subprocess");
1837 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
1838 return _error
->Error(_("Child process failed"));
1843 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
1844 // ---------------------------------------------------------------------
1845 /* This function will look at the build depends list of the given source
1846 package and install the necessary packages to make it true, or fail. */
1847 bool DoBuildDep(CommandLine
&CmdL
)
1850 if (Cache
.Open(true) == false)
1853 if (CmdL
.FileSize() <= 1)
1854 return _error
->Error(_("Must specify at least one package to check builddeps for"));
1856 // Read the source list
1858 if (List
.ReadMainList() == false)
1859 return _error
->Error(_("The list of sources could not be read."));
1861 // Create the text record parsers
1862 pkgRecords
Recs(Cache
);
1863 pkgSrcRecords
SrcRecs(List
);
1864 if (_error
->PendingError() == true)
1867 // Create the download object
1868 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1869 pkgAcquire
Fetcher(&Stat
);
1872 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1875 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1877 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1879 // Process the build-dependencies
1880 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
1881 if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only",false)) == false)
1882 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
1884 // Also ensure that build-essential packages are present
1885 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
1888 for (; Opts
; Opts
= Opts
->Next
)
1890 if (Opts
->Value
.empty() == true)
1893 pkgSrcRecords::Parser::BuildDepRec rec
;
1894 rec
.Package
= Opts
->Value
;
1895 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
1897 BuildDeps
.insert(BuildDeps
.begin(), rec
);
1900 if (BuildDeps
.size() == 0)
1902 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
1906 // Install the requested packages
1907 unsigned int ExpectedInst
= 0;
1908 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
1909 pkgProblemResolver
Fix(Cache
);
1910 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); D
++)
1912 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
1913 if (Pkg
.end() == true)
1915 /* for a build-conflict; ignore unknown packages */
1916 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1917 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1920 return _error
->Error(_("%s dependency on %s cannot be satisfied because the package %s cannot be found"),
1921 Last
->BuildDepType((*D
).Type
),Src
.c_str(),(*D
).Package
.c_str());
1923 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1925 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1926 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1929 * conflict; need to remove if we have an installed version
1930 * that satisfies the version criterial
1932 if (IV
.end() == false &&
1933 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1934 TryToInstall(Pkg
,Cache
,Fix
,true,false,ExpectedInst
);
1939 * If this is a virtual package, we need to check the list of
1940 * packages that provide it and see if any of those are
1943 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
1944 for (; Prv
.end() != true; Prv
++)
1945 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
1948 if (Prv
.end() == true)
1951 * depends; need to install or upgrade if we don't have the
1952 * package installed or if the version does not satisfy the
1953 * build dep. This is complicated by the fact that if we
1954 * depend on a version lower than what we already have
1955 * installed it is not clear what should be done; in practice
1956 * this case should be rare though and right now nothing
1957 * is done about it :-(
1959 if (IV
.end() == true ||
1960 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == false)
1961 TryToInstall(Pkg
,Cache
,Fix
,false,false,ExpectedInst
);
1966 Fix
.InstallProtect();
1967 if (Fix
.Resolve(true) == false)
1970 // Now we check the state of the packages,
1971 if (Cache
->BrokenCount() != 0)
1972 return _error
->Error(_("Some broken packages were found while trying to process build-dependencies.\n"
1973 "You might want to run `apt-get -f install' to correct these."));
1976 if (InstallPackages(Cache
, false, true) == false)
1977 return _error
->Error(_("Failed to process build dependencies"));
1982 // DoMoo - Never Ask, Never Tell /*{{{*/
1983 // ---------------------------------------------------------------------
1985 bool DoMoo(CommandLine
&CmdL
)
1994 "....\"Have you mooed today?\"...\n";
1999 // ShowHelp - Show a help screen /*{{{*/
2000 // ---------------------------------------------------------------------
2002 bool ShowHelp(CommandLine
&CmdL
)
2004 ioprintf(cout
,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE
,VERSION
,
2005 COMMON_OS
,COMMON_CPU
,__DATE__
,__TIME__
);
2007 if (_config
->FindB("version") == true)
2009 cout
<< _("Supported Modules:") << endl
;
2011 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
2013 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
2014 if (_system
!= 0 && _system
->VS
== VS
)
2018 cout
<< "Ver: " << VS
->Label
<< endl
;
2020 /* Print out all the packaging systems that will work with
2022 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
2024 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
2029 if (Sys
->VS
->TestCompatibility(*VS
) == true)
2030 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
2034 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
2036 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
2037 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
2040 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
2042 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
2043 cout
<< " Idx: " << Type
->Label
<< endl
;
2050 _("Usage: apt-get [options] command\n"
2051 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
2052 " apt-get [options] source pkg1 [pkg2 ...]\n"
2054 "apt-get is a simple command line interface for downloading and\n"
2055 "installing packages. The most frequently used commands are update\n"
2059 " update - Retrieve new lists of packages\n"
2060 " upgrade - Perform an upgrade\n"
2061 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
2062 " remove - Remove packages\n"
2063 " source - Download source archives\n"
2064 " build-dep - Configure build-dependencies for source packages\n"
2065 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
2066 " dselect-upgrade - Follow dselect selections\n"
2067 " clean - Erase downloaded archive files\n"
2068 " autoclean - Erase old downloaded archive files\n"
2069 " check - Verify that there are no broken dependencies\n"
2072 " -h This help text.\n"
2073 " -q Loggable output - no progress indicator\n"
2074 " -qq No output except for errors\n"
2075 " -d Download only - do NOT install or unpack archives\n"
2076 " -s No-act. Perform ordering simulation\n"
2077 " -y Assume Yes to all queries and do not prompt\n"
2078 " -f Attempt to continue if the integrity check fails\n"
2079 " -m Attempt to continue if archives are unlocatable\n"
2080 " -u Show a list of upgraded packages as well\n"
2081 " -b Build the source package after fetching it\n"
2082 " -c=? Read this configuration file\n"
2083 " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n"
2084 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
2085 "pages for more information and options.\n"
2086 " This APT has Super Cow Powers.\n");
2090 // GetInitialize - Initialize things for apt-get /*{{{*/
2091 // ---------------------------------------------------------------------
2093 void GetInitialize()
2095 _config
->Set("quiet",0);
2096 _config
->Set("help",false);
2097 _config
->Set("APT::Get::Download-Only",false);
2098 _config
->Set("APT::Get::Simulate",false);
2099 _config
->Set("APT::Get::Assume-Yes",false);
2100 _config
->Set("APT::Get::Fix-Broken",false);
2101 _config
->Set("APT::Get::Force-Yes",false);
2102 _config
->Set("APT::Get::APT::Get::No-List-Cleanup",true);
2105 // SigWinch - Window size change signal handler /*{{{*/
2106 // ---------------------------------------------------------------------
2110 // Riped from GNU ls
2114 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
2115 ScreenWidth
= ws
.ws_col
- 1;
2120 int main(int argc
,const char *argv
[])
2122 CommandLine::Args Args
[] = {
2123 {'h',"help","help",0},
2124 {'v',"version","version",0},
2125 {'q',"quiet","quiet",CommandLine::IntLevel
},
2126 {'q',"silent","quiet",CommandLine::IntLevel
},
2127 {'d',"download-only","APT::Get::Download-Only",0},
2128 {'b',"compile","APT::Get::Compile",0},
2129 {'b',"build","APT::Get::Compile",0},
2130 {'s',"simulate","APT::Get::Simulate",0},
2131 {'s',"just-print","APT::Get::Simulate",0},
2132 {'s',"recon","APT::Get::Simulate",0},
2133 {'s',"dry-run","APT::Get::Simulate",0},
2134 {'s',"no-act","APT::Get::Simulate",0},
2135 {'y',"yes","APT::Get::Assume-Yes",0},
2136 {'y',"assume-yes","APT::Get::Assume-Yes",0},
2137 {'f',"fix-broken","APT::Get::Fix-Broken",0},
2138 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
2139 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
2140 {'t',"target-release","APT::Default-Release",CommandLine::HasArg
},
2141 {'t',"default-release","APT::Default-Release",CommandLine::HasArg
},
2142 {0,"download","APT::Get::Download",0},
2143 {0,"fix-missing","APT::Get::Fix-Missing",0},
2144 {0,"ignore-hold","APT::Ignore-Hold",0},
2145 {0,"upgrade","APT::Get::upgrade",0},
2146 {0,"force-yes","APT::Get::force-yes",0},
2147 {0,"print-uris","APT::Get::Print-URIs",0},
2148 {0,"diff-only","APT::Get::Diff-Only",0},
2149 {0,"tar-only","APT::Get::tar-Only",0},
2150 {0,"purge","APT::Get::Purge",0},
2151 {0,"list-cleanup","APT::Get::List-Cleanup",0},
2152 {0,"reinstall","APT::Get::ReInstall",0},
2153 {0,"trivial-only","APT::Get::Trivial-Only",0},
2154 {0,"remove","APT::Get::Remove",0},
2155 {0,"only-source","APT::Get::Only-Source",0},
2156 {0,"arch-only","APT::Get::Arch-Only",0},
2157 {'c',"config-file",0,CommandLine::ConfigFile
},
2158 {'o',"option",0,CommandLine::ArbItem
},
2160 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
2161 {"upgrade",&DoUpgrade
},
2162 {"install",&DoInstall
},
2163 {"remove",&DoInstall
},
2164 {"dist-upgrade",&DoDistUpgrade
},
2165 {"dselect-upgrade",&DoDSelectUpgrade
},
2166 {"build-dep",&DoBuildDep
},
2168 {"autoclean",&DoAutoClean
},
2170 {"source",&DoSource
},
2175 // Set up gettext support
2176 setlocale(LC_ALL
,"");
2177 textdomain(PACKAGE
);
2179 // Parse the command line and initialize the package library
2180 CommandLine
CmdL(Args
,_config
);
2181 if (pkgInitConfig(*_config
) == false ||
2182 CmdL
.Parse(argc
,argv
) == false ||
2183 pkgInitSystem(*_config
,_system
) == false)
2185 if (_config
->FindB("version") == true)
2188 _error
->DumpErrors();
2192 // See if the help should be shown
2193 if (_config
->FindB("help") == true ||
2194 _config
->FindB("version") == true ||
2195 CmdL
.FileSize() == 0)
2201 // Deal with stdout not being a tty
2202 if (ttyname(STDOUT_FILENO
) == 0 && _config
->FindI("quiet",0) < 1)
2203 _config
->Set("quiet","1");
2205 // Setup the output streams
2206 c0out
.rdbuf(cout
.rdbuf());
2207 c1out
.rdbuf(cout
.rdbuf());
2208 c2out
.rdbuf(cout
.rdbuf());
2209 if (_config
->FindI("quiet",0) > 0)
2210 c0out
.rdbuf(devnull
.rdbuf());
2211 if (_config
->FindI("quiet",0) > 1)
2212 c1out
.rdbuf(devnull
.rdbuf());
2214 // Setup the signals
2215 signal(SIGPIPE
,SIG_IGN
);
2216 signal(SIGWINCH
,SigWinch
);
2219 // Match the operation
2220 CmdL
.DispatchArg(Cmds
);
2222 // Print any errors or warnings found during parsing
2223 if (_error
->empty() == false)
2225 bool Errors
= _error
->PendingError();
2226 _error
->DumpErrors();
2227 return Errors
== true?100:0;