]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.126 2003/02/12 16:14:08 doogie Exp $
4 /* ######################################################################
6 apt-get - Cover for dpkg
8 This is an allout cover for dpkg implementing a safer front end. It is
9 based largely on libapt-pkg.
11 The syntax is different,
12 apt-get [opt] command [things]
14 update - Resyncronize the package files from their sources
15 upgrade - Smart-Download the newest versions of all packages
16 dselect-upgrade - Follows dselect's changes to the Status: field
17 and installes new and removes old packages
18 dist-upgrade - Powerfull upgrader designed to handle the issues with
20 install - Download and install a given package (by name, not by .deb)
21 check - Update the package cache and check for broken packages
22 clean - Erase the .debs downloaded to /var/cache/apt/archives and
25 ##################################################################### */
27 // Include Files /*{{{*/
28 #include <apt-pkg/error.h>
29 #include <apt-pkg/cmndline.h>
30 #include <apt-pkg/init.h>
31 #include <apt-pkg/depcache.h>
32 #include <apt-pkg/sourcelist.h>
33 #include <apt-pkg/algorithms.h>
34 #include <apt-pkg/acquire-item.h>
35 #include <apt-pkg/strutl.h>
36 #include <apt-pkg/clean.h>
37 #include <apt-pkg/srcrecords.h>
38 #include <apt-pkg/version.h>
39 #include <apt-pkg/cachefile.h>
40 #include <apt-pkg/sptr.h>
41 #include <apt-pkg/versionmatch.h>
46 #include "acqprogress.h"
51 #include <sys/ioctl.h>
53 #include <sys/statvfs.h>
67 ofstream
devnull("/dev/null");
68 unsigned int ScreenWidth
= 80;
70 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
71 // ---------------------------------------------------------------------
73 class CacheFile
: public pkgCacheFile
75 static pkgCache
*SortCache
;
76 static int NameComp(const void *a
,const void *b
);
79 pkgCache::Package
**List
;
82 bool CheckDeps(bool AllowBroken
= false);
83 bool BuildCaches(bool WithLock
= true)
85 OpTextProgress
Prog(*_config
);
86 if (pkgCacheFile::BuildCaches(Prog
,WithLock
) == false)
90 bool Open(bool WithLock
= true)
92 OpTextProgress
Prog(*_config
);
93 if (pkgCacheFile::Open(Prog
,WithLock
) == false)
101 if (_config
->FindB("APT::Get::Print-URIs") == true)
106 CacheFile() : List(0) {};
110 // YnPrompt - Yes No Prompt. /*{{{*/
111 // ---------------------------------------------------------------------
112 /* Returns true on a Yes.*/
115 // This needs to be a capital
116 const char *Yes
= _("Y");
118 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
120 c1out
<< Yes
<< endl
;
126 if (read(STDIN_FILENO
,&C
,1) != 1)
128 while (C
!= '\n' && Jnk
!= '\n')
129 if (read(STDIN_FILENO
,&Jnk
,1) != 1)
132 if (!(toupper(C
) == *Yes
|| C
== '\n' || C
== '\r'))
137 // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
138 // ---------------------------------------------------------------------
139 /* Returns true on a Yes.*/
140 bool AnalPrompt(const char *Text
)
143 cin
.getline(Buf
,sizeof(Buf
));
144 if (strcmp(Buf
,Text
) == 0)
149 // ShowList - Show a list /*{{{*/
150 // ---------------------------------------------------------------------
151 /* This prints out a string of space separated words with a title and
152 a two space indent line wraped to the current screen width. */
153 bool ShowList(ostream
&out
,string Title
,string List
)
155 if (List
.empty() == true)
157 // trim trailing space
158 int NonSpace
= List
.find_last_not_of(' ');
161 List
= List
.erase(NonSpace
+ 1);
162 if (List
.empty() == true)
166 // Acount for the leading space
167 int ScreenWidth
= ::ScreenWidth
- 3;
169 out
<< Title
<< endl
;
170 string::size_type Start
= 0;
171 while (Start
< List
.size())
173 string::size_type End
;
174 if (Start
+ ScreenWidth
>= List
.size())
177 End
= List
.rfind(' ',Start
+ScreenWidth
);
179 if (End
== string::npos
|| End
< Start
)
180 End
= Start
+ ScreenWidth
;
181 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
187 // ShowBroken - Debugging aide /*{{{*/
188 // ---------------------------------------------------------------------
189 /* This prints out the names of all the packages that are broken along
190 with the name of each each broken dependency and a quite version
193 The output looks like:
194 The following packages have unmet dependencies:
195 exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed
196 Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
197 Depends: libsasl7 but it is not going to be installed
199 void ShowBroken(ostream
&out
,CacheFile
&Cache
,bool Now
)
201 out
<< _("The following packages have unmet dependencies:") << endl
;
202 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
204 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
208 if (Cache
[I
].NowBroken() == false)
213 if (Cache
[I
].InstBroken() == false)
217 // Print out each package and the failed dependencies
218 out
<<" " << I
.Name() << ":";
219 unsigned Indent
= strlen(I
.Name()) + 3;
221 pkgCache::VerIterator Ver
;
224 Ver
= I
.CurrentVer();
226 Ver
= Cache
[I
].InstVerIter(Cache
);
228 if (Ver
.end() == true)
234 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false;)
236 // Compute a single dependency element (glob or)
237 pkgCache::DepIterator Start
;
238 pkgCache::DepIterator End
;
241 if (Cache
->IsImportantDep(End
) == false)
246 if ((Cache
[End
] & pkgDepCache::DepGNow
) == pkgDepCache::DepGNow
)
251 if ((Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
259 for (unsigned J
= 0; J
!= Indent
; J
++)
263 if (FirstOr
== false)
265 for (unsigned J
= 0; J
!= strlen(End
.DepType()) + 3; J
++)
269 out
<< ' ' << End
.DepType() << ": ";
272 out
<< Start
.TargetPkg().Name();
274 // Show a quick summary of the version requirements
275 if (Start
.TargetVer() != 0)
276 out
<< " (" << Start
.CompType() << " " << Start
.TargetVer() << ")";
278 /* Show a summary of the target package if possible. In the case
279 of virtual packages we show nothing */
280 pkgCache::PkgIterator Targ
= Start
.TargetPkg();
281 if (Targ
->ProvidesList
== 0)
284 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
286 Ver
= Targ
.CurrentVer();
288 if (Ver
.end() == false)
291 ioprintf(out
,_("but %s is installed"),Ver
.VerStr());
293 ioprintf(out
,_("but %s is to be installed"),Ver
.VerStr());
297 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
299 if (Targ
->ProvidesList
== 0)
300 out
<< _("but it is not installable");
302 out
<< _("but it is a virtual package");
305 out
<< (Now
?_("but it is not installed"):_("but it is not going to be installed"));
321 // ShowNew - Show packages to newly install /*{{{*/
322 // ---------------------------------------------------------------------
324 void ShowNew(ostream
&out
,CacheFile
&Cache
)
326 /* Print out a list of packages that are going to be removed extra
327 to what the user asked */
329 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
331 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
332 if (Cache
[I
].NewInstall() == true)
333 List
+= string(I
.Name()) + " ";
336 ShowList(out
,_("The following NEW packages will be installed:"),List
);
339 // ShowDel - Show packages to delete /*{{{*/
340 // ---------------------------------------------------------------------
342 void ShowDel(ostream
&out
,CacheFile
&Cache
)
344 /* Print out a list of packages that are going to be removed extra
345 to what the user asked */
347 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
349 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
350 if (Cache
[I
].Delete() == true)
352 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
353 List
+= string(I
.Name()) + "* ";
355 List
+= string(I
.Name()) + " ";
359 ShowList(out
,_("The following packages will be REMOVED:"),List
);
362 // ShowKept - Show kept packages /*{{{*/
363 // ---------------------------------------------------------------------
365 void ShowKept(ostream
&out
,CacheFile
&Cache
)
368 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
370 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
373 if (Cache
[I
].Upgrade() == true || Cache
[I
].Upgradable() == false ||
374 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
377 List
+= string(I
.Name()) + " ";
379 ShowList(out
,_("The following packages have been kept back"),List
);
382 // ShowUpgraded - Show upgraded packages /*{{{*/
383 // ---------------------------------------------------------------------
385 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
388 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
390 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
393 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
396 List
+= string(I
.Name()) + " ";
398 ShowList(out
,_("The following packages will be upgraded"),List
);
401 // ShowDowngraded - Show downgraded packages /*{{{*/
402 // ---------------------------------------------------------------------
404 bool ShowDowngraded(ostream
&out
,CacheFile
&Cache
)
407 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
409 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
412 if (Cache
[I
].Downgrade() == false || Cache
[I
].NewInstall() == true)
415 List
+= string(I
.Name()) + " ";
417 return ShowList(out
,_("The following packages will be DOWNGRADED"),List
);
420 // ShowHold - Show held but changed packages /*{{{*/
421 // ---------------------------------------------------------------------
423 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
426 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
428 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
429 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
430 I
->SelectedState
== pkgCache::State::Hold
)
431 List
+= string(I
.Name()) + " ";
434 return ShowList(out
,_("The following held packages will be changed:"),List
);
437 // ShowEssential - Show an essential package warning /*{{{*/
438 // ---------------------------------------------------------------------
439 /* This prints out a warning message that is not to be ignored. It shows
440 all essential packages and their dependents that are to be removed.
441 It is insanely risky to remove the dependents of an essential package! */
442 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
445 bool *Added
= new bool[Cache
->Head().PackageCount
];
446 for (unsigned int I
= 0; I
!= Cache
->Head().PackageCount
; I
++)
449 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
451 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
452 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
&&
453 (I
->Flags
& pkgCache::Flag::Important
) != pkgCache::Flag::Important
)
456 // The essential package is being removed
457 if (Cache
[I
].Delete() == true)
459 if (Added
[I
->ID
] == false)
462 List
+= string(I
.Name()) + " ";
466 if (I
->CurrentVer
== 0)
469 // Print out any essential package depenendents that are to be removed
470 for (pkgCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
472 // Skip everything but depends
473 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
474 D
->Type
!= pkgCache::Dep::Depends
)
477 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
478 if (Cache
[P
].Delete() == true)
480 if (Added
[P
->ID
] == true)
485 snprintf(S
,sizeof(S
),_("%s (due to %s) "),P
.Name(),I
.Name());
492 return ShowList(out
,_("WARNING: The following essential packages will be removed\n"
493 "This should NOT be done unless you know exactly what you are doing!"),List
);
496 // Stats - Show some statistics /*{{{*/
497 // ---------------------------------------------------------------------
499 void Stats(ostream
&out
,pkgDepCache
&Dep
)
501 unsigned long Upgrade
= 0;
502 unsigned long Downgrade
= 0;
503 unsigned long Install
= 0;
504 unsigned long ReInstall
= 0;
505 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
507 if (Dep
[I
].NewInstall() == true)
511 if (Dep
[I
].Upgrade() == true)
514 if (Dep
[I
].Downgrade() == true)
518 if (Dep
[I
].Delete() == false && (Dep
[I
].iFlags
& pkgDepCache::ReInstall
) == pkgDepCache::ReInstall
)
522 ioprintf(out
,_("%lu packages upgraded, %lu newly installed, "),
526 ioprintf(out
,_("%lu reinstalled, "),ReInstall
);
528 ioprintf(out
,_("%lu downgraded, "),Downgrade
);
530 ioprintf(out
,_("%lu to remove and %lu not upgraded.\n"),
531 Dep
.DelCount(),Dep
.KeepCount());
533 if (Dep
.BadCount() != 0)
534 ioprintf(out
,_("%lu packages not fully installed or removed.\n"),
539 // CacheFile::NameComp - QSort compare by name /*{{{*/
540 // ---------------------------------------------------------------------
542 pkgCache
*CacheFile::SortCache
= 0;
543 int CacheFile::NameComp(const void *a
,const void *b
)
545 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
546 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
548 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
549 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
551 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
554 // CacheFile::Sort - Sort by name /*{{{*/
555 // ---------------------------------------------------------------------
557 void CacheFile::Sort()
560 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
561 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
562 pkgCache::PkgIterator I
= Cache
->PkgBegin();
563 for (;I
.end() != true; I
++)
567 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
570 // CacheFile::CheckDeps - Open the cache file /*{{{*/
571 // ---------------------------------------------------------------------
572 /* This routine generates the caches and then opens the dependency cache
573 and verifies that the system is OK. */
574 bool CacheFile::CheckDeps(bool AllowBroken
)
576 if (_error
->PendingError() == true)
579 // Check that the system is OK
580 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
581 return _error
->Error("Internal Error, non-zero counts");
583 // Apply corrections for half-installed packages
584 if (pkgApplyStatus(*DCache
) == false)
588 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
591 // Attempt to fix broken things
592 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
594 c1out
<< _("Correcting dependencies...") << flush
;
595 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
597 c1out
<< _(" failed.") << endl
;
598 ShowBroken(c1out
,*this,true);
600 return _error
->Error(_("Unable to correct dependencies"));
602 if (pkgMinimizeUpgrade(*DCache
) == false)
603 return _error
->Error(_("Unable to minimize the upgrade set"));
605 c1out
<< _(" Done") << endl
;
609 c1out
<< _("You might want to run `apt-get -f install' to correct these.") << endl
;
610 ShowBroken(c1out
,*this,true);
612 return _error
->Error(_("Unmet dependencies. Try using -f."));
619 // InstallPackages - Actually download and install the packages /*{{{*/
620 // ---------------------------------------------------------------------
621 /* This displays the informative messages describing what is going to
622 happen and then calls the download routines */
623 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,
626 if (_config
->FindB("APT::Get::Purge",false) == true)
628 pkgCache::PkgIterator I
= Cache
->PkgBegin();
629 for (; I
.end() == false; I
++)
631 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
632 Cache
->MarkDelete(I
,true);
637 bool Essential
= false;
639 // Show all the various warning indicators
640 ShowDel(c1out
,Cache
);
641 ShowNew(c1out
,Cache
);
643 ShowKept(c1out
,Cache
);
644 Fail
|= !ShowHold(c1out
,Cache
);
645 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
646 ShowUpgraded(c1out
,Cache
);
647 Fail
|= !ShowDowngraded(c1out
,Cache
);
648 Essential
= !ShowEssential(c1out
,Cache
);
653 if (Cache
->BrokenCount() != 0)
655 ShowBroken(c1out
,Cache
,false);
656 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
659 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
660 Cache
->BadCount() == 0)
664 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::Remove",true) == false)
665 return _error
->Error(_("Packages need to be removed but Remove is disabled."));
667 // Run the simulator ..
668 if (_config
->FindB("APT::Get::Simulate") == true)
670 pkgSimulate
PM(Cache
);
671 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
672 if (Res
== pkgPackageManager::Failed
)
674 if (Res
!= pkgPackageManager::Completed
)
675 return _error
->Error("Internal Error, Ordering didn't finish");
679 // Create the text record parser
680 pkgRecords
Recs(Cache
);
681 if (_error
->PendingError() == true)
684 // Lock the archive directory
686 if (_config
->FindB("Debug::NoLocking",false) == false &&
687 _config
->FindB("APT::Get::Print-URIs") == false)
689 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
690 if (_error
->PendingError() == true)
691 return _error
->Error(_("Unable to lock the download directory"));
694 // Create the download object
695 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
696 pkgAcquire
Fetcher(&Stat
);
698 // Read the source list
700 if (List
.ReadMainList() == false)
701 return _error
->Error(_("The list of sources could not be read."));
703 // Create the package manager and prepare to download
704 SPtr
<pkgPackageManager
> PM
= _system
->CreatePM(Cache
);
705 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false ||
706 _error
->PendingError() == true)
709 // Display statistics
710 double FetchBytes
= Fetcher
.FetchNeeded();
711 double FetchPBytes
= Fetcher
.PartialPresent();
712 double DebBytes
= Fetcher
.TotalNeeded();
713 if (DebBytes
!= Cache
->DebSize())
715 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
716 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
720 if (DebBytes
!= FetchBytes
)
721 ioprintf(c1out
,_("Need to get %sB/%sB of archives.\n"),
722 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
724 ioprintf(c1out
,_("Need to get %sB of archives.\n"),
725 SizeToStr(DebBytes
).c_str());
728 if (Cache
->UsrSize() >= 0)
729 ioprintf(c1out
,_("After unpacking %sB of additional disk space will be used.\n"),
730 SizeToStr(Cache
->UsrSize()).c_str());
732 ioprintf(c1out
,_("After unpacking %sB disk space will be freed.\n"),
733 SizeToStr(-1*Cache
->UsrSize()).c_str());
735 if (_error
->PendingError() == true)
738 /* Check for enough free space, but only if we are actually going to
740 if (_config
->FindB("APT::Get::Print-URIs") == false &&
741 _config
->FindB("APT::Get::Download",true) == true)
744 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
745 if (statvfs(OutputDir
.c_str(),&Buf
) != 0)
746 return _error
->Errno("statvfs","Couldn't determine free space in %s",
748 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
749 return _error
->Error(_("You don't have enough free space in %s."),
754 if (_config
->FindI("quiet",0) >= 2 ||
755 _config
->FindB("APT::Get::Assume-Yes",false) == true)
757 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
758 return _error
->Error(_("There are problems and -y was used without --force-yes"));
761 if (Essential
== true && Saftey
== true)
763 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
764 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
766 const char *Prompt
= _("Yes, do as I say!");
768 _("You are about to do something potentially harmful\n"
769 "To continue type in the phrase '%s'\n"
772 if (AnalPrompt(Prompt
) == false)
774 c2out
<< _("Abort.") << endl
;
780 // Prompt to continue
781 if (Ask
== true || Fail
== true)
783 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
784 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
786 if (_config
->FindI("quiet",0) < 2 &&
787 _config
->FindB("APT::Get::Assume-Yes",false) == false)
789 c2out
<< _("Do you want to continue? [Y/n] ") << flush
;
791 if (YnPrompt() == false)
793 c2out
<< _("Abort.") << endl
;
800 // Just print out the uris an exit if the --print-uris flag was used
801 if (_config
->FindB("APT::Get::Print-URIs") == true)
803 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
804 for (; I
!= Fetcher
.UriEnd(); I
++)
805 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
806 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
810 /* Unlock the dpkg lock if we are not going to be doing an install
812 if (_config
->FindB("APT::Get::Download-Only",false) == true)
818 bool Transient
= false;
819 if (_config
->FindB("APT::Get::Download",true) == false)
821 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
823 if ((*I
)->Local
== true)
829 // Close the item and check if it was found in cache
831 if ((*I
)->Complete
== false)
834 // Clear it out of the fetch list
836 I
= Fetcher
.ItemsBegin();
840 if (Fetcher
.Run() == pkgAcquire::Failed
)
845 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
847 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
848 (*I
)->Complete
== true)
851 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
858 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
859 (*I
)->ErrorText
.c_str());
863 /* If we are in no download mode and missing files and there were
864 'failures' then the user must specify -m. Furthermore, there
865 is no such thing as a transient error in no-download mode! */
866 if (Transient
== true &&
867 _config
->FindB("APT::Get::Download",true) == false)
873 if (_config
->FindB("APT::Get::Download-Only",false) == true)
875 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
876 return _error
->Error(_("Some files failed to download"));
877 c1out
<< _("Download complete and in download only mode") << endl
;
881 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
883 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
886 if (Transient
== true && Failed
== true)
887 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
889 // Try to deal with missing package files
890 if (Failed
== true && PM
->FixMissing() == false)
892 cerr
<< _("Unable to correct missing packages.") << endl
;
893 return _error
->Error(_("Aborting Install."));
897 pkgPackageManager::OrderResult Res
= PM
->DoInstall();
898 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
900 if (Res
== pkgPackageManager::Completed
)
903 // Reload the fetcher object and loop again for media swapping
905 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false)
912 // TryToInstall - Try to install a single package /*{{{*/
913 // ---------------------------------------------------------------------
914 /* This used to be inlined in DoInstall, but with the advent of regex package
915 name matching it was split out.. */
916 bool TryToInstall(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
917 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
918 unsigned int &ExpectedInst
,bool AllowFail
= true)
920 /* This is a pure virtual package and there is a single available
922 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0 &&
923 Pkg
.ProvidesList()->NextProvides
== 0)
925 pkgCache::PkgIterator Tmp
= Pkg
.ProvidesList().OwnerPkg();
926 ioprintf(c1out
,_("Note, selecting %s instead of %s\n"),
927 Tmp
.Name(),Pkg
.Name());
931 // Handle the no-upgrade case
932 if (_config
->FindB("APT::Get::upgrade",true) == false &&
933 Pkg
->CurrentVer
!= 0)
935 if (AllowFail
== true)
936 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
941 // Check if there is something at all to install
942 pkgDepCache::StateCache
&State
= Cache
[Pkg
];
943 if (Remove
== true && Pkg
->CurrentVer
== 0)
949 /* We want to continue searching for regex hits, so we return false here
950 otherwise this is not really an error. */
951 if (AllowFail
== false)
954 ioprintf(c1out
,_("Package %s is not installed, so not removed\n"),Pkg
.Name());
958 if (State
.CandidateVer
== 0 && Remove
== false)
960 if (AllowFail
== false)
963 if (Pkg
->ProvidesList
!= 0)
965 ioprintf(c1out
,_("Package %s is a virtual package provided by:\n"),
968 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
969 for (; I
.end() == false; I
++)
971 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
973 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer())
975 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
976 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
977 _(" [Installed]") << endl
;
979 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
982 c1out
<< _("You should explicitly select one to install.") << endl
;
987 _("Package %s has no available version, but exists in the database.\n"
988 "This typically means that the package was mentioned in a dependency and\n"
989 "never uploaded, has been obsoleted or is not available with the contents\n"
990 "of sources.list\n"),Pkg
.Name());
993 SPtrArray
<bool> Seen
= new bool[Cache
.Head().PackageCount
];
994 memset(Seen
,0,Cache
.Head().PackageCount
*sizeof(*Seen
));
995 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
996 for (; Dep
.end() == false; Dep
++)
998 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
1000 if (Seen
[Dep
.ParentPkg()->ID
] == true)
1002 Seen
[Dep
.ParentPkg()->ID
] = true;
1003 List
+= string(Dep
.ParentPkg().Name()) + " ";
1005 ShowList(c1out
,_("However the following packages replace it:"),List
);
1008 _error
->Error(_("Package %s has no installation candidate"),Pkg
.Name());
1017 Cache
.MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
1022 Cache
.MarkInstall(Pkg
,false);
1023 if (State
.Install() == false)
1025 if (_config
->FindB("APT::Get::ReInstall",false) == true)
1027 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
1028 ioprintf(c1out
,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
1031 Cache
.SetReInstall(Pkg
,true);
1035 if (AllowFail
== true)
1036 ioprintf(c1out
,_("%s is already the newest version.\n"),
1043 // Install it with autoinstalling enabled.
1044 if (State
.InstBroken() == true && BrokenFix
== false)
1045 Cache
.MarkInstall(Pkg
,true);
1049 // TryToChangeVer - Try to change a candidate version /*{{{*/
1050 // ---------------------------------------------------------------------
1052 bool TryToChangeVer(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
1053 const char *VerTag
,bool IsRel
)
1055 pkgVersionMatch
Match(VerTag
,(IsRel
== true?pkgVersionMatch::Release
:
1056 pkgVersionMatch::Version
));
1058 pkgCache::VerIterator Ver
= Match
.Find(Pkg
);
1060 if (Ver
.end() == true)
1063 return _error
->Error(_("Release '%s' for '%s' was not found"),
1065 return _error
->Error(_("Version '%s' for '%s' was not found"),
1069 if (strcmp(VerTag
,Ver
.VerStr()) != 0)
1071 ioprintf(c1out
,_("Selected version %s (%s) for %s\n"),
1072 Ver
.VerStr(),Ver
.RelStr().c_str(),Pkg
.Name());
1075 Cache
.SetCandidateVersion(Ver
);
1079 // FindSrc - Find a source record /*{{{*/
1080 // ---------------------------------------------------------------------
1082 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
1083 pkgSrcRecords
&SrcRecs
,string
&Src
,
1086 // We want to pull the version off the package specification..
1088 string TmpSrc
= Name
;
1089 string::size_type Slash
= TmpSrc
.rfind('=');
1090 if (Slash
!= string::npos
)
1092 VerTag
= string(TmpSrc
.begin() + Slash
+ 1,TmpSrc
.end());
1093 TmpSrc
= string(TmpSrc
.begin(),TmpSrc
.begin() + Slash
);
1096 /* Lookup the version of the package we would install if we were to
1097 install a version and determine the source package name, then look
1098 in the archive for a source package of the same name. In theory
1099 we could stash the version string as well and match that too but
1100 today there aren't multi source versions in the archive. */
1101 if (_config
->FindB("APT::Get::Only-Source") == false &&
1102 VerTag
.empty() == true)
1104 pkgCache::PkgIterator Pkg
= Cache
.FindPkg(TmpSrc
);
1105 if (Pkg
.end() == false)
1107 pkgCache::VerIterator Ver
= Cache
.GetCandidateVer(Pkg
);
1108 if (Ver
.end() == false)
1110 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1111 Src
= Parse
.SourcePkg();
1116 // No source package name..
1117 if (Src
.empty() == true)
1121 pkgSrcRecords::Parser
*Last
= 0;
1122 unsigned long Offset
= 0;
1124 bool IsMatch
= false;
1126 // If we are matching by version then we need exact matches to be happy
1127 if (VerTag
.empty() == false)
1130 /* Iterate over all of the hits, which includes the resulting
1131 binary packages in the search */
1132 pkgSrcRecords::Parser
*Parse
;
1134 while ((Parse
= SrcRecs
.Find(Src
.c_str(),false)) != 0)
1136 string Ver
= Parse
->Version();
1138 // Skip name mismatches
1139 if (IsMatch
== true && Parse
->Package() != Src
)
1142 if (VerTag
.empty() == false)
1144 /* Don't want to fall through because we are doing exact version
1146 if (Cache
.VS().CmpVersion(VerTag
,Ver
) != 0)
1150 Offset
= Parse
->Offset();
1154 // Newer version or an exact match
1155 if (Last
== 0 || Cache
.VS().CmpVersion(Version
,Ver
) < 0 ||
1156 (Parse
->Package() == Src
&& IsMatch
== false))
1158 IsMatch
= Parse
->Package() == Src
;
1160 Offset
= Parse
->Offset();
1168 if (Last
->Jump(Offset
) == false)
1175 // DoUpdate - Update the package lists /*{{{*/
1176 // ---------------------------------------------------------------------
1178 bool DoUpdate(CommandLine
&CmdL
)
1180 if (CmdL
.FileSize() != 1)
1181 return _error
->Error(_("The update command takes no arguments"));
1183 // Get the source list
1185 if (List
.ReadMainList() == false)
1188 // Lock the list directory
1190 if (_config
->FindB("Debug::NoLocking",false) == false)
1192 Lock
.Fd(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
1193 if (_error
->PendingError() == true)
1194 return _error
->Error(_("Unable to lock the list directory"));
1197 // Create the download object
1198 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1199 pkgAcquire
Fetcher(&Stat
);
1201 // Populate it with the source selection
1202 if (List
.GetIndexes(&Fetcher
) == false)
1205 // Just print out the uris an exit if the --print-uris flag was used
1206 if (_config
->FindB("APT::Get::Print-URIs") == true)
1208 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1209 for (; I
!= Fetcher
.UriEnd(); I
++)
1210 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1211 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1216 if (Fetcher
.Run() == pkgAcquire::Failed
)
1219 bool Failed
= false;
1220 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1222 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
1227 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1228 (*I
)->ErrorText
.c_str());
1232 // Clean out any old list files
1233 if (_config
->FindB("APT::Get::List-Cleanup",true) == true)
1235 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
1236 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
1240 // Prepare the cache.
1242 if (Cache
.BuildCaches() == false)
1246 return _error
->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
1251 // DoUpgrade - Upgrade all packages /*{{{*/
1252 // ---------------------------------------------------------------------
1253 /* Upgrade all packages without installing new packages or erasing old
1255 bool DoUpgrade(CommandLine
&CmdL
)
1258 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1262 if (pkgAllUpgrade(Cache
) == false)
1264 ShowBroken(c1out
,Cache
,false);
1265 return _error
->Error(_("Internal Error, AllUpgrade broke stuff"));
1268 return InstallPackages(Cache
,true);
1271 // DoInstall - Install packages from the command line /*{{{*/
1272 // ---------------------------------------------------------------------
1273 /* Install named packages */
1274 bool DoInstall(CommandLine
&CmdL
)
1277 if (Cache
.OpenForInstall() == false ||
1278 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
1281 // Enter the special broken fixing mode if the user specified arguments
1282 bool BrokenFix
= false;
1283 if (Cache
->BrokenCount() != 0)
1286 unsigned int ExpectedInst
= 0;
1287 unsigned int Packages
= 0;
1288 pkgProblemResolver
Fix(Cache
);
1290 bool DefRemove
= false;
1291 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
1294 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1296 // Duplicate the string
1297 unsigned int Length
= strlen(*I
);
1299 if (Length
>= sizeof(S
))
1303 // See if we are removing and special indicators..
1304 bool Remove
= DefRemove
;
1306 bool VerIsRel
= false;
1307 while (Cache
->FindPkg(S
).end() == true)
1309 // Handle an optional end tag indicating what to do
1310 if (S
[Length
- 1] == '-')
1317 if (S
[Length
- 1] == '+')
1324 char *Slash
= strchr(S
,'=');
1332 Slash
= strchr(S
,'/');
1343 // Locate the package
1344 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
1346 if (Pkg
.end() == true)
1348 // Check if the name is a regex
1350 for (I
= S
; *I
!= 0; I
++)
1351 if (*I
== '?' || *I
== '*' || *I
== '|' ||
1352 *I
== '[' || *I
== '^' || *I
== '$')
1355 return _error
->Error(_("Couldn't find package %s"),S
);
1357 // Regexs must always be confirmed
1358 ExpectedInst
+= 1000;
1360 // Compile the regex pattern
1363 if ((Res
= regcomp(&Pattern
,S
,REG_EXTENDED
| REG_ICASE
|
1367 regerror(Res
,&Pattern
,Error
,sizeof(Error
));
1368 return _error
->Error(_("Regex compilation error - %s"),Error
);
1371 // Run over the matches
1373 for (Pkg
= Cache
->PkgBegin(); Pkg
.end() == false; Pkg
++)
1375 if (regexec(&Pattern
,Pkg
.Name(),0,0,0) != 0)
1378 ioprintf(c1out
,_("Note, selecting %s for regex '%s'\n"),
1382 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1385 Hit
|= TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,
1386 ExpectedInst
,false);
1391 return _error
->Error(_("Couldn't find package %s"),S
);
1396 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1398 if (TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,ExpectedInst
) == false)
1403 /* If we are in the Broken fixing mode we do not attempt to fix the
1404 problems. This is if the user invoked install without -f and gave
1406 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1408 c1out
<< _("You might want to run `apt-get -f install' to correct these:") << endl
;
1409 ShowBroken(c1out
,Cache
,false);
1411 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1414 // Call the scored problem resolver
1415 Fix
.InstallProtect();
1416 if (Fix
.Resolve(true) == false)
1419 // Now we check the state of the packages,
1420 if (Cache
->BrokenCount() != 0)
1423 _("Some packages could not be installed. This may mean that you have\n"
1424 "requested an impossible situation or if you are using the unstable\n"
1425 "distribution that some required packages have not yet been created\n"
1426 "or been moved out of Incoming.") << endl
;
1431 _("Since you only requested a single operation it is extremely likely that\n"
1432 "the package is simply not installable and a bug report against\n"
1433 "that package should be filed.") << endl
;
1436 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1438 ShowBroken(c1out
,Cache
,false);
1439 return _error
->Error(_("Broken packages"));
1442 /* Print out a list of packages that are going to be installed extra
1443 to what the user asked */
1444 if (Cache
->InstCount() != ExpectedInst
)
1447 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1449 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1450 if ((*Cache
)[I
].Install() == false)
1454 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1455 if (strcmp(*J
,I
.Name()) == 0)
1459 List
+= string(I
.Name()) + " ";
1462 ShowList(c1out
,_("The following extra packages will be installed:"),List
);
1465 // See if we need to prompt
1466 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
1467 return InstallPackages(Cache
,false,false);
1469 return InstallPackages(Cache
,false);
1472 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1473 // ---------------------------------------------------------------------
1474 /* Intelligent upgrader that will install and remove packages at will */
1475 bool DoDistUpgrade(CommandLine
&CmdL
)
1478 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1481 c0out
<< _("Calculating Upgrade... ") << flush
;
1482 if (pkgDistUpgrade(*Cache
) == false)
1484 c0out
<< _("Failed") << endl
;
1485 ShowBroken(c1out
,Cache
,false);
1489 c0out
<< _("Done") << endl
;
1491 return InstallPackages(Cache
,true);
1494 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1495 // ---------------------------------------------------------------------
1496 /* Follows dselect's selections */
1497 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1500 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1503 // Install everything with the install flag set
1504 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1505 for (;I
.end() != true; I
++)
1507 /* Install the package only if it is a new install, the autoupgrader
1508 will deal with the rest */
1509 if (I
->SelectedState
== pkgCache::State::Install
)
1510 Cache
->MarkInstall(I
,false);
1513 /* Now install their deps too, if we do this above then order of
1514 the status file is significant for | groups */
1515 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1517 /* Install the package only if it is a new install, the autoupgrader
1518 will deal with the rest */
1519 if (I
->SelectedState
== pkgCache::State::Install
)
1520 Cache
->MarkInstall(I
,true);
1523 // Apply erasures now, they override everything else.
1524 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1527 if (I
->SelectedState
== pkgCache::State::DeInstall
||
1528 I
->SelectedState
== pkgCache::State::Purge
)
1529 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
1532 /* Resolve any problems that dselect created, allupgrade cannot handle
1533 such things. We do so quite agressively too.. */
1534 if (Cache
->BrokenCount() != 0)
1536 pkgProblemResolver
Fix(Cache
);
1538 // Hold back held packages.
1539 if (_config
->FindB("APT::Ignore-Hold",false) == false)
1541 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
1543 if (I
->SelectedState
== pkgCache::State::Hold
)
1551 if (Fix
.Resolve() == false)
1553 ShowBroken(c1out
,Cache
,false);
1554 return _error
->Error("Internal Error, problem resolver broke stuff");
1558 // Now upgrade everything
1559 if (pkgAllUpgrade(Cache
) == false)
1561 ShowBroken(c1out
,Cache
,false);
1562 return _error
->Error("Internal Error, problem resolver broke stuff");
1565 return InstallPackages(Cache
,false);
1568 // DoClean - Remove download archives /*{{{*/
1569 // ---------------------------------------------------------------------
1571 bool DoClean(CommandLine
&CmdL
)
1573 if (_config
->FindB("APT::Get::Simulate") == true)
1575 cout
<< "Del " << _config
->FindDir("Dir::Cache::archives") << "* " <<
1576 _config
->FindDir("Dir::Cache::archives") << "partial/*" << endl
;
1580 // Lock the archive directory
1582 if (_config
->FindB("Debug::NoLocking",false) == false)
1584 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1585 if (_error
->PendingError() == true)
1586 return _error
->Error(_("Unable to lock the download directory"));
1590 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
1591 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
1595 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
1596 // ---------------------------------------------------------------------
1597 /* This is similar to clean but it only purges things that cannot be
1598 downloaded, that is old versions of cached packages. */
1599 class LogCleaner
: public pkgArchiveCleaner
1602 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1604 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
1606 if (_config
->FindB("APT::Get::Simulate") == false)
1611 bool DoAutoClean(CommandLine
&CmdL
)
1613 // Lock the archive directory
1615 if (_config
->FindB("Debug::NoLocking",false) == false)
1617 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
1618 if (_error
->PendingError() == true)
1619 return _error
->Error(_("Unable to lock the download directory"));
1623 if (Cache
.Open() == false)
1628 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1629 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1632 // DoCheck - Perform the check operation /*{{{*/
1633 // ---------------------------------------------------------------------
1634 /* Opening automatically checks the system, this command is mostly used
1636 bool DoCheck(CommandLine
&CmdL
)
1645 // DoSource - Fetch a source archive /*{{{*/
1646 // ---------------------------------------------------------------------
1647 /* Fetch souce packages */
1655 bool DoSource(CommandLine
&CmdL
)
1658 if (Cache
.Open(false) == false)
1661 if (CmdL
.FileSize() <= 1)
1662 return _error
->Error(_("Must specify at least one package to fetch source for"));
1664 // Read the source list
1666 if (List
.ReadMainList() == false)
1667 return _error
->Error(_("The list of sources could not be read."));
1669 // Create the text record parsers
1670 pkgRecords
Recs(Cache
);
1671 pkgSrcRecords
SrcRecs(List
);
1672 if (_error
->PendingError() == true)
1675 // Create the download object
1676 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1677 pkgAcquire
Fetcher(&Stat
);
1679 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
1681 // Load the requestd sources into the fetcher
1683 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1686 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1689 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1692 vector
<pkgSrcRecords::File
> Lst
;
1693 if (Last
->Files(Lst
) == false)
1696 // Load them into the fetcher
1697 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
1698 I
!= Lst
.end(); I
++)
1700 // Try to guess what sort of file it is we are getting.
1701 if (I
->Type
== "dsc")
1703 Dsc
[J
].Package
= Last
->Package();
1704 Dsc
[J
].Version
= Last
->Version();
1705 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
1708 // Diff only mode only fetches .diff files
1709 if (_config
->FindB("APT::Get::Diff-Only",false) == true &&
1713 // Tar only mode only fetches .tar files
1714 if (_config
->FindB("APT::Get::Tar-Only",false) == true &&
1718 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
1720 Last
->Index().SourceInfo(*Last
,*I
),Src
);
1724 // Display statistics
1725 double FetchBytes
= Fetcher
.FetchNeeded();
1726 double FetchPBytes
= Fetcher
.PartialPresent();
1727 double DebBytes
= Fetcher
.TotalNeeded();
1729 // Check for enough free space
1731 string OutputDir
= ".";
1732 if (statvfs(OutputDir
.c_str(),&Buf
) != 0)
1733 return _error
->Errno("statvfs","Couldn't determine free space in %s",
1735 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1736 return _error
->Error(_("You don't have enough free space in %s"),
1740 if (DebBytes
!= FetchBytes
)
1741 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
1742 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
1744 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
1745 SizeToStr(DebBytes
).c_str());
1747 if (_config
->FindB("APT::Get::Simulate",false) == true)
1749 for (unsigned I
= 0; I
!= J
; I
++)
1750 ioprintf(cout
,_("Fetch Source %s\n"),Dsc
[I
].Package
.c_str());
1754 // Just print out the uris an exit if the --print-uris flag was used
1755 if (_config
->FindB("APT::Get::Print-URIs") == true)
1757 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1758 for (; I
!= Fetcher
.UriEnd(); I
++)
1759 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1760 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1765 if (Fetcher
.Run() == pkgAcquire::Failed
)
1768 // Print error messages
1769 bool Failed
= false;
1770 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1772 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1773 (*I
)->Complete
== true)
1776 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1777 (*I
)->ErrorText
.c_str());
1781 return _error
->Error(_("Failed to fetch some archives."));
1783 if (_config
->FindB("APT::Get::Download-only",false) == true)
1785 c1out
<< _("Download complete and in download only mode") << endl
;
1789 // Unpack the sources
1790 pid_t Process
= ExecFork();
1794 for (unsigned I
= 0; I
!= J
; I
++)
1796 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
1798 // Diff only mode only fetches .diff files
1799 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
1800 _config
->FindB("APT::Get::Tar-Only",false) == true ||
1801 Dsc
[I
].Dsc
.empty() == true)
1804 // See if the package is already unpacked
1806 if (stat(Dir
.c_str(),&Stat
) == 0 &&
1807 S_ISDIR(Stat
.st_mode
) != 0)
1809 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
1816 snprintf(S
,sizeof(S
),"%s -x %s",
1817 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
1818 Dsc
[I
].Dsc
.c_str());
1821 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
1826 // Try to compile it with dpkg-buildpackage
1827 if (_config
->FindB("APT::Get::Compile",false) == true)
1829 // Call dpkg-buildpackage
1831 snprintf(S
,sizeof(S
),"cd %s && %s %s",
1833 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
1834 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
1838 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
1847 // Wait for the subprocess
1849 while (waitpid(Process
,&Status
,0) != Process
)
1853 return _error
->Errno("waitpid","Couldn't wait for subprocess");
1856 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
1857 return _error
->Error(_("Child process failed"));
1862 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
1863 // ---------------------------------------------------------------------
1864 /* This function will look at the build depends list of the given source
1865 package and install the necessary packages to make it true, or fail. */
1866 bool DoBuildDep(CommandLine
&CmdL
)
1869 if (Cache
.Open(true) == false)
1872 if (CmdL
.FileSize() <= 1)
1873 return _error
->Error(_("Must specify at least one package to check builddeps for"));
1875 // Read the source list
1877 if (List
.ReadMainList() == false)
1878 return _error
->Error(_("The list of sources could not be read."));
1880 // Create the text record parsers
1881 pkgRecords
Recs(Cache
);
1882 pkgSrcRecords
SrcRecs(List
);
1883 if (_error
->PendingError() == true)
1886 // Create the download object
1887 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1888 pkgAcquire
Fetcher(&Stat
);
1891 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1894 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
1896 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
1898 // Process the build-dependencies
1899 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
1900 if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only",false)) == false)
1901 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
1903 // Also ensure that build-essential packages are present
1904 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
1907 for (; Opts
; Opts
= Opts
->Next
)
1909 if (Opts
->Value
.empty() == true)
1912 pkgSrcRecords::Parser::BuildDepRec rec
;
1913 rec
.Package
= Opts
->Value
;
1914 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
1916 BuildDeps
.insert(BuildDeps
.begin(), rec
);
1919 if (BuildDeps
.size() == 0)
1921 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
1925 // Install the requested packages
1926 unsigned int ExpectedInst
= 0;
1927 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
1928 pkgProblemResolver
Fix(Cache
);
1929 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); D
++)
1931 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
1932 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
1934 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
1935 // Build-conflicts on unknown packages are silently ignored
1936 if (Pkg
.end() == true)
1939 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1942 * Remove if we have an installed version that satisfies the
1945 if (IV
.end() == false &&
1946 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1947 TryToInstall(Pkg
,Cache
,Fix
,true,false,ExpectedInst
);
1949 else // BuildDep || BuildDepIndep
1951 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
1952 if (Pkg
.end() == true)
1954 // Check if there are any alternatives
1955 if (((*D
).Op
& pkgCache::Dep::Or
) != pkgCache::Dep::Or
)
1956 return _error
->Error(_("%s dependency for %s cannot be satisfied "
1957 "because the package %s cannot be found"),
1958 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
1959 (*D
).Package
.c_str());
1960 // Try the next alternative
1965 * if there are alternatives, we've already picked one, so skip
1968 * TODO: this means that if there's a build-dep on A|B and B is
1969 * installed, we'll still try to install A; more importantly,
1970 * if A is currently broken, we cannot go back and try B. To fix
1971 * this would require we do a Resolve cycle for each package we
1972 * add to the install list. Ugh
1974 while (D
!= BuildDeps
.end() &&
1975 (((*D
).Op
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
))
1979 * If this is a virtual package, we need to check the list of
1980 * packages that provide it and see if any of those are
1983 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
1984 for (; Prv
.end() != true; Prv
++)
1985 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
1988 // Get installed version and version we are going to install
1989 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
1990 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1992 for (; CV
.end() != true; CV
++)
1994 if (Cache
->VS().CheckDep(CV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
1997 if (CV
.end() == true)
1998 return _error
->Error(_("%s dependency for %s cannot be satisfied "
1999 "because no available versions of package %s "
2000 "can satisfy version requirements"),
2001 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
2002 (*D
).Package
.c_str());
2005 * TODO: if we depend on a version lower than what we already have
2006 * installed it is not clear what should be done; in practice
2007 * this case should be rare, and right now nothing is
2010 if (Prv
.end() == true && // Nothing provides it; and
2011 (IV
.end() == true || // It is not installed, or
2012 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == false))
2013 // the version installed doesn't
2014 // satisfy constraints
2015 TryToInstall(Pkg
,Cache
,Fix
,false,false,ExpectedInst
);
2019 Fix
.InstallProtect();
2020 if (Fix
.Resolve(true) == false)
2023 // Now we check the state of the packages,
2024 if (Cache
->BrokenCount() != 0)
2025 return _error
->Error(_("Some broken packages were found while trying to process build-dependencies.\n"
2026 "You might want to run `apt-get -f install' to correct these."));
2029 if (InstallPackages(Cache
, false, true) == false)
2030 return _error
->Error(_("Failed to process build dependencies"));
2035 // DoMoo - Never Ask, Never Tell /*{{{*/
2036 // ---------------------------------------------------------------------
2038 bool DoMoo(CommandLine
&CmdL
)
2047 "....\"Have you mooed today?\"...\n";
2052 // ShowHelp - Show a help screen /*{{{*/
2053 // ---------------------------------------------------------------------
2055 bool ShowHelp(CommandLine
&CmdL
)
2057 ioprintf(cout
,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE
,VERSION
,
2058 COMMON_OS
,COMMON_CPU
,__DATE__
,__TIME__
);
2060 if (_config
->FindB("version") == true)
2062 cout
<< _("Supported Modules:") << endl
;
2064 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
2066 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
2067 if (_system
!= 0 && _system
->VS
== VS
)
2071 cout
<< "Ver: " << VS
->Label
<< endl
;
2073 /* Print out all the packaging systems that will work with
2075 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
2077 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
2082 if (Sys
->VS
->TestCompatibility(*VS
) == true)
2083 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
2087 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
2089 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
2090 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
2093 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
2095 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
2096 cout
<< " Idx: " << Type
->Label
<< endl
;
2103 _("Usage: apt-get [options] command\n"
2104 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
2105 " apt-get [options] source pkg1 [pkg2 ...]\n"
2107 "apt-get is a simple command line interface for downloading and\n"
2108 "installing packages. The most frequently used commands are update\n"
2112 " update - Retrieve new lists of packages\n"
2113 " upgrade - Perform an upgrade\n"
2114 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
2115 " remove - Remove packages\n"
2116 " source - Download source archives\n"
2117 " build-dep - Configure build-dependencies for source packages\n"
2118 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
2119 " dselect-upgrade - Follow dselect selections\n"
2120 " clean - Erase downloaded archive files\n"
2121 " autoclean - Erase old downloaded archive files\n"
2122 " check - Verify that there are no broken dependencies\n"
2125 " -h This help text.\n"
2126 " -q Loggable output - no progress indicator\n"
2127 " -qq No output except for errors\n"
2128 " -d Download only - do NOT install or unpack archives\n"
2129 " -s No-act. Perform ordering simulation\n"
2130 " -y Assume Yes to all queries and do not prompt\n"
2131 " -f Attempt to continue if the integrity check fails\n"
2132 " -m Attempt to continue if archives are unlocatable\n"
2133 " -u Show a list of upgraded packages as well\n"
2134 " -b Build the source package after fetching it\n"
2135 " -c=? Read this configuration file\n"
2136 " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n"
2137 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
2138 "pages for more information and options.\n"
2139 " This APT has Super Cow Powers.\n");
2143 // GetInitialize - Initialize things for apt-get /*{{{*/
2144 // ---------------------------------------------------------------------
2146 void GetInitialize()
2148 _config
->Set("quiet",0);
2149 _config
->Set("help",false);
2150 _config
->Set("APT::Get::Download-Only",false);
2151 _config
->Set("APT::Get::Simulate",false);
2152 _config
->Set("APT::Get::Assume-Yes",false);
2153 _config
->Set("APT::Get::Fix-Broken",false);
2154 _config
->Set("APT::Get::Force-Yes",false);
2155 _config
->Set("APT::Get::APT::Get::No-List-Cleanup",true);
2158 // SigWinch - Window size change signal handler /*{{{*/
2159 // ---------------------------------------------------------------------
2163 // Riped from GNU ls
2167 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
2168 ScreenWidth
= ws
.ws_col
- 1;
2173 int main(int argc
,const char *argv
[])
2175 CommandLine::Args Args
[] = {
2176 {'h',"help","help",0},
2177 {'v',"version","version",0},
2178 {'q',"quiet","quiet",CommandLine::IntLevel
},
2179 {'q',"silent","quiet",CommandLine::IntLevel
},
2180 {'d',"download-only","APT::Get::Download-Only",0},
2181 {'b',"compile","APT::Get::Compile",0},
2182 {'b',"build","APT::Get::Compile",0},
2183 {'s',"simulate","APT::Get::Simulate",0},
2184 {'s',"just-print","APT::Get::Simulate",0},
2185 {'s',"recon","APT::Get::Simulate",0},
2186 {'s',"dry-run","APT::Get::Simulate",0},
2187 {'s',"no-act","APT::Get::Simulate",0},
2188 {'y',"yes","APT::Get::Assume-Yes",0},
2189 {'y',"assume-yes","APT::Get::Assume-Yes",0},
2190 {'f',"fix-broken","APT::Get::Fix-Broken",0},
2191 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
2192 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
2193 {'t',"target-release","APT::Default-Release",CommandLine::HasArg
},
2194 {'t',"default-release","APT::Default-Release",CommandLine::HasArg
},
2195 {0,"download","APT::Get::Download",0},
2196 {0,"fix-missing","APT::Get::Fix-Missing",0},
2197 {0,"ignore-hold","APT::Ignore-Hold",0},
2198 {0,"upgrade","APT::Get::upgrade",0},
2199 {0,"force-yes","APT::Get::force-yes",0},
2200 {0,"print-uris","APT::Get::Print-URIs",0},
2201 {0,"diff-only","APT::Get::Diff-Only",0},
2202 {0,"tar-only","APT::Get::tar-Only",0},
2203 {0,"purge","APT::Get::Purge",0},
2204 {0,"list-cleanup","APT::Get::List-Cleanup",0},
2205 {0,"reinstall","APT::Get::ReInstall",0},
2206 {0,"trivial-only","APT::Get::Trivial-Only",0},
2207 {0,"remove","APT::Get::Remove",0},
2208 {0,"only-source","APT::Get::Only-Source",0},
2209 {0,"arch-only","APT::Get::Arch-Only",0},
2210 {'c',"config-file",0,CommandLine::ConfigFile
},
2211 {'o',"option",0,CommandLine::ArbItem
},
2213 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
2214 {"upgrade",&DoUpgrade
},
2215 {"install",&DoInstall
},
2216 {"remove",&DoInstall
},
2217 {"dist-upgrade",&DoDistUpgrade
},
2218 {"dselect-upgrade",&DoDSelectUpgrade
},
2219 {"build-dep",&DoBuildDep
},
2221 {"autoclean",&DoAutoClean
},
2223 {"source",&DoSource
},
2228 // Set up gettext support
2229 setlocale(LC_ALL
,"");
2230 textdomain(PACKAGE
);
2232 // Parse the command line and initialize the package library
2233 CommandLine
CmdL(Args
,_config
);
2234 if (pkgInitConfig(*_config
) == false ||
2235 CmdL
.Parse(argc
,argv
) == false ||
2236 pkgInitSystem(*_config
,_system
) == false)
2238 if (_config
->FindB("version") == true)
2241 _error
->DumpErrors();
2245 // See if the help should be shown
2246 if (_config
->FindB("help") == true ||
2247 _config
->FindB("version") == true ||
2248 CmdL
.FileSize() == 0)
2254 // Deal with stdout not being a tty
2255 if (ttyname(STDOUT_FILENO
) == 0 && _config
->FindI("quiet",0) < 1)
2256 _config
->Set("quiet","1");
2258 // Setup the output streams
2259 c0out
.rdbuf(cout
.rdbuf());
2260 c1out
.rdbuf(cout
.rdbuf());
2261 c2out
.rdbuf(cout
.rdbuf());
2262 if (_config
->FindI("quiet",0) > 0)
2263 c0out
.rdbuf(devnull
.rdbuf());
2264 if (_config
->FindI("quiet",0) > 1)
2265 c1out
.rdbuf(devnull
.rdbuf());
2267 // Setup the signals
2268 signal(SIGPIPE
,SIG_IGN
);
2269 signal(SIGWINCH
,SigWinch
);
2272 // Match the operation
2273 CmdL
.DispatchArg(Cmds
);
2275 // Print any errors or warnings found during parsing
2276 if (_error
->empty() == false)
2278 bool Errors
= _error
->PendingError();
2279 _error
->DumpErrors();
2280 return Errors
== true?100:0;