]>
git.saurik.com Git - apt-legacy.git/blob - cmdline/apt-get.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.156 2004/08/28 01:05:16 mdz 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/md5.h>
42 #include <apt-pkg/versionmatch.h>
47 #include "acqprogress.h"
54 #include <sys/ioctl.h>
56 #include <sys/param.h>
57 #include <sys/mount.h>
58 #include <sys/statvfs.h>
68 #define RAMFS_MAGIC 0x858458f6
70 #define _trace() printf("_trace(%s:%d)\n", __FILE__, __LINE__)
77 unsigned int ScreenWidth
= 80 - 1; /* - 1 for the cursor */
79 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
80 // ---------------------------------------------------------------------
82 class CacheFile
: public pkgCacheFile
84 static pkgCache
*SortCache
;
85 static int NameComp(const void *a
,const void *b
);
88 pkgCache::Package
**List
;
91 bool CheckDeps(bool AllowBroken
= false);
92 bool BuildCaches(bool WithLock
= true)
94 OpTextProgress
Prog(*_config
);
95 if (pkgCacheFile::BuildCaches(Prog
,WithLock
) == false)
99 bool Open(bool WithLock
= true)
101 OpTextProgress
Prog(*_config
);
102 if (pkgCacheFile::Open(Prog
,WithLock
) == false)
108 bool OpenForInstall()
110 if (_config
->FindB("APT::Get::Print-URIs") == true)
115 CacheFile() : List(0) {};
122 // YnPrompt - Yes No Prompt. /*{{{*/
123 // ---------------------------------------------------------------------
124 /* Returns true on a Yes.*/
125 bool YnPrompt(bool Default
=true)
127 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
129 c1out
<< _("Y") << endl
;
133 char response
[1024] = "";
134 cin
.getline(response
, sizeof(response
));
139 if (strlen(response
) == 0)
145 Res
= regcomp(&Pattern
, nl_langinfo(YESEXPR
),
146 REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
150 regerror(Res
,&Pattern
,Error
,sizeof(Error
));
151 return _error
->Error(_("Regex compilation error - %s"),Error
);
154 Res
= regexec(&Pattern
, response
, 0, NULL
, 0);
160 // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
161 // ---------------------------------------------------------------------
162 /* Returns true on a Yes.*/
163 bool AnalPrompt(const char *Text
)
166 cin
.getline(Buf
,sizeof(Buf
));
167 if (strcmp(Buf
,Text
) == 0)
172 // ShowList - Show a list /*{{{*/
173 // ---------------------------------------------------------------------
174 /* This prints out a string of space separated words with a title and
175 a two space indent line wraped to the current screen width. */
176 bool ShowList(ostream
&out
,string Title
,string List
,string VersionsList
)
178 if (List
.empty() == true)
180 // trim trailing space
181 int NonSpace
= List
.find_last_not_of(' ');
184 List
= List
.erase(NonSpace
+ 1);
185 if (List
.empty() == true)
189 // Acount for the leading space
190 int ScreenWidth
= ::ScreenWidth
- 3;
192 out
<< Title
<< endl
;
193 string::size_type Start
= 0;
194 string::size_type VersionsStart
= 0;
195 while (Start
< List
.size())
197 if(_config
->FindB("APT::Get::Show-Versions",false) == true &&
198 VersionsList
.size() > 0) {
199 string::size_type End
;
200 string::size_type VersionsEnd
;
202 End
= List
.find(' ',Start
);
203 VersionsEnd
= VersionsList
.find('\n', VersionsStart
);
205 out
<< " " << string(List
,Start
,End
- Start
) << " (" <<
206 string(VersionsList
,VersionsStart
,VersionsEnd
- VersionsStart
) <<
209 if (End
== string::npos
|| End
< Start
)
210 End
= Start
+ ScreenWidth
;
213 VersionsStart
= VersionsEnd
+ 1;
215 string::size_type End
;
217 if (Start
+ ScreenWidth
>= List
.size())
220 End
= List
.rfind(' ',Start
+ScreenWidth
);
222 if (End
== string::npos
|| End
< Start
)
223 End
= Start
+ ScreenWidth
;
224 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
232 // ShowBroken - Debugging aide /*{{{*/
233 // ---------------------------------------------------------------------
234 /* This prints out the names of all the packages that are broken along
235 with the name of each each broken dependency and a quite version
238 The output looks like:
239 The following packages have unmet dependencies:
240 exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed
241 Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
242 Depends: libsasl7 but it is not going to be installed
244 void ShowBroken(ostream
&out
,CacheFile
&Cache
,bool Now
)
246 out
<< _("The following packages have unmet dependencies:") << endl
;
247 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
249 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
253 if (Cache
[I
].NowBroken() == false)
258 if (Cache
[I
].InstBroken() == false)
262 // Print out each package and the failed dependencies
263 out
<<" " << I
.Name() << ":";
264 unsigned Indent
= strlen(I
.Name()) + 3;
266 pkgCache::VerIterator Ver
;
269 Ver
= I
.CurrentVer();
271 Ver
= Cache
[I
].InstVerIter(Cache
);
273 if (Ver
.end() == true)
279 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false;)
281 // Compute a single dependency element (glob or)
282 pkgCache::DepIterator Start
;
283 pkgCache::DepIterator End
;
284 D
.GlobOr(Start
,End
); // advances D
286 if (Cache
->IsImportantDep(End
) == false)
291 if ((Cache
[End
] & pkgDepCache::DepGNow
) == pkgDepCache::DepGNow
)
296 if ((Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
304 for (unsigned J
= 0; J
!= Indent
; J
++)
308 if (FirstOr
== false)
310 for (unsigned J
= 0; J
!= strlen(End
.DepType()) + 3; J
++)
314 out
<< ' ' << End
.DepType() << ": ";
317 out
<< Start
.TargetPkg().Name();
319 // Show a quick summary of the version requirements
320 if (Start
.TargetVer() != 0)
321 out
<< " (" << Start
.CompType() << " " << Start
.TargetVer() << ")";
323 /* Show a summary of the target package if possible. In the case
324 of virtual packages we show nothing */
325 pkgCache::PkgIterator Targ
= Start
.TargetPkg();
326 if (Targ
->ProvidesList
== 0)
329 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
331 Ver
= Targ
.CurrentVer();
333 if (Ver
.end() == false)
336 ioprintf(out
,_("but %s is installed"),Ver
.VerStr());
338 ioprintf(out
,_("but %s is to be installed"),Ver
.VerStr());
342 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
344 if (Targ
->ProvidesList
== 0)
345 out
<< _("but it is not installable");
347 out
<< _("but it is a virtual package");
350 out
<< (Now
?_("but it is not installed"):_("but it is not going to be installed"));
366 // ShowNew - Show packages to newly install /*{{{*/
367 // ---------------------------------------------------------------------
369 void ShowNew(ostream
&out
,CacheFile
&Cache
)
371 /* Print out a list of packages that are going to be installed extra
372 to what the user asked */
375 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
377 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
378 if (Cache
[I
].NewInstall() == true) {
379 List
+= string(I
.Name()) + " ";
380 VersionsList
+= string(Cache
[I
].CandVersion
) + "\n";
384 ShowList(out
,_("The following NEW packages will be installed:"),List
,VersionsList
);
387 // ShowDel - Show packages to delete /*{{{*/
388 // ---------------------------------------------------------------------
390 void ShowDel(ostream
&out
,CacheFile
&Cache
)
392 /* Print out a list of packages that are going to be removed extra
393 to what the user asked */
396 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
398 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
399 if (Cache
[I
].Delete() == true)
401 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
402 List
+= string(I
.Name()) + "* ";
404 List
+= string(I
.Name()) + " ";
406 VersionsList
+= string(Cache
[I
].CandVersion
)+ "\n";
410 ShowList(out
,_("The following packages will be REMOVED:"),List
,VersionsList
);
413 // ShowKept - Show kept packages /*{{{*/
414 // ---------------------------------------------------------------------
416 void ShowKept(ostream
&out
,CacheFile
&Cache
)
420 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
422 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
425 if (Cache
[I
].Upgrade() == true || Cache
[I
].Upgradable() == false ||
426 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
429 List
+= string(I
.Name()) + " ";
430 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
432 ShowList(out
,_("The following packages have been kept back:"),List
,VersionsList
);
435 // ShowUpgraded - Show upgraded packages /*{{{*/
436 // ---------------------------------------------------------------------
438 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
442 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
444 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
447 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
450 List
+= string(I
.Name()) + " ";
451 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
453 ShowList(out
,_("The following packages will be upgraded:"),List
,VersionsList
);
456 // ShowDowngraded - Show downgraded packages /*{{{*/
457 // ---------------------------------------------------------------------
459 bool ShowDowngraded(ostream
&out
,CacheFile
&Cache
)
463 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
465 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
468 if (Cache
[I
].Downgrade() == false || Cache
[I
].NewInstall() == true)
471 List
+= string(I
.Name()) + " ";
472 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
474 return ShowList(out
,_("The following packages will be DOWNGRADED:"),List
,VersionsList
);
477 // ShowHold - Show held but changed packages /*{{{*/
478 // ---------------------------------------------------------------------
480 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
484 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
486 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
487 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
488 I
->SelectedState
== pkgCache::State::Hold
) {
489 List
+= string(I
.Name()) + " ";
490 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
494 return ShowList(out
,_("The following held packages will be changed:"),List
,VersionsList
);
497 // ShowEssential - Show an essential package warning /*{{{*/
498 // ---------------------------------------------------------------------
499 /* This prints out a warning message that is not to be ignored. It shows
500 all essential packages and their dependents that are to be removed.
501 It is insanely risky to remove the dependents of an essential package! */
502 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
506 bool *Added
= new bool[Cache
->Head().PackageCount
];
507 for (unsigned int I
= 0; I
!= Cache
->Head().PackageCount
; I
++)
510 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
512 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
513 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
&&
514 (I
->Flags
& pkgCache::Flag::Important
) != pkgCache::Flag::Important
)
517 // The essential package is being removed
518 if (Cache
[I
].Delete() == true)
520 if (Added
[I
->ID
] == false)
523 List
+= string(I
.Name()) + " ";
524 //VersionsList += string(Cache[I].CurVersion) + "\n"; ???
528 if (I
->CurrentVer
== 0)
531 // Print out any essential package depenendents that are to be removed
532 for (pkgCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
534 // Skip everything but depends
535 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
536 D
->Type
!= pkgCache::Dep::Depends
)
539 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
540 if (Cache
[P
].Delete() == true)
542 if (Added
[P
->ID
] == true)
547 snprintf(S
,sizeof(S
),_("%s (due to %s) "),P
.Name(),I
.Name());
549 //VersionsList += "\n"; ???
555 return ShowList(out
,_("WARNING: The following essential packages will be removed.\n"
556 "This should NOT be done unless you know exactly what you are doing!"),List
,VersionsList
);
560 // Stats - Show some statistics /*{{{*/
561 // ---------------------------------------------------------------------
563 void Stats(ostream
&out
,pkgDepCache
&Dep
)
565 unsigned long Upgrade
= 0;
566 unsigned long Downgrade
= 0;
567 unsigned long Install
= 0;
568 unsigned long ReInstall
= 0;
569 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
571 if (Dep
[I
].NewInstall() == true)
575 if (Dep
[I
].Upgrade() == true)
578 if (Dep
[I
].Downgrade() == true)
582 if (Dep
[I
].Delete() == false && (Dep
[I
].iFlags
& pkgDepCache::ReInstall
) == pkgDepCache::ReInstall
)
586 ioprintf(out
,_("%lu upgraded, %lu newly installed, "),
590 ioprintf(out
,_("%lu reinstalled, "),ReInstall
);
592 ioprintf(out
,_("%lu downgraded, "),Downgrade
);
594 ioprintf(out
,_("%lu to remove and %lu not upgraded.\n"),
595 Dep
.DelCount(),Dep
.KeepCount());
597 if (Dep
.BadCount() != 0)
598 ioprintf(out
,_("%lu not fully installed or removed.\n"),
602 // CacheFile::NameComp - QSort compare by name /*{{{*/
603 // ---------------------------------------------------------------------
605 pkgCache
*CacheFile::SortCache
= 0;
606 int CacheFile::NameComp(const void *a
,const void *b
)
608 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
609 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
611 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
612 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
614 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
617 // CacheFile::Sort - Sort by name /*{{{*/
618 // ---------------------------------------------------------------------
620 void CacheFile::Sort()
623 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
624 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
625 pkgCache::PkgIterator I
= Cache
->PkgBegin();
626 for (;I
.end() != true; I
++)
630 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
633 // CacheFile::CheckDeps - Open the cache file /*{{{*/
634 // ---------------------------------------------------------------------
635 /* This routine generates the caches and then opens the dependency cache
636 and verifies that the system is OK. */
637 bool CacheFile::CheckDeps(bool AllowBroken
)
639 bool FixBroken
= _config
->FindB("APT::Get::Fix-Broken",false);
641 if (_error
->PendingError() == true)
644 // Check that the system is OK
645 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
646 return _error
->Error("Internal error, non-zero counts");
648 // Apply corrections for half-installed packages
649 if (pkgApplyStatus(*DCache
) == false)
652 if (_config
->FindB("APT::Get::Fix-Policy-Broken",false) == true)
655 if ((DCache
->PolicyBrokenCount() > 0))
657 // upgrade all policy-broken packages with ForceImportantDeps=True
658 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); !I
.end(); I
++)
659 if ((*DCache
)[I
].NowPolicyBroken() == true)
660 DCache
->MarkInstall(I
,true,0, false, true);
665 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
668 // Attempt to fix broken things
669 if (FixBroken
== true)
671 c1out
<< _("Correcting dependencies...") << flush
;
672 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
674 c1out
<< _(" failed.") << endl
;
675 ShowBroken(c1out
,*this,true);
677 return _error
->Error(_("Unable to correct dependencies"));
679 if (pkgMinimizeUpgrade(*DCache
) == false)
680 return _error
->Error(_("Unable to minimize the upgrade set"));
682 c1out
<< _(" Done") << endl
;
686 c1out
<< _("You might want to run `apt-get -f install' to correct these.") << endl
;
687 ShowBroken(c1out
,*this,true);
689 return _error
->Error(_("Unmet dependencies. Try using -f."));
695 // CheckAuth - check if each download comes form a trusted source /*{{{*/
696 // ---------------------------------------------------------------------
698 static bool CheckAuth(pkgAcquire
& Fetcher
)
700 string UntrustedList
;
701 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd(); ++I
)
703 if (!(*I
)->IsTrusted())
705 UntrustedList
+= string((*I
)->ShortDesc()) + " ";
709 if (UntrustedList
== "")
714 ShowList(c2out
,_("WARNING: The following packages cannot be authenticated!"),UntrustedList
,"");
716 if (_config
->FindB("APT::Get::AllowUnauthenticated",false) == true)
718 c2out
<< _("Authentication warning overridden.\n");
722 if (_config
->FindI("quiet",0) < 2
723 && _config
->FindB("APT::Get::Assume-Yes",false) == false)
725 c2out
<< _("Install these packages without verification [y/N]? ") << flush
;
726 if (!YnPrompt(false))
727 return _error
->Error(_("Some packages could not be authenticated"));
731 else if (_config
->FindB("APT::Get::Force-Yes",false) == true)
736 return _error
->Error(_("There are problems and -y was used without --force-yes"));
739 // InstallPackages - Actually download and install the packages /*{{{*/
740 // ---------------------------------------------------------------------
741 /* This displays the informative messages describing what is going to
742 happen and then calls the download routines */
743 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,
746 if (_config
->FindB("APT::Get::Purge",false) == true)
748 pkgCache::PkgIterator I
= Cache
->PkgBegin();
749 for (; I
.end() == false; I
++)
751 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
752 Cache
->MarkDelete(I
,true);
757 bool Essential
= false;
759 // Show all the various warning indicators
760 ShowDel(c1out
,Cache
);
761 ShowNew(c1out
,Cache
);
763 ShowKept(c1out
,Cache
);
764 Fail
|= !ShowHold(c1out
,Cache
);
765 if (_config
->FindB("APT::Get::Show-Upgraded",true) == true)
766 ShowUpgraded(c1out
,Cache
);
767 Fail
|= !ShowDowngraded(c1out
,Cache
);
768 if (_config
->FindB("APT::Get::Download-Only",false) == false)
769 Essential
= !ShowEssential(c1out
,Cache
);
774 if (Cache
->BrokenCount() != 0)
776 ShowBroken(c1out
,Cache
,false);
777 return _error
->Error(_("Internal error, InstallPackages was called with broken packages!"));
780 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
781 Cache
->BadCount() == 0)
785 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::Remove",true) == false)
786 return _error
->Error(_("Packages need to be removed but remove is disabled."));
788 // Run the simulator ..
789 if (_config
->FindB("APT::Get::Simulate") == true)
791 pkgSimulate
PM(Cache
);
792 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
793 pkgPackageManager::OrderResult Res
= PM
.DoInstall(status_fd
);
794 if (Res
== pkgPackageManager::Failed
)
796 if (Res
!= pkgPackageManager::Completed
)
797 return _error
->Error(_("Internal error, Ordering didn't finish"));
801 // Create the text record parser
802 pkgRecords
Recs(Cache
);
803 if (_error
->PendingError() == true)
806 // Lock the archive directory
808 if (_config
->FindB("Debug::NoLocking",false) == false &&
809 _config
->FindB("APT::Get::Print-URIs") == false)
811 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
812 if (_error
->PendingError() == true)
813 return _error
->Error(_("Unable to lock the download directory"));
816 // Create the download object
817 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
818 pkgAcquire
Fetcher(&Stat
);
820 // Read the source list
822 if (List
.ReadMainList() == false)
823 return _error
->Error(_("The list of sources could not be read."));
825 // Create the package manager and prepare to download
826 SPtr
<pkgPackageManager
> PM
= _system
->CreatePM(Cache
);
827 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false ||
828 _error
->PendingError() == true)
831 // Display statistics
832 double FetchBytes
= Fetcher
.FetchNeeded();
833 double FetchPBytes
= Fetcher
.PartialPresent();
834 double DebBytes
= Fetcher
.TotalNeeded();
835 if (DebBytes
!= Cache
->DebSize())
837 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
838 c0out
<< _("How odd.. The sizes didn't match, email apt@packages.debian.org") << endl
;
842 if (DebBytes
!= FetchBytes
)
843 ioprintf(c1out
,_("Need to get %sB/%sB of archives.\n"),
844 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
845 else if (DebBytes
!= 0)
846 ioprintf(c1out
,_("Need to get %sB of archives.\n"),
847 SizeToStr(DebBytes
).c_str());
850 if (Cache
->UsrSize() >= 0)
851 ioprintf(c1out
,_("After this operation, %sB of additional disk space will be used.\n"),
852 SizeToStr(Cache
->UsrSize()).c_str());
854 ioprintf(c1out
,_("After this operation, %sB disk space will be freed.\n"),
855 SizeToStr(-1*Cache
->UsrSize()).c_str());
857 if (_error
->PendingError() == true)
860 /* Check for enough free space, but only if we are actually going to
862 if (_config
->FindB("APT::Get::Print-URIs") == false &&
863 _config
->FindB("APT::Get::Download",true) == true)
866 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
867 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
868 if (errno
== EOVERFLOW
)
869 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
872 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
874 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
877 if (statfs(OutputDir
.c_str(),&Stat
) != 0
878 #if HAVE_STRUCT_STATFS_F_TYPE
879 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
882 return _error
->Error(_("You don't have enough free space in %s."),
888 if (_config
->FindI("quiet",0) >= 2 ||
889 _config
->FindB("APT::Get::Assume-Yes",false) == true)
891 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
892 return _error
->Error(_("There are problems and -y was used without --force-yes"));
895 if (Essential
== true && Safety
== true)
897 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
898 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
900 const char *Prompt
= _("Yes, do as I say!");
902 _("You are about to do something potentially harmful.\n"
903 "To continue type in the phrase '%s'\n"
906 if (AnalPrompt(Prompt
) == false)
908 c2out
<< _("Abort.") << endl
;
914 // Prompt to continue
915 if (Ask
== true || Fail
== true)
917 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
918 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
920 if (_config
->FindI("quiet",0) < 2 &&
921 _config
->FindB("APT::Get::Assume-Yes",false) == false)
923 c2out
<< _("Do you want to continue [Y/n]? ") << flush
;
925 if (YnPrompt() == false)
927 c2out
<< _("Abort.") << endl
;
934 // Just print out the uris an exit if the --print-uris flag was used
935 if (_config
->FindB("APT::Get::Print-URIs") == true)
937 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
938 for (; I
!= Fetcher
.UriEnd(); I
++)
939 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
940 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
944 if (!CheckAuth(Fetcher
))
947 /* Unlock the dpkg lock if we are not going to be doing an install
949 if (_config
->FindB("APT::Get::Download-Only",false) == true)
955 bool Transient
= false;
956 if (_config
->FindB("APT::Get::Download",true) == false)
958 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
960 if ((*I
)->Local
== true)
966 // Close the item and check if it was found in cache
968 if ((*I
)->Complete
== false)
971 // Clear it out of the fetch list
973 I
= Fetcher
.ItemsBegin();
977 if (Fetcher
.Run() == pkgAcquire::Failed
)
982 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
984 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
985 (*I
)->Complete
== true)
988 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
995 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
996 (*I
)->ErrorText
.c_str());
1000 /* If we are in no download mode and missing files and there were
1001 'failures' then the user must specify -m. Furthermore, there
1002 is no such thing as a transient error in no-download mode! */
1003 if (Transient
== true &&
1004 _config
->FindB("APT::Get::Download",true) == false)
1010 if (_config
->FindB("APT::Get::Download-Only",false) == true)
1012 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
1013 return _error
->Error(_("Some files failed to download"));
1014 c1out
<< _("Download complete and in download only mode") << endl
;
1018 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
1020 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
1023 if (Transient
== true && Failed
== true)
1024 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
1026 // Try to deal with missing package files
1027 if (Failed
== true && PM
->FixMissing() == false)
1029 cerr
<< _("Unable to correct missing packages.") << endl
;
1030 return _error
->Error(_("Aborting install."));
1034 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
1035 pkgPackageManager::OrderResult Res
= PM
->DoInstall(status_fd
);
1036 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
1038 if (Res
== pkgPackageManager::Completed
)
1041 // Reload the fetcher object and loop again for media swapping
1043 if (PM
->GetArchives(&Fetcher
,&List
,&Recs
) == false)
1050 // TryToInstall - Try to install a single package /*{{{*/
1051 // ---------------------------------------------------------------------
1052 /* This used to be inlined in DoInstall, but with the advent of regex package
1053 name matching it was split out.. */
1054 bool TryToInstall(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
1055 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
1056 unsigned int &ExpectedInst
,bool AllowFail
= true)
1058 /* This is a pure virtual package and there is a single available
1059 candidate providing it. */
1060 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0)
1062 pkgCache::PkgIterator Prov
;
1063 bool found_one
= false;
1065 for (pkgCache::PrvIterator P
= Pkg
.ProvidesList(); P
; P
++)
1067 pkgCache::VerIterator
const PVer
= P
.OwnerVer();
1068 pkgCache::PkgIterator
const PPkg
= PVer
.ParentPkg();
1070 /* Ignore versions that are not a candidate. */
1071 if (Cache
[PPkg
].CandidateVer
!= PVer
)
1074 if (found_one
== false)
1079 else if (PPkg
!= Prov
)
1081 found_one
= false; // we found at least two
1086 if (found_one
== true)
1088 ioprintf(c1out
,_("Note, selecting %s instead of %s\n"),
1089 Prov
.Name(),Pkg
.Name());
1094 // Handle the no-upgrade case
1095 if (_config
->FindB("APT::Get::upgrade",true) == false &&
1096 Pkg
->CurrentVer
!= 0)
1098 if (AllowFail
== true)
1099 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
1104 // Check if there is something at all to install
1105 pkgDepCache::StateCache
&State
= Cache
[Pkg
];
1106 if (Remove
== true && Pkg
->CurrentVer
== 0)
1112 /* We want to continue searching for regex hits, so we return false here
1113 otherwise this is not really an error. */
1114 if (AllowFail
== false)
1117 ioprintf(c1out
,_("Package %s is not installed, so not removed\n"),Pkg
.Name());
1121 if (State
.CandidateVer
== 0 && Remove
== false)
1123 if (AllowFail
== false)
1126 if (Pkg
->ProvidesList
!= 0)
1128 ioprintf(c1out
,_("Package %s is a virtual package provided by:\n"),
1131 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
1132 for (; I
.end() == false; I
++)
1134 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
1136 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer())
1138 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
1139 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
1140 _(" [Installed]") << endl
;
1142 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
1145 c1out
<< _("You should explicitly select one to install.") << endl
;
1150 _("Package %s is not available, but is referred to by another package.\n"
1151 "This may mean that the package is missing, has been obsoleted, or\n"
1152 "is only available from another source\n"),Pkg
.Name());
1155 string VersionsList
;
1156 SPtrArray
<bool> Seen
= new bool[Cache
.Head().PackageCount
];
1157 memset(Seen
,0,Cache
.Head().PackageCount
*sizeof(*Seen
));
1158 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
1159 for (; Dep
.end() == false; Dep
++)
1161 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
1163 if (Seen
[Dep
.ParentPkg()->ID
] == true)
1165 Seen
[Dep
.ParentPkg()->ID
] = true;
1166 List
+= string(Dep
.ParentPkg().Name()) + " ";
1167 //VersionsList += string(Dep.ParentPkg().CurVersion) + "\n"; ???
1169 ShowList(c1out
,_("However the following packages replace it:"),List
,VersionsList
);
1172 _error
->Error(_("Package %s has no installation candidate"),Pkg
.Name());
1181 Cache
.MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
1186 Cache
.MarkInstall(Pkg
,false);
1187 if (State
.Install() == false)
1189 if (_config
->FindB("APT::Get::ReInstall",false) == true)
1191 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
1192 ioprintf(c1out
,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
1195 Cache
.SetReInstall(Pkg
,true);
1199 if (AllowFail
== true)
1200 ioprintf(c1out
,_("%s is already the newest version.\n"),
1207 // Install it with autoinstalling enabled (if we not respect the minial
1208 // required deps or the policy)
1209 if ((State
.InstBroken() == true || State
.InstPolicyBroken() == true) && BrokenFix
== false)
1210 Cache
.MarkInstall(Pkg
,true);
1215 // TryToChangeVer - Try to change a candidate version /*{{{*/
1216 // ---------------------------------------------------------------------
1218 bool TryToChangeVer(pkgCache::PkgIterator Pkg
,pkgDepCache
&Cache
,
1219 const char *VerTag
,bool IsRel
)
1221 pkgVersionMatch
Match(VerTag
,(IsRel
== true?pkgVersionMatch::Release
:
1222 pkgVersionMatch::Version
));
1224 pkgCache::VerIterator Ver
= Match
.Find(Pkg
);
1226 if (Ver
.end() == true)
1229 return _error
->Error(_("Release '%s' for '%s' was not found"),
1231 return _error
->Error(_("Version '%s' for '%s' was not found"),
1235 if (strcmp(VerTag
,Ver
.VerStr()) != 0)
1237 ioprintf(c1out
,_("Selected version %s (%s) for %s\n"),
1238 Ver
.VerStr(),Ver
.RelStr().c_str(),Pkg
.Name());
1241 Cache
.SetCandidateVersion(Ver
);
1245 // FindSrc - Find a source record /*{{{*/
1246 // ---------------------------------------------------------------------
1248 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
1249 pkgSrcRecords
&SrcRecs
,string
&Src
,
1253 string DefRel
= _config
->Find("APT::Default-Release");
1254 string TmpSrc
= Name
;
1256 // extract the version/release from the pkgname
1257 const size_t found
= TmpSrc
.find_last_of("/=");
1258 if (found
!= string::npos
) {
1259 if (TmpSrc
[found
] == '/')
1260 DefRel
= TmpSrc
.substr(found
+1);
1262 VerTag
= TmpSrc
.substr(found
+1);
1263 TmpSrc
= TmpSrc
.substr(0,found
);
1266 /* Lookup the version of the package we would install if we were to
1267 install a version and determine the source package name, then look
1268 in the archive for a source package of the same name. */
1269 bool MatchSrcOnly
= _config
->FindB("APT::Get::Only-Source");
1270 const pkgCache::PkgIterator Pkg
= Cache
.FindPkg(TmpSrc
);
1271 if (MatchSrcOnly
== false && Pkg
.end() == false)
1273 if(VerTag
.empty() == false || DefRel
.empty() == false)
1275 // we have a default release, try to locate the pkg. we do it like
1276 // this because GetCandidateVer() will not "downgrade", that means
1277 // "apt-get source -t stable apt" won't work on a unstable system
1278 for (pkgCache::VerIterator Ver
= Pkg
.VersionList();
1279 Ver
.end() == false; Ver
++)
1281 for (pkgCache::VerFileIterator VF
= Ver
.FileList();
1282 VF
.end() == false; VF
++)
1284 /* If this is the status file, and the current version is not the
1285 version in the status file (ie it is not installed, or somesuch)
1286 then it is not a candidate for installation, ever. This weeds
1287 out bogus entries that may be due to config-file states, or
1289 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) ==
1290 pkgCache::Flag::NotSource
&& Pkg
.CurrentVer() != Ver
)
1293 // We match against a concrete version (or a part of this version)
1294 if (VerTag
.empty() == false && strncmp(VerTag
.c_str(), Ver
.VerStr(), VerTag
.size()) != 0)
1297 // or we match against a release
1298 if(VerTag
.empty() == false ||
1299 (VF
.File().Archive() != 0 && VF
.File().Archive() == DefRel
))
1301 pkgRecords::Parser
&Parse
= Recs
.Lookup(VF
);
1302 Src
= Parse
.SourcePkg();
1303 // no SourcePkg name, so it is the "binary" name
1304 if (Src
.empty() == true)
1306 // no Version, so we try the Version of the SourcePkg -
1307 // and after that the version of the binary package
1308 if (VerTag
.empty() == true)
1309 VerTag
= Parse
.SourceVer();
1310 if (VerTag
.empty() == true)
1311 VerTag
= Ver
.VerStr();
1315 if (Src
.empty() == false)
1318 if (Src
.empty() == true)
1320 // Sources files have no codename information
1321 if (VerTag
.empty() == true && DefRel
.empty() == false)
1322 _error
->Warning(_("Ignore unavailable target release '%s' of package '%s'"), DefRel
.c_str(), TmpSrc
.c_str());
1326 if (Src
.empty() == true)
1328 // if we don't have found a fitting package yet so we will
1329 // choose a good candidate and proceed with that.
1330 // Maybe we will find a source later on with the right VerTag
1331 pkgCache::VerIterator Ver
= Cache
.GetCandidateVer(Pkg
);
1332 if (Ver
.end() == false)
1334 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1335 Src
= Parse
.SourcePkg();
1336 if (VerTag
.empty() == true)
1337 VerTag
= Parse
.SourceVer();
1342 if (Src
.empty() == true)
1346 /* if we have a source pkg name, make sure to only search
1347 for srcpkg names, otherwise apt gets confused if there
1348 is a binary package "pkg1" and a source package "pkg1"
1349 with the same name but that comes from different packages */
1350 MatchSrcOnly
= true;
1353 ioprintf(c1out
, _("Picking '%s' as source package instead of '%s'\n"), Src
.c_str(), TmpSrc
.c_str());
1358 pkgSrcRecords::Parser
*Last
= 0;
1359 unsigned long Offset
= 0;
1362 /* Iterate over all of the hits, which includes the resulting
1363 binary packages in the search */
1364 pkgSrcRecords::Parser
*Parse
;
1368 while ((Parse
= SrcRecs
.Find(Src
.c_str(), MatchSrcOnly
)) != 0)
1370 const string Ver
= Parse
->Version();
1372 // Ignore all versions which doesn't fit
1373 if (VerTag
.empty() == false && strncmp(VerTag
.c_str(), Ver
.c_str(), VerTag
.size()) != 0)
1376 // Newer version or an exact match? Save the hit
1377 if (Last
== 0 || Cache
.VS().CmpVersion(Version
,Ver
) < 0) {
1379 Offset
= Parse
->Offset();
1383 // was the version check above an exact match? If so, we don't need to look further
1384 if (VerTag
.empty() == false && VerTag
.size() == Ver
.size())
1387 if (Last
!= 0 || VerTag
.empty() == true)
1389 //if (VerTag.empty() == false && Last == 0)
1390 _error
->Warning(_("Ignore unavailable version '%s' of package '%s'"), VerTag
.c_str(), TmpSrc
.c_str());
1394 if (Last
== 0 || Last
->Jump(Offset
) == false)
1400 // DoUpdate - Update the package lists /*{{{*/
1401 // ---------------------------------------------------------------------
1403 bool DoUpdate(CommandLine
&CmdL
)
1405 if (CmdL
.FileSize() != 1)
1406 return _error
->Error(_("The update command takes no arguments"));
1408 // Get the source list
1410 if (List
.ReadMainList() == false)
1413 // Lock the list directory
1415 if (_config
->FindB("Debug::NoLocking",false) == false)
1417 Lock
.Fd(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
1418 if (_error
->PendingError() == true)
1419 return _error
->Error(_("Unable to lock the list directory"));
1422 // Create the progress
1423 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1425 // Just print out the uris an exit if the --print-uris flag was used
1426 if (_config
->FindB("APT::Get::Print-URIs") == true)
1429 pkgAcquire
Fetcher(&Stat
);
1431 // Populate it with the source selection and get all Indexes
1433 if (List
.GetIndexes(&Fetcher
,true) == false)
1436 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1437 for (; I
!= Fetcher
.UriEnd(); I
++)
1438 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1439 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
1445 if (_config
->FindB("APT::Get::Download",true) == true)
1446 ListUpdate(Stat
, List
);
1448 // Rebuild the cache.
1449 if (Cache
.BuildCaches() == false)
1455 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
1456 // ---------------------------------------------------------------------
1457 /* Remove unused automatic packages */
1458 bool DoAutomaticRemove(CacheFile
&Cache
)
1460 bool Debug
= _config
->FindI("Debug::pkgAutoRemove",false);
1461 bool doAutoRemove
= _config
->FindB("APT::Get::AutomaticRemove", false);
1462 bool hideAutoRemove
= _config
->FindB("APT::Get::HideAutoRemove");
1464 pkgDepCache::ActionGroup
group(*Cache
);
1466 std::cout
<< "DoAutomaticRemove()" << std::endl
;
1468 // we don't want to autoremove and we don't want to see it, so why calculating?
1469 if (doAutoRemove
== false && hideAutoRemove
== true)
1472 if (doAutoRemove
== true &&
1473 _config
->FindB("APT::Get::Remove",true) == false)
1475 c1out
<< _("We are not supposed to delete stuff, can't start "
1476 "AutoRemover") << std::endl
;
1480 bool purgePkgs
= _config
->FindB("APT::Get::Purge", false);
1481 bool smallList
= (hideAutoRemove
== false &&
1482 strcasecmp(_config
->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
1484 string autoremovelist
, autoremoveversions
;
1485 unsigned long autoRemoveCount
= 0;
1486 // look over the cache to see what can be removed
1487 for (pkgCache::PkgIterator Pkg
= Cache
->PkgBegin(); ! Pkg
.end(); ++Pkg
)
1489 if (Cache
[Pkg
].Garbage
)
1491 if(Pkg
.CurrentVer() != 0 || Cache
[Pkg
].Install())
1493 std::cout
<< "We could delete %s" << Pkg
.Name() << std::endl
;
1497 if(Pkg
.CurrentVer() != 0 &&
1498 Pkg
->CurrentState
!= pkgCache::State::ConfigFiles
)
1499 Cache
->MarkDelete(Pkg
, purgePkgs
);
1501 Cache
->MarkKeep(Pkg
, false, false);
1505 // only show stuff in the list that is not yet marked for removal
1506 if(Cache
[Pkg
].Delete() == false)
1508 // we don't need to fill the strings if we don't need them
1509 if (smallList
== true)
1513 autoremovelist
+= string(Pkg
.Name()) + " ";
1514 autoremoveversions
+= string(Cache
[Pkg
].CandVersion
) + "\n";
1520 // if we don't remove them, we should show them!
1521 if (doAutoRemove
== false && (autoremovelist
.empty() == false || autoRemoveCount
!= 0))
1523 if (smallList
== false)
1524 ShowList(c1out
, _("The following packages were automatically installed and are no longer required:"), autoremovelist
, autoremoveversions
);
1526 ioprintf(c1out
, _("%lu packages were automatically installed and are no longer required.\n"), autoRemoveCount
);
1527 c1out
<< _("Use 'apt-get autoremove' to remove them.") << std::endl
;
1529 // Now see if we had destroyed anything (if we had done anything)
1530 else if (Cache
->BrokenCount() != 0)
1532 c1out
<< _("Hmm, seems like the AutoRemover destroyed something which really\n"
1533 "shouldn't happen. Please file a bug report against apt.") << endl
;
1535 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1537 ShowBroken(c1out
,Cache
,false);
1539 return _error
->Error(_("Internal Error, AutoRemover broke stuff"));
1544 // DoUpgrade - Upgrade all packages /*{{{*/
1545 // ---------------------------------------------------------------------
1546 /* Upgrade all packages without installing new packages or erasing old
1548 bool DoUpgrade(CommandLine
&CmdL
)
1551 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1555 if (pkgAllUpgrade(Cache
) == false)
1557 ShowBroken(c1out
,Cache
,false);
1558 return _error
->Error(_("Internal error, AllUpgrade broke stuff"));
1561 return InstallPackages(Cache
,true);
1564 // DoInstallTask - Install task from the command line /*{{{*/
1565 // ---------------------------------------------------------------------
1566 /* Install named task */
1567 bool TryInstallTask(pkgDepCache
&Cache
, pkgProblemResolver
&Fix
,
1569 unsigned int& ExpectedInst
,
1570 const char *taskname
,
1573 const char *start
, *end
;
1574 pkgCache::PkgIterator Pkg
;
1579 pkgRecords
Recs(Cache
);
1581 // build regexp for the task
1583 snprintf(S
, sizeof(S
), "^Task:.*[, ]%s([, ]|$)", taskname
);
1584 if(regcomp(&Pattern
,S
, REG_EXTENDED
| REG_NOSUB
| REG_NEWLINE
) != 0)
1585 return _error
->Error("Failed to compile task regexp");
1590 // two runs, first ignore dependencies, second install any missing
1591 for(int IgnoreBroken
=1; IgnoreBroken
>= 0; IgnoreBroken
--)
1593 for (Pkg
= Cache
.PkgBegin(); Pkg
.end() == false; Pkg
++)
1595 pkgCache::VerIterator ver
= Cache
[Pkg
].CandidateVerIter(Cache
);
1598 pkgRecords::Parser
&parser
= Recs
.Lookup(ver
.FileList());
1599 parser
.GetRec(start
,end
);
1600 strncpy(buf
, start
, end
-start
);
1601 buf
[end
-start
] = 0x0;
1602 if (regexec(&Pattern
,buf
,0,0,0) != 0)
1604 res
&= TryToInstall(Pkg
,Cache
,Fix
,Remove
,IgnoreBroken
,ExpectedInst
);
1609 // now let the problem resolver deal with any issues
1613 _error
->Error(_("Couldn't find task %s"),taskname
);
1619 // DoInstall - Install packages from the command line /*{{{*/
1620 // ---------------------------------------------------------------------
1621 /* Install named packages */
1622 bool DoInstall(CommandLine
&CmdL
)
1625 if (Cache
.OpenForInstall() == false ||
1626 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
1629 // Enter the special broken fixing mode if the user specified arguments
1630 bool BrokenFix
= false;
1631 if (Cache
->BrokenCount() != 0)
1634 unsigned int AutoMarkChanged
= 0;
1635 unsigned int ExpectedInst
= 0;
1636 unsigned int Packages
= 0;
1637 pkgProblemResolver
Fix(Cache
);
1639 bool DefRemove
= false;
1640 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
1642 else if (strcasecmp(CmdL
.FileList
[0], "purge") == 0)
1644 _config
->Set("APT::Get::Purge", true);
1647 else if (strcasecmp(CmdL
.FileList
[0], "autoremove") == 0)
1649 _config
->Set("APT::Get::AutomaticRemove", "true");
1652 // new scope for the ActionGroup
1654 pkgDepCache::ActionGroup
group(Cache
);
1655 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
1657 // Duplicate the string
1658 unsigned int Length
= strlen(*I
);
1660 if (Length
>= sizeof(S
))
1664 // See if we are removing and special indicators..
1665 bool Remove
= DefRemove
;
1667 bool VerIsRel
= false;
1670 if (Length
>= 1 && S
[Length
- 1] == '^')
1673 // tasks must always be confirmed
1674 ExpectedInst
+= 1000;
1675 // see if we can install it
1676 TryInstallTask(Cache
, Fix
, BrokenFix
, ExpectedInst
, S
, Remove
);
1680 while (Cache
->FindPkg(S
).end() == true)
1682 // Handle an optional end tag indicating what to do
1683 if (Length
>= 1 && S
[Length
- 1] == '-')
1690 if (Length
>= 1 && S
[Length
- 1] == '+')
1697 char *Slash
= strchr(S
,'=');
1705 Slash
= strchr(S
,'/');
1716 // Locate the package
1717 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
1719 if (Pkg
.end() == true)
1721 // Check if the name is a regex
1723 for (I
= S
; *I
!= 0; I
++)
1724 if (*I
== '?' || *I
== '*' || *I
== '|' ||
1725 *I
== '[' || *I
== '^' || *I
== '$')
1728 return _error
->Error(_("Couldn't find package %s"),S
);
1730 // Regexs must always be confirmed
1731 ExpectedInst
+= 1000;
1733 // Compile the regex pattern
1736 if ((Res
= regcomp(&Pattern
,S
,REG_EXTENDED
| REG_ICASE
|
1740 regerror(Res
,&Pattern
,Error
,sizeof(Error
));
1741 return _error
->Error(_("Regex compilation error - %s"),Error
);
1744 // Run over the matches
1746 for (Pkg
= Cache
->PkgBegin(); Pkg
.end() == false; Pkg
++)
1748 if (regexec(&Pattern
,Pkg
.Name(),0,0,0) != 0)
1751 ioprintf(c1out
,_("Note, selecting %s for regex '%s'\n"),
1755 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1758 Hit
|= TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,
1759 ExpectedInst
,false);
1764 return _error
->Error(_("Couldn't find package %s"),S
);
1769 if (TryToChangeVer(Pkg
,Cache
,VerTag
,VerIsRel
) == false)
1771 if (TryToInstall(Pkg
,Cache
,Fix
,Remove
,BrokenFix
,ExpectedInst
) == false)
1774 // see if we need to fix the auto-mark flag
1775 // e.g. apt-get install foo
1776 // where foo is marked automatic
1778 Cache
[Pkg
].Install() == false &&
1779 (Cache
[Pkg
].Flags
& pkgCache::Flag::Auto
) &&
1780 _config
->FindB("APT::Get::ReInstall",false) == false &&
1781 _config
->FindB("APT::Get::Download-Only",false) == false)
1783 ioprintf(c1out
,_("%s set to manually installed.\n"),
1785 Cache
->MarkAuto(Pkg
,false);
1791 /* If we are in the Broken fixing mode we do not attempt to fix the
1792 problems. This is if the user invoked install without -f and gave
1794 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1796 c1out
<< _("You might want to run `apt-get -f install' to correct these:") << endl
;
1797 ShowBroken(c1out
,Cache
,false);
1799 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1802 // Call the scored problem resolver
1803 Fix
.InstallProtect();
1804 if (Fix
.Resolve(true) == false)
1807 // Now we check the state of the packages,
1808 if (Cache
->BrokenCount() != 0)
1811 _("Some packages could not be installed. This may mean that you have\n"
1812 "requested an impossible situation or if you are using the unstable\n"
1813 "distribution that some required packages have not yet been created\n"
1814 "or been moved out of Incoming.") << endl
;
1820 _("Since you only requested a single operation it is extremely likely that\n"
1821 "the package is simply not installable and a bug report against\n"
1822 "that package should be filed.") << endl;
1826 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1828 ShowBroken(c1out
,Cache
,false);
1829 return _error
->Error(_("Broken packages"));
1832 if (!DoAutomaticRemove(Cache
))
1835 /* Print out a list of packages that are going to be installed extra
1836 to what the user asked */
1837 if (Cache
->InstCount() != ExpectedInst
)
1840 string VersionsList
;
1841 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1843 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1844 if ((*Cache
)[I
].Install() == false)
1848 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
1849 if (strcmp(*J
,I
.Name()) == 0)
1853 List
+= string(I
.Name()) + " ";
1854 VersionsList
+= string(Cache
[I
].CandVersion
) + "\n";
1858 ShowList(c1out
,_("The following extra packages will be installed:"),List
,VersionsList
);
1861 /* Print out a list of suggested and recommended packages */
1863 string SuggestsList
, RecommendsList
, List
;
1864 string SuggestsVersions
, RecommendsVersions
;
1865 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1867 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
1869 /* Just look at the ones we want to install */
1870 if ((*Cache
)[Pkg
].Install() == false)
1873 // get the recommends/suggests for the candidate ver
1874 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1875 for (pkgCache::DepIterator D
= CV
.DependsList(); D
.end() == false; )
1877 pkgCache::DepIterator Start
;
1878 pkgCache::DepIterator End
;
1879 D
.GlobOr(Start
,End
); // advances D
1881 // FIXME: we really should display a or-group as a or-group to the user
1882 // the problem is that ShowList is incapable of doing this
1883 string RecommendsOrList
,RecommendsOrVersions
;
1884 string SuggestsOrList
,SuggestsOrVersions
;
1885 bool foundInstalledInOrGroup
= false;
1888 /* Skip if package is installed already, or is about to be */
1889 string target
= string(Start
.TargetPkg().Name()) + " ";
1891 if ((*Start
.TargetPkg()).SelectedState
== pkgCache::State::Install
1892 || Cache
[Start
.TargetPkg()].Install())
1894 foundInstalledInOrGroup
=true;
1898 /* Skip if we already saw it */
1899 if (int(SuggestsList
.find(target
)) != -1 || int(RecommendsList
.find(target
)) != -1)
1901 foundInstalledInOrGroup
=true;
1905 // this is a dep on a virtual pkg, check if any package that provides it
1906 // should be installed
1907 if(Start
.TargetPkg().ProvidesList() != 0)
1909 pkgCache::PrvIterator I
= Start
.TargetPkg().ProvidesList();
1910 for (; I
.end() == false; I
++)
1912 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
1913 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer() &&
1914 Pkg
.CurrentVer() != 0)
1915 foundInstalledInOrGroup
=true;
1919 if (Start
->Type
== pkgCache::Dep::Suggests
)
1921 SuggestsOrList
+= target
;
1922 SuggestsOrVersions
+= string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
1925 if (Start
->Type
== pkgCache::Dep::Recommends
)
1927 RecommendsOrList
+= target
;
1928 RecommendsOrVersions
+= string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
1936 if(foundInstalledInOrGroup
== false)
1938 RecommendsList
+= RecommendsOrList
;
1939 RecommendsVersions
+= RecommendsOrVersions
;
1940 SuggestsList
+= SuggestsOrList
;
1941 SuggestsVersions
+= SuggestsOrVersions
;
1947 ShowList(c1out
,_("Suggested packages:"),SuggestsList
,SuggestsVersions
);
1948 ShowList(c1out
,_("Recommended packages:"),RecommendsList
,RecommendsVersions
);
1952 // if nothing changed in the cache, but only the automark information
1953 // we write the StateFile here, otherwise it will be written in
1955 if (AutoMarkChanged
> 0 &&
1956 Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
1957 Cache
->BadCount() == 0 &&
1958 _config
->FindB("APT::Get::Simulate",false) == false)
1959 Cache
->writeStateFile(NULL
);
1961 // See if we need to prompt
1962 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
1963 return InstallPackages(Cache
,false,false);
1965 return InstallPackages(Cache
,false);
1968 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1969 // ---------------------------------------------------------------------
1970 /* Intelligent upgrader that will install and remove packages at will */
1971 bool DoDistUpgrade(CommandLine
&CmdL
)
1974 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1977 c0out
<< _("Calculating upgrade... ") << flush
;
1978 if (pkgDistUpgrade(*Cache
) == false)
1980 c0out
<< _("Failed") << endl
;
1981 ShowBroken(c1out
,Cache
,false);
1985 c0out
<< _("Done") << endl
;
1987 return InstallPackages(Cache
,true);
1990 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1991 // ---------------------------------------------------------------------
1992 /* Follows dselect's selections */
1993 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1996 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1999 pkgDepCache::ActionGroup
group(Cache
);
2001 // Install everything with the install flag set
2002 pkgCache::PkgIterator I
= Cache
->PkgBegin();
2003 for (;I
.end() != true; I
++)
2005 /* Install the package only if it is a new install, the autoupgrader
2006 will deal with the rest */
2007 if (I
->SelectedState
== pkgCache::State::Install
)
2008 Cache
->MarkInstall(I
,false);
2011 /* Now install their deps too, if we do this above then order of
2012 the status file is significant for | groups */
2013 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
2015 /* Install the package only if it is a new install, the autoupgrader
2016 will deal with the rest */
2017 if (I
->SelectedState
== pkgCache::State::Install
)
2018 Cache
->MarkInstall(I
,true);
2021 // Apply erasures now, they override everything else.
2022 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
2025 if (I
->SelectedState
== pkgCache::State::DeInstall
||
2026 I
->SelectedState
== pkgCache::State::Purge
)
2027 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
2030 /* Resolve any problems that dselect created, allupgrade cannot handle
2031 such things. We do so quite agressively too.. */
2032 if (Cache
->BrokenCount() != 0)
2034 pkgProblemResolver
Fix(Cache
);
2036 // Hold back held packages.
2037 if (_config
->FindB("APT::Ignore-Hold",false) == false)
2039 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
2041 if (I
->SelectedState
== pkgCache::State::Hold
)
2049 if (Fix
.Resolve() == false)
2051 ShowBroken(c1out
,Cache
,false);
2052 return _error
->Error(_("Internal error, problem resolver broke stuff"));
2056 // Now upgrade everything
2057 if (pkgAllUpgrade(Cache
) == false)
2059 ShowBroken(c1out
,Cache
,false);
2060 return _error
->Error(_("Internal error, problem resolver broke stuff"));
2063 return InstallPackages(Cache
,false);
2066 // DoClean - Remove download archives /*{{{*/
2067 // ---------------------------------------------------------------------
2069 bool DoClean(CommandLine
&CmdL
)
2071 if (_config
->FindB("APT::Get::Simulate") == true)
2073 cout
<< "Del " << _config
->FindDir("Dir::Cache::archives") << "* " <<
2074 _config
->FindDir("Dir::Cache::archives") << "partial/*" << endl
;
2078 // Lock the archive directory
2080 if (_config
->FindB("Debug::NoLocking",false) == false)
2082 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
2083 if (_error
->PendingError() == true)
2084 return _error
->Error(_("Unable to lock the download directory"));
2088 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
2089 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
2093 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
2094 // ---------------------------------------------------------------------
2095 /* This is similar to clean but it only purges things that cannot be
2096 downloaded, that is old versions of cached packages. */
2097 class LogCleaner
: public pkgArchiveCleaner
2100 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
2102 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
2104 if (_config
->FindB("APT::Get::Simulate") == false)
2109 bool DoAutoClean(CommandLine
&CmdL
)
2111 // Lock the archive directory
2113 if (_config
->FindB("Debug::NoLocking",false) == false)
2115 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
2116 if (_error
->PendingError() == true)
2117 return _error
->Error(_("Unable to lock the download directory"));
2121 if (Cache
.Open() == false)
2126 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
2127 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
2130 // DoCheck - Perform the check operation /*{{{*/
2131 // ---------------------------------------------------------------------
2132 /* Opening automatically checks the system, this command is mostly used
2134 bool DoCheck(CommandLine
&CmdL
)
2143 // DoSource - Fetch a source archive /*{{{*/
2144 // ---------------------------------------------------------------------
2145 /* Fetch souce packages */
2153 bool DoSource(CommandLine
&CmdL
)
2156 if (Cache
.Open(false) == false)
2159 if (CmdL
.FileSize() <= 1)
2160 return _error
->Error(_("Must specify at least one package to fetch source for"));
2162 // Read the source list
2164 if (List
.ReadMainList() == false)
2165 return _error
->Error(_("The list of sources could not be read."));
2167 // Create the text record parsers
2168 pkgRecords
Recs(Cache
);
2169 pkgSrcRecords
SrcRecs(List
);
2170 if (_error
->PendingError() == true)
2173 // Create the download object
2174 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
2175 pkgAcquire
Fetcher(&Stat
);
2177 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
2179 // insert all downloaded uris into this set to avoid downloading them
2182 // Load the requestd sources into the fetcher
2184 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
2187 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
2190 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
2193 vector
<pkgSrcRecords::File
> Lst
;
2194 if (Last
->Files(Lst
) == false)
2197 // Load them into the fetcher
2198 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
2199 I
!= Lst
.end(); I
++)
2201 // Try to guess what sort of file it is we are getting.
2202 if (I
->Type
== "dsc")
2204 Dsc
[J
].Package
= Last
->Package();
2205 Dsc
[J
].Version
= Last
->Version();
2206 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
2209 // Diff only mode only fetches .diff files
2210 if (_config
->FindB("APT::Get::Diff-Only",false) == true &&
2214 // Tar only mode only fetches .tar files
2215 if (_config
->FindB("APT::Get::Tar-Only",false) == true &&
2219 // Dsc only mode only fetches .dsc files
2220 if (_config
->FindB("APT::Get::Dsc-Only",false) == true &&
2224 // don't download the same uri twice (should this be moved to
2225 // the fetcher interface itself?)
2226 if(queued
.find(Last
->Index().ArchiveURI(I
->Path
)) != queued
.end())
2228 queued
.insert(Last
->Index().ArchiveURI(I
->Path
));
2230 // check if we have a file with that md5 sum already localy
2231 if(!I
->MD5Hash
.empty() && FileExists(flNotDir(I
->Path
)))
2233 FileFd
Fd(flNotDir(I
->Path
), FileFd::ReadOnly
);
2235 sum
.AddFD(Fd
.Fd(), Fd
.Size());
2237 if((string
)sum
.Result() == I
->MD5Hash
)
2239 ioprintf(c1out
,_("Skipping already downloaded file '%s'\n"),
2240 flNotDir(I
->Path
).c_str());
2245 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
2247 Last
->Index().SourceInfo(*Last
,*I
),Src
);
2251 // Display statistics
2252 double FetchBytes
= Fetcher
.FetchNeeded();
2253 double FetchPBytes
= Fetcher
.PartialPresent();
2254 double DebBytes
= Fetcher
.TotalNeeded();
2256 // Check for enough free space
2258 string OutputDir
= ".";
2259 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
2260 if (errno
== EOVERFLOW
)
2261 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
2264 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
2266 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
2269 if (statfs(OutputDir
.c_str(),&Stat
) != 0
2270 #if HAVE_STRUCT_STATFS_F_TYPE
2271 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
2274 return _error
->Error(_("You don't have enough free space in %s"),
2279 if (DebBytes
!= FetchBytes
)
2280 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
2281 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
2283 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
2284 SizeToStr(DebBytes
).c_str());
2286 if (_config
->FindB("APT::Get::Simulate",false) == true)
2288 for (unsigned I
= 0; I
!= J
; I
++)
2289 ioprintf(cout
,_("Fetch source %s\n"),Dsc
[I
].Package
.c_str());
2293 // Just print out the uris an exit if the --print-uris flag was used
2294 if (_config
->FindB("APT::Get::Print-URIs") == true)
2296 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
2297 for (; I
!= Fetcher
.UriEnd(); I
++)
2298 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
2299 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
2304 if (Fetcher
.Run() == pkgAcquire::Failed
)
2307 // Print error messages
2308 bool Failed
= false;
2309 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
2311 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
2312 (*I
)->Complete
== true)
2315 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
2316 (*I
)->ErrorText
.c_str());
2320 return _error
->Error(_("Failed to fetch some archives."));
2322 if (_config
->FindB("APT::Get::Download-only",false) == true)
2324 c1out
<< _("Download complete and in download only mode") << endl
;
2328 // Unpack the sources
2329 pid_t Process
= ExecFork();
2333 for (unsigned I
= 0; I
!= J
; I
++)
2335 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
2337 // Diff only mode only fetches .diff files
2338 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
2339 _config
->FindB("APT::Get::Tar-Only",false) == true ||
2340 Dsc
[I
].Dsc
.empty() == true)
2343 // See if the package is already unpacked
2345 if (stat(Dir
.c_str(),&Stat
) == 0 &&
2346 S_ISDIR(Stat
.st_mode
) != 0)
2348 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
2355 snprintf(S
,sizeof(S
),"%s -x %s",
2356 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
2357 Dsc
[I
].Dsc
.c_str());
2360 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
2361 fprintf(stderr
,_("Check if the 'dpkg-dev' package is installed.\n"));
2366 // Try to compile it with dpkg-buildpackage
2367 if (_config
->FindB("APT::Get::Compile",false) == true)
2369 // Call dpkg-buildpackage
2371 snprintf(S
,sizeof(S
),"cd %s && %s %s",
2373 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
2374 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
2378 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
2387 // Wait for the subprocess
2389 while (waitpid(Process
,&Status
,0) != Process
)
2393 return _error
->Errno("waitpid","Couldn't wait for subprocess");
2396 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
2397 return _error
->Error(_("Child process failed"));
2402 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
2403 // ---------------------------------------------------------------------
2404 /* This function will look at the build depends list of the given source
2405 package and install the necessary packages to make it true, or fail. */
2406 bool DoBuildDep(CommandLine
&CmdL
)
2409 if (Cache
.Open(true) == false)
2412 if (CmdL
.FileSize() <= 1)
2413 return _error
->Error(_("Must specify at least one package to check builddeps for"));
2415 // Read the source list
2417 if (List
.ReadMainList() == false)
2418 return _error
->Error(_("The list of sources could not be read."));
2420 // Create the text record parsers
2421 pkgRecords
Recs(Cache
);
2422 pkgSrcRecords
SrcRecs(List
);
2423 if (_error
->PendingError() == true)
2426 // Create the download object
2427 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
2428 pkgAcquire
Fetcher(&Stat
);
2431 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
2434 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
2436 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
2438 // Process the build-dependencies
2439 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
2440 if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only",false)) == false)
2441 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
2443 // Also ensure that build-essential packages are present
2444 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
2447 for (; Opts
; Opts
= Opts
->Next
)
2449 if (Opts
->Value
.empty() == true)
2452 pkgSrcRecords::Parser::BuildDepRec rec
;
2453 rec
.Package
= Opts
->Value
;
2454 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
2456 BuildDeps
.push_back(rec
);
2459 if (BuildDeps
.size() == 0)
2461 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
2465 // Install the requested packages
2466 unsigned int ExpectedInst
= 0;
2467 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
2468 pkgProblemResolver
Fix(Cache
);
2469 bool skipAlternatives
= false; // skip remaining alternatives in an or group
2470 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); D
++)
2472 bool hasAlternatives
= (((*D
).Op
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
);
2474 if (skipAlternatives
== true)
2476 if (!hasAlternatives
)
2477 skipAlternatives
= false; // end of or group
2481 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
2482 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
2484 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
2485 // Build-conflicts on unknown packages are silently ignored
2486 if (Pkg
.end() == true)
2489 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
2492 * Remove if we have an installed version that satisfies the
2495 if (IV
.end() == false &&
2496 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2497 TryToInstall(Pkg
,Cache
,Fix
,true,false,ExpectedInst
);
2499 else // BuildDep || BuildDepIndep
2501 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
2502 if (_config
->FindB("Debug::BuildDeps",false) == true)
2503 cout
<< "Looking for " << (*D
).Package
<< "...\n";
2505 if (Pkg
.end() == true)
2507 if (_config
->FindB("Debug::BuildDeps",false) == true)
2508 cout
<< " (not found)" << (*D
).Package
<< endl
;
2510 if (hasAlternatives
)
2513 return _error
->Error(_("%s dependency for %s cannot be satisfied "
2514 "because the package %s cannot be found"),
2515 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
2516 (*D
).Package
.c_str());
2520 * if there are alternatives, we've already picked one, so skip
2523 * TODO: this means that if there's a build-dep on A|B and B is
2524 * installed, we'll still try to install A; more importantly,
2525 * if A is currently broken, we cannot go back and try B. To fix
2526 * this would require we do a Resolve cycle for each package we
2527 * add to the install list. Ugh
2531 * If this is a virtual package, we need to check the list of
2532 * packages that provide it and see if any of those are
2535 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
2536 for (; Prv
.end() != true; Prv
++)
2538 if (_config
->FindB("Debug::BuildDeps",false) == true)
2539 cout
<< " Checking provider " << Prv
.OwnerPkg().Name() << endl
;
2541 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
2545 // Get installed version and version we are going to install
2546 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
2548 if ((*D
).Version
[0] != '\0') {
2549 // Versioned dependency
2551 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
2553 for (; CV
.end() != true; CV
++)
2555 if (Cache
->VS().CheckDep(CV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2558 if (CV
.end() == true)
2560 if (hasAlternatives
)
2566 return _error
->Error(_("%s dependency for %s cannot be satisfied "
2567 "because no available versions of package %s "
2568 "can satisfy version requirements"),
2569 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
2570 (*D
).Package
.c_str());
2576 // Only consider virtual packages if there is no versioned dependency
2577 if (Prv
.end() == false)
2579 if (_config
->FindB("Debug::BuildDeps",false) == true)
2580 cout
<< " Is provided by installed package " << Prv
.OwnerPkg().Name() << endl
;
2581 skipAlternatives
= hasAlternatives
;
2586 if (IV
.end() == false)
2588 if (_config
->FindB("Debug::BuildDeps",false) == true)
2589 cout
<< " Is installed\n";
2591 if (Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2593 skipAlternatives
= hasAlternatives
;
2597 if (_config
->FindB("Debug::BuildDeps",false) == true)
2598 cout
<< " ...but the installed version doesn't meet the version requirement\n";
2600 if (((*D
).Op
& pkgCache::Dep::LessEq
) == pkgCache::Dep::LessEq
)
2602 return _error
->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
2603 Last
->BuildDepType((*D
).Type
),
2610 if (_config
->FindB("Debug::BuildDeps",false) == true)
2611 cout
<< " Trying to install " << (*D
).Package
<< endl
;
2613 if (TryToInstall(Pkg
,Cache
,Fix
,false,false,ExpectedInst
) == true)
2615 // We successfully installed something; skip remaining alternatives
2616 skipAlternatives
= hasAlternatives
;
2617 if(_config
->FindB("APT::Get::Build-Dep-Automatic", false) == true)
2618 Cache
->MarkAuto(Pkg
, true);
2621 else if (hasAlternatives
)
2623 if (_config
->FindB("Debug::BuildDeps",false) == true)
2624 cout
<< " Unsatisfiable, trying alternatives\n";
2629 return _error
->Error(_("Failed to satisfy %s dependency for %s: %s"),
2630 Last
->BuildDepType((*D
).Type
),
2632 (*D
).Package
.c_str());
2637 Fix
.InstallProtect();
2638 if (Fix
.Resolve(true) == false)
2641 // Now we check the state of the packages,
2642 if (Cache
->BrokenCount() != 0)
2644 ShowBroken(cout
, Cache
, false);
2645 return _error
->Error(_("Build-dependencies for %s could not be satisfied."),*I
);
2649 if (InstallPackages(Cache
, false, true) == false)
2650 return _error
->Error(_("Failed to process build dependencies"));
2655 // DoMoo - Never Ask, Never Tell /*{{{*/
2656 // ---------------------------------------------------------------------
2658 bool DoMoo(CommandLine
&CmdL
)
2667 "....\"Have you mooed today?\"...\n";
2672 // ShowHelp - Show a help screen /*{{{*/
2673 // ---------------------------------------------------------------------
2675 bool ShowHelp(CommandLine
&CmdL
)
2677 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,VERSION
,
2678 COMMON_ARCH
,__DATE__
,__TIME__
);
2680 if (_config
->FindB("version") == true)
2682 cout
<< _("Supported modules:") << endl
;
2684 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
2686 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
2687 if (_system
!= 0 && _system
->VS
== VS
)
2691 cout
<< "Ver: " << VS
->Label
<< endl
;
2693 /* Print out all the packaging systems that will work with
2695 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
2697 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
2702 if (Sys
->VS
->TestCompatibility(*VS
) == true)
2703 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
2707 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
2709 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
2710 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
2713 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
2715 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
2716 cout
<< " Idx: " << Type
->Label
<< endl
;
2723 _("Usage: apt-get [options] command\n"
2724 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
2725 " apt-get [options] source pkg1 [pkg2 ...]\n"
2727 "apt-get is a simple command line interface for downloading and\n"
2728 "installing packages. The most frequently used commands are update\n"
2732 " update - Retrieve new lists of packages\n"
2733 " upgrade - Perform an upgrade\n"
2734 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
2735 " remove - Remove packages\n"
2736 " autoremove - Remove automatically all unused packages\n"
2737 " purge - Remove packages and config files\n"
2738 " source - Download source archives\n"
2739 " build-dep - Configure build-dependencies for source packages\n"
2740 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
2741 " dselect-upgrade - Follow dselect selections\n"
2742 " clean - Erase downloaded archive files\n"
2743 " autoclean - Erase old downloaded archive files\n"
2744 " check - Verify that there are no broken dependencies\n"
2747 " -h This help text.\n"
2748 " -q Loggable output - no progress indicator\n"
2749 " -qq No output except for errors\n"
2750 " -d Download only - do NOT install or unpack archives\n"
2751 " -s No-act. Perform ordering simulation\n"
2752 " -y Assume Yes to all queries and do not prompt\n"
2753 " -f Attempt to correct a system with broken dependencies in place\n"
2754 " -m Attempt to continue if archives are unlocatable\n"
2755 " -u Show a list of upgraded packages as well\n"
2756 " -b Build the source package after fetching it\n"
2757 " -V Show verbose version numbers\n"
2758 " -c=? Read this configuration file\n"
2759 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
2760 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
2761 "pages for more information and options.\n"
2762 " This APT has Super Cow Powers.\n");
2766 // GetInitialize - Initialize things for apt-get /*{{{*/
2767 // ---------------------------------------------------------------------
2769 void GetInitialize()
2771 _config
->Set("quiet",0);
2772 _config
->Set("help",false);
2773 _config
->Set("APT::Get::Download-Only",false);
2774 _config
->Set("APT::Get::Simulate",false);
2775 _config
->Set("APT::Get::Assume-Yes",false);
2776 _config
->Set("APT::Get::Fix-Broken",false);
2777 _config
->Set("APT::Get::Force-Yes",false);
2778 _config
->Set("APT::Get::List-Cleanup",true);
2779 _config
->Set("APT::Get::AutomaticRemove",false);
2782 // SigWinch - Window size change signal handler /*{{{*/
2783 // ---------------------------------------------------------------------
2787 // Riped from GNU ls
2791 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
2792 ScreenWidth
= ws
.ws_col
- 1;
2796 int main(int argc
,const char *argv
[]) /*{{{*/
2798 CommandLine::Args Args
[] = {
2799 {'h',"help","help",0},
2800 {'v',"version","version",0},
2801 {'V',"verbose-versions","APT::Get::Show-Versions",0},
2802 {'q',"quiet","quiet",CommandLine::IntLevel
},
2803 {'q',"silent","quiet",CommandLine::IntLevel
},
2804 {'d',"download-only","APT::Get::Download-Only",0},
2805 {'b',"compile","APT::Get::Compile",0},
2806 {'b',"build","APT::Get::Compile",0},
2807 {'s',"simulate","APT::Get::Simulate",0},
2808 {'s',"just-print","APT::Get::Simulate",0},
2809 {'s',"recon","APT::Get::Simulate",0},
2810 {'s',"dry-run","APT::Get::Simulate",0},
2811 {'s',"no-act","APT::Get::Simulate",0},
2812 {'y',"yes","APT::Get::Assume-Yes",0},
2813 {'y',"assume-yes","APT::Get::Assume-Yes",0},
2814 {'f',"fix-broken","APT::Get::Fix-Broken",0},
2815 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
2816 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
2817 {'t',"target-release","APT::Default-Release",CommandLine::HasArg
},
2818 {'t',"default-release","APT::Default-Release",CommandLine::HasArg
},
2819 {0,"download","APT::Get::Download",0},
2820 {0,"fix-missing","APT::Get::Fix-Missing",0},
2821 {0,"ignore-hold","APT::Ignore-Hold",0},
2822 {0,"upgrade","APT::Get::upgrade",0},
2823 {0,"force-yes","APT::Get::force-yes",0},
2824 {0,"print-uris","APT::Get::Print-URIs",0},
2825 {0,"diff-only","APT::Get::Diff-Only",0},
2826 {0,"debian-only","APT::Get::Diff-Only",0},
2827 {0,"tar-only","APT::Get::Tar-Only",0},
2828 {0,"dsc-only","APT::Get::Dsc-Only",0},
2829 {0,"purge","APT::Get::Purge",0},
2830 {0,"list-cleanup","APT::Get::List-Cleanup",0},
2831 {0,"reinstall","APT::Get::ReInstall",0},
2832 {0,"trivial-only","APT::Get::Trivial-Only",0},
2833 {0,"remove","APT::Get::Remove",0},
2834 {0,"only-source","APT::Get::Only-Source",0},
2835 {0,"arch-only","APT::Get::Arch-Only",0},
2836 {0,"auto-remove","APT::Get::AutomaticRemove",0},
2837 {0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0},
2838 {0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean
},
2839 {0,"fix-policy","APT::Get::Fix-Policy-Broken",0},
2840 {'c',"config-file",0,CommandLine::ConfigFile
},
2841 {'o',"option",0,CommandLine::ArbItem
},
2843 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
2844 {"upgrade",&DoUpgrade
},
2845 {"install",&DoInstall
},
2846 {"remove",&DoInstall
},
2847 {"purge",&DoInstall
},
2848 {"autoremove",&DoInstall
},
2849 {"purge",&DoInstall
},
2850 {"dist-upgrade",&DoDistUpgrade
},
2851 {"dselect-upgrade",&DoDSelectUpgrade
},
2852 {"build-dep",&DoBuildDep
},
2854 {"autoclean",&DoAutoClean
},
2856 {"source",&DoSource
},
2861 // Set up gettext support
2862 setlocale(LC_ALL
,"");
2863 textdomain(PACKAGE
);
2865 // Parse the command line and initialize the package library
2866 CommandLine
CmdL(Args
,_config
);
2867 if (pkgInitConfig(*_config
) == false ||
2868 CmdL
.Parse(argc
,argv
) == false ||
2869 pkgInitSystem(*_config
,_system
) == false)
2871 if (_config
->FindB("version") == true)
2874 _error
->DumpErrors();
2878 // See if the help should be shown
2879 if (_config
->FindB("help") == true ||
2880 _config
->FindB("version") == true ||
2881 CmdL
.FileSize() == 0)
2887 // simulate user-friendly if apt-get has no root privileges
2888 if (getuid() != 0 && _config
->FindB("APT::Get::Simulate") == true)
2890 if (_config
->FindB("APT::Get::Show-User-Simulation-Note",true) == true)
2891 cout
<< _("NOTE: This is only a simulation!\n"
2892 " apt-get needs root privileges for real execution.\n"
2893 " Keep also in mind that locking is deactivated,\n"
2894 " so don't depend on the relevance to the real current situation!"
2896 _config
->Set("Debug::NoLocking",true);
2899 // Deal with stdout not being a tty
2900 if (!isatty(STDOUT_FILENO
) && _config
->FindI("quiet",0) < 1)
2901 _config
->Set("quiet","1");
2904 devnull
.open("/dev/null");
2906 // Setup the output streams
2907 c0out
.rdbuf(cout
.rdbuf());
2908 c1out
.rdbuf(cout
.rdbuf());
2909 c2out
.rdbuf(cout
.rdbuf());
2910 if (_config
->FindI("quiet",0) > 0)
2911 c0out
.rdbuf(devnull
.rdbuf());
2912 if (_config
->FindI("quiet",0) > 1)
2913 c1out
.rdbuf(devnull
.rdbuf());
2915 // Setup the signals
2916 signal(SIGPIPE
,SIG_IGN
);
2917 signal(SIGWINCH
,SigWinch
);
2920 // Match the operation
2921 CmdL
.DispatchArg(Cmds
);
2923 // Print any errors or warnings found during parsing
2924 if (_error
->empty() == false)
2926 bool Errors
= _error
->PendingError();
2927 _error
->DumpErrors();
2928 return Errors
== true?100:0;