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 #define _LARGEFILE_SOURCE
29 #define _LARGEFILE64_SOURCE
31 #include <apt-pkg/aptconfiguration.h>
32 #include <apt-pkg/error.h>
33 #include <apt-pkg/cmndline.h>
34 #include <apt-pkg/init.h>
35 #include <apt-pkg/depcache.h>
36 #include <apt-pkg/sourcelist.h>
37 #include <apt-pkg/algorithms.h>
38 #include <apt-pkg/acquire-item.h>
39 #include <apt-pkg/strutl.h>
40 #include <apt-pkg/clean.h>
41 #include <apt-pkg/srcrecords.h>
42 #include <apt-pkg/version.h>
43 #include <apt-pkg/cachefile.h>
44 #include <apt-pkg/cacheset.h>
45 #include <apt-pkg/sptr.h>
46 #include <apt-pkg/md5.h>
47 #include <apt-pkg/versionmatch.h>
52 #include "acqprogress.h"
59 #include <sys/ioctl.h>
61 #include <sys/statfs.h>
62 #include <sys/statvfs.h>
71 #define statfs statfs64
72 #define statvfs statvfs64
75 #define RAMFS_MAGIC 0x858458f6
82 ofstream
devnull("/dev/null");
83 unsigned int ScreenWidth
= 80 - 1; /* - 1 for the cursor */
85 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
86 // ---------------------------------------------------------------------
88 class CacheFile
: public pkgCacheFile
90 static pkgCache
*SortCache
;
91 static int NameComp(const void *a
,const void *b
);
94 pkgCache::Package
**List
;
97 bool CheckDeps(bool AllowBroken
= false);
98 bool BuildCaches(bool WithLock
= true)
100 OpTextProgress
Prog(*_config
);
101 if (pkgCacheFile::BuildCaches(&Prog
,WithLock
) == false)
105 bool Open(bool WithLock
= true)
107 OpTextProgress
Prog(*_config
);
108 if (pkgCacheFile::Open(&Prog
,WithLock
) == false)
114 bool OpenForInstall()
116 if (_config
->FindB("APT::Get::Print-URIs") == true)
121 CacheFile() : List(0) {};
128 // YnPrompt - Yes No Prompt. /*{{{*/
129 // ---------------------------------------------------------------------
130 /* Returns true on a Yes.*/
131 bool YnPrompt(bool Default
=true)
133 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
135 c1out
<< _("Y") << endl
;
139 char response
[1024] = "";
140 cin
.getline(response
, sizeof(response
));
145 if (strlen(response
) == 0)
151 Res
= regcomp(&Pattern
, nl_langinfo(YESEXPR
),
152 REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
156 regerror(Res
,&Pattern
,Error
,sizeof(Error
));
157 return _error
->Error(_("Regex compilation error - %s"),Error
);
160 Res
= regexec(&Pattern
, response
, 0, NULL
, 0);
166 // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
167 // ---------------------------------------------------------------------
168 /* Returns true on a Yes.*/
169 bool AnalPrompt(const char *Text
)
172 cin
.getline(Buf
,sizeof(Buf
));
173 if (strcmp(Buf
,Text
) == 0)
178 // ShowList - Show a list /*{{{*/
179 // ---------------------------------------------------------------------
180 /* This prints out a string of space separated words with a title and
181 a two space indent line wraped to the current screen width. */
182 bool ShowList(ostream
&out
,string Title
,string List
,string VersionsList
)
184 if (List
.empty() == true)
186 // trim trailing space
187 int NonSpace
= List
.find_last_not_of(' ');
190 List
= List
.erase(NonSpace
+ 1);
191 if (List
.empty() == true)
195 // Acount for the leading space
196 int ScreenWidth
= ::ScreenWidth
- 3;
198 out
<< Title
<< endl
;
199 string::size_type Start
= 0;
200 string::size_type VersionsStart
= 0;
201 while (Start
< List
.size())
203 if(_config
->FindB("APT::Get::Show-Versions",false) == true &&
204 VersionsList
.size() > 0) {
205 string::size_type End
;
206 string::size_type VersionsEnd
;
208 End
= List
.find(' ',Start
);
209 VersionsEnd
= VersionsList
.find('\n', VersionsStart
);
211 out
<< " " << string(List
,Start
,End
- Start
) << " (" <<
212 string(VersionsList
,VersionsStart
,VersionsEnd
- VersionsStart
) <<
215 if (End
== string::npos
|| End
< Start
)
216 End
= Start
+ ScreenWidth
;
219 VersionsStart
= VersionsEnd
+ 1;
221 string::size_type End
;
223 if (Start
+ ScreenWidth
>= List
.size())
226 End
= List
.rfind(' ',Start
+ScreenWidth
);
228 if (End
== string::npos
|| End
< Start
)
229 End
= Start
+ ScreenWidth
;
230 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
238 // ShowBroken - Debugging aide /*{{{*/
239 // ---------------------------------------------------------------------
240 /* This prints out the names of all the packages that are broken along
241 with the name of each each broken dependency and a quite version
244 The output looks like:
245 The following packages have unmet dependencies:
246 exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed
247 Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
248 Depends: libsasl7 but it is not going to be installed
250 void ShowBroken(ostream
&out
,CacheFile
&Cache
,bool Now
)
252 out
<< _("The following packages have unmet dependencies:") << endl
;
253 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
255 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
259 if (Cache
[I
].NowBroken() == false)
264 if (Cache
[I
].InstBroken() == false)
268 // Print out each package and the failed dependencies
269 out
<< " " << I
.FullName(true) << " :";
270 unsigned const Indent
= I
.FullName(true).size() + 3;
272 pkgCache::VerIterator Ver
;
275 Ver
= I
.CurrentVer();
277 Ver
= Cache
[I
].InstVerIter(Cache
);
279 if (Ver
.end() == true)
285 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false;)
287 // Compute a single dependency element (glob or)
288 pkgCache::DepIterator Start
;
289 pkgCache::DepIterator End
;
290 D
.GlobOr(Start
,End
); // advances D
292 if (Cache
->IsImportantDep(End
) == false)
297 if ((Cache
[End
] & pkgDepCache::DepGNow
) == pkgDepCache::DepGNow
)
302 if ((Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
310 for (unsigned J
= 0; J
!= Indent
; J
++)
314 if (FirstOr
== false)
316 for (unsigned J
= 0; J
!= strlen(End
.DepType()) + 3; J
++)
320 out
<< ' ' << End
.DepType() << ": ";
323 out
<< Start
.TargetPkg().FullName(true);
325 // Show a quick summary of the version requirements
326 if (Start
.TargetVer() != 0)
327 out
<< " (" << Start
.CompType() << " " << Start
.TargetVer() << ")";
329 /* Show a summary of the target package if possible. In the case
330 of virtual packages we show nothing */
331 pkgCache::PkgIterator Targ
= Start
.TargetPkg();
332 if (Targ
->ProvidesList
== 0)
335 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
337 Ver
= Targ
.CurrentVer();
339 if (Ver
.end() == false)
342 ioprintf(out
,_("but %s is installed"),Ver
.VerStr());
344 ioprintf(out
,_("but %s is to be installed"),Ver
.VerStr());
348 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
350 if (Targ
->ProvidesList
== 0)
351 out
<< _("but it is not installable");
353 out
<< _("but it is a virtual package");
356 out
<< (Now
?_("but it is not installed"):_("but it is not going to be installed"));
372 // ShowNew - Show packages to newly install /*{{{*/
373 // ---------------------------------------------------------------------
375 void ShowNew(ostream
&out
,CacheFile
&Cache
)
377 /* Print out a list of packages that are going to be installed extra
378 to what the user asked */
381 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
383 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
384 if (Cache
[I
].NewInstall() == true) {
385 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
387 List
+= I
.FullName(true) + " ";
388 VersionsList
+= string(Cache
[I
].CandVersion
) + "\n";
392 ShowList(out
,_("The following NEW packages will be installed:"),List
,VersionsList
);
395 // ShowDel - Show packages to delete /*{{{*/
396 // ---------------------------------------------------------------------
398 void ShowDel(ostream
&out
,CacheFile
&Cache
)
400 /* Print out a list of packages that are going to be removed extra
401 to what the user asked */
404 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
406 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
407 if (Cache
[I
].Delete() == true)
409 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
411 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
412 List
+= I
.FullName(true) + "* ";
414 List
+= I
.FullName(true) + " ";
416 VersionsList
+= string(Cache
[I
].CandVersion
)+ "\n";
420 ShowList(out
,_("The following packages will be REMOVED:"),List
,VersionsList
);
423 // ShowKept - Show kept packages /*{{{*/
424 // ---------------------------------------------------------------------
426 void ShowKept(ostream
&out
,CacheFile
&Cache
)
430 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
432 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
435 if (Cache
[I
].Upgrade() == true || Cache
[I
].Upgradable() == false ||
436 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
439 List
+= I
.FullName(true) + " ";
440 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
442 ShowList(out
,_("The following packages have been kept back:"),List
,VersionsList
);
445 // ShowUpgraded - Show upgraded packages /*{{{*/
446 // ---------------------------------------------------------------------
448 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
452 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
454 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
457 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
459 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
462 List
+= I
.FullName(true) + " ";
463 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
465 ShowList(out
,_("The following packages will be upgraded:"),List
,VersionsList
);
468 // ShowDowngraded - Show downgraded packages /*{{{*/
469 // ---------------------------------------------------------------------
471 bool ShowDowngraded(ostream
&out
,CacheFile
&Cache
)
475 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
477 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
480 if (Cache
[I
].Downgrade() == false || Cache
[I
].NewInstall() == true)
482 if (Cache
[I
].CandidateVerIter(Cache
).Pseudo() == true)
485 List
+= I
.FullName(true) + " ";
486 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
488 return ShowList(out
,_("The following packages will be DOWNGRADED:"),List
,VersionsList
);
491 // ShowHold - Show held but changed packages /*{{{*/
492 // ---------------------------------------------------------------------
494 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
498 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
500 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
501 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
502 I
->SelectedState
== pkgCache::State::Hold
) {
503 List
+= I
.FullName(true) + " ";
504 VersionsList
+= string(Cache
[I
].CurVersion
) + " => " + Cache
[I
].CandVersion
+ "\n";
508 return ShowList(out
,_("The following held packages will be changed:"),List
,VersionsList
);
511 // ShowEssential - Show an essential package warning /*{{{*/
512 // ---------------------------------------------------------------------
513 /* This prints out a warning message that is not to be ignored. It shows
514 all essential packages and their dependents that are to be removed.
515 It is insanely risky to remove the dependents of an essential package! */
516 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
520 bool *Added
= new bool[Cache
->Head().PackageCount
];
521 for (unsigned int I
= 0; I
!= Cache
->Head().PackageCount
; I
++)
524 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
526 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
527 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
&&
528 (I
->Flags
& pkgCache::Flag::Important
) != pkgCache::Flag::Important
)
531 // The essential package is being removed
532 if (Cache
[I
].Delete() == true)
534 if (Added
[I
->ID
] == false)
537 List
+= I
.FullName(true) + " ";
538 //VersionsList += string(Cache[I].CurVersion) + "\n"; ???
544 if (I
->CurrentVer
== 0)
547 // Print out any essential package depenendents that are to be removed
548 for (pkgCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
550 // Skip everything but depends
551 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
552 D
->Type
!= pkgCache::Dep::Depends
)
555 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
556 if (Cache
[P
].Delete() == true)
558 if (Added
[P
->ID
] == true)
563 snprintf(S
,sizeof(S
),_("%s (due to %s) "),P
.FullName(true).c_str(),I
.FullName(true).c_str());
565 //VersionsList += "\n"; ???
571 return ShowList(out
,_("WARNING: The following essential packages will be removed.\n"
572 "This should NOT be done unless you know exactly what you are doing!"),List
,VersionsList
);
576 // Stats - Show some statistics /*{{{*/
577 // ---------------------------------------------------------------------
579 void Stats(ostream
&out
,pkgDepCache
&Dep
)
581 unsigned long Upgrade
= 0;
582 unsigned long Downgrade
= 0;
583 unsigned long Install
= 0;
584 unsigned long ReInstall
= 0;
585 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
587 if (pkgCache::VerIterator(Dep
, Dep
[I
].CandidateVer
).Pseudo() == true)
590 if (Dep
[I
].NewInstall() == true)
594 if (Dep
[I
].Upgrade() == true)
597 if (Dep
[I
].Downgrade() == true)
601 if (Dep
[I
].Delete() == false && (Dep
[I
].iFlags
& pkgDepCache::ReInstall
) == pkgDepCache::ReInstall
)
605 ioprintf(out
,_("%lu upgraded, %lu newly installed, "),
609 ioprintf(out
,_("%lu reinstalled, "),ReInstall
);
611 ioprintf(out
,_("%lu downgraded, "),Downgrade
);
613 ioprintf(out
,_("%lu to remove and %lu not upgraded.\n"),
614 Dep
.DelCount(),Dep
.KeepCount());
616 if (Dep
.BadCount() != 0)
617 ioprintf(out
,_("%lu not fully installed or removed.\n"),
621 // CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/
622 class CacheSetHelperAPTGet
: public APT::CacheSetHelper
{
623 /** \brief stream message should be printed to */
625 /** \brief were things like Task or RegEx used to select packages? */
626 bool explicitlyNamed
;
628 APT::PackageSet virtualPkgs
;
631 std::list
<std::pair
<pkgCache::VerIterator
, std::string
> > selectedByRelease
;
633 CacheSetHelperAPTGet(std::ostream
&out
) : APT::CacheSetHelper(true), out(out
) {
634 explicitlyNamed
= true;
637 virtual void showTaskSelection(APT::PackageSet
const &pkgset
, string
const &pattern
) {
638 for (APT::PackageSet::const_iterator Pkg
= pkgset
.begin(); Pkg
!= pkgset
.end(); ++Pkg
)
639 ioprintf(out
, _("Note, selecting '%s' for task '%s'\n"),
640 Pkg
.FullName(true).c_str(), pattern
.c_str());
641 explicitlyNamed
= false;
643 virtual void showRegExSelection(APT::PackageSet
const &pkgset
, string
const &pattern
) {
644 for (APT::PackageSet::const_iterator Pkg
= pkgset
.begin(); Pkg
!= pkgset
.end(); ++Pkg
)
645 ioprintf(out
, _("Note, selecting '%s' for regex '%s'\n"),
646 Pkg
.FullName(true).c_str(), pattern
.c_str());
647 explicitlyNamed
= false;
649 virtual void showSelectedVersion(pkgCache::PkgIterator
const &Pkg
, pkgCache::VerIterator
const Ver
,
650 string
const &ver
, bool const &verIsRel
) {
651 if (ver
== Ver
.VerStr())
653 selectedByRelease
.push_back(make_pair(Ver
, ver
));
656 bool showVirtualPackageErrors(pkgCacheFile
&Cache
) {
657 if (virtualPkgs
.empty() == true)
659 for (APT::PackageSet::const_iterator Pkg
= virtualPkgs
.begin();
660 Pkg
!= virtualPkgs
.end(); ++Pkg
) {
661 if (Pkg
->ProvidesList
!= 0) {
662 ioprintf(c1out
,_("Package %s is a virtual package provided by:\n"),
663 Pkg
.FullName(true).c_str());
665 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
666 unsigned short provider
= 0;
667 for (; I
.end() == false; ++I
) {
668 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
670 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer()) {
671 out
<< " " << Pkg
.FullName(true) << " " << I
.OwnerVer().VerStr();
672 if (Cache
[Pkg
].Install() == true && Cache
[Pkg
].NewInstall() == false)
673 out
<< _(" [Installed]");
678 // if we found no candidate which provide this package, show non-candidates
680 for (I
= Pkg
.ProvidesList(); I
.end() == false; I
++)
681 out
<< " " << I
.OwnerPkg().FullName(true) << " " << I
.OwnerVer().VerStr()
682 << _(" [Not candidate version]") << endl
;
684 out
<< _("You should explicitly select one to install.") << endl
;
687 _("Package %s is not available, but is referred to by another package.\n"
688 "This may mean that the package is missing, has been obsoleted, or\n"
689 "is only available from another source\n"),Pkg
.FullName(true).c_str());
693 SPtrArray
<bool> Seen
= new bool[Cache
.GetPkgCache()->Head().PackageCount
];
694 memset(Seen
,0,Cache
.GetPkgCache()->Head().PackageCount
*sizeof(*Seen
));
695 for (pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
696 Dep
.end() == false; Dep
++) {
697 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
699 if (Seen
[Dep
.ParentPkg()->ID
] == true)
701 Seen
[Dep
.ParentPkg()->ID
] = true;
702 List
+= Dep
.ParentPkg().FullName(true) + " ";
703 //VersionsList += string(Dep.ParentPkg().CurVersion) + "\n"; ???
705 ShowList(out
,_("However the following packages replace it:"),List
,VersionsList
);
712 virtual pkgCache::VerIterator
canNotFindCandidateVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
713 APT::VersionSet
const verset
= tryVirtualPackage(Cache
, Pkg
, APT::VersionSet::CANDIDATE
);
714 if (verset
.empty() == false)
715 return *(verset
.begin());
716 if (ShowError
== true) {
717 _error
->Error(_("Package '%s' has no installation candidate"),Pkg
.FullName(true).c_str());
718 virtualPkgs
.insert(Pkg
);
720 return pkgCache::VerIterator(Cache
, 0);
723 virtual pkgCache::VerIterator
canNotFindNewestVer(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
724 APT::VersionSet
const verset
= tryVirtualPackage(Cache
, Pkg
, APT::VersionSet::NEWEST
);
725 if (verset
.empty() == false)
726 return *(verset
.begin());
727 if (ShowError
== true)
728 ioprintf(out
, _("Virtual packages like '%s' can't be removed\n"), Pkg
.FullName(true).c_str());
729 return pkgCache::VerIterator(Cache
, 0);
732 APT::VersionSet
tryVirtualPackage(pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
,
733 APT::VersionSet::Version
const &select
) {
734 /* This is a pure virtual package and there is a single available
735 candidate providing it. */
736 if (unlikely(Cache
[Pkg
].CandidateVer
!= 0) || Pkg
->ProvidesList
== 0)
737 return APT::VersionSet();
739 pkgCache::PkgIterator Prov
;
740 bool found_one
= false;
741 for (pkgCache::PrvIterator P
= Pkg
.ProvidesList(); P
; ++P
) {
742 pkgCache::VerIterator
const PVer
= P
.OwnerVer();
743 pkgCache::PkgIterator
const PPkg
= PVer
.ParentPkg();
745 /* Ignore versions that are not a candidate. */
746 if (Cache
[PPkg
].CandidateVer
!= PVer
)
749 if (found_one
== false) {
752 } else if (PPkg
!= Prov
) {
753 found_one
= false; // we found at least two
758 if (found_one
== true) {
759 ioprintf(out
, _("Note, selecting '%s' instead of '%s'\n"),
760 Prov
.FullName(true).c_str(), Pkg
.FullName(true).c_str());
761 return APT::VersionSet::FromPackage(Cache
, Prov
, select
, *this);
763 return APT::VersionSet();
766 inline bool allPkgNamedExplicitly() const { return explicitlyNamed
; }
770 // TryToInstall - Mark a package for installation /*{{{*/
771 struct TryToInstall
{
773 pkgProblemResolver
* Fix
;
775 unsigned long AutoMarkChanged
;
776 APT::PackageSet doAutoInstallLater
;
778 TryToInstall(pkgCacheFile
&Cache
, pkgProblemResolver
&PM
, bool const &FixBroken
) : Cache(&Cache
), Fix(&PM
),
779 FixBroken(FixBroken
), AutoMarkChanged(0) {};
781 void operator() (pkgCache::VerIterator
const &Ver
) {
782 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
784 Cache
->GetDepCache()->SetCandidateVersion(Ver
);
785 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
787 // Handle the no-upgrade case
788 if (_config
->FindB("APT::Get::upgrade",true) == false && Pkg
->CurrentVer
!= 0)
789 ioprintf(c1out
,_("Skipping %s, it is already installed and upgrade is not set.\n"),
790 Pkg
.FullName(true).c_str());
791 // Ignore request for install if package would be new
792 else if (_config
->FindB("APT::Get::Only-Upgrade", false) == true && Pkg
->CurrentVer
== 0)
793 ioprintf(c1out
,_("Skipping %s, it is not installed and only upgrades are requested.\n"),
794 Pkg
.FullName(true).c_str());
798 Cache
->GetDepCache()->MarkInstall(Pkg
,false);
800 if (State
.Install() == false) {
801 if (_config
->FindB("APT::Get::ReInstall",false) == true) {
802 if (Pkg
->CurrentVer
== 0 || Pkg
.CurrentVer().Downloadable() == false)
803 ioprintf(c1out
,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
804 Pkg
.FullName(true).c_str());
806 Cache
->GetDepCache()->SetReInstall(Pkg
, true);
808 ioprintf(c1out
,_("%s is already the newest version.\n"),
809 Pkg
.FullName(true).c_str());
812 // Install it with autoinstalling enabled (if we not respect the minial
813 // required deps or the policy)
814 if (FixBroken
== false)
815 doAutoInstallLater
.insert(Pkg
);
818 // see if we need to fix the auto-mark flag
819 // e.g. apt-get install foo
820 // where foo is marked automatic
821 if (State
.Install() == false &&
822 (State
.Flags
& pkgCache::Flag::Auto
) &&
823 _config
->FindB("APT::Get::ReInstall",false) == false &&
824 _config
->FindB("APT::Get::Only-Upgrade",false) == false &&
825 _config
->FindB("APT::Get::Download-Only",false) == false)
827 ioprintf(c1out
,_("%s set to manually installed.\n"),
828 Pkg
.FullName(true).c_str());
829 Cache
->GetDepCache()->MarkAuto(Pkg
,false);
834 bool propergateReleaseCandiateSwitching(std::list
<std::pair
<pkgCache::VerIterator
, std::string
> > start
, std::ostream
&out
)
836 for (std::list
<std::pair
<pkgCache::VerIterator
, std::string
> >::const_iterator s
= start
.begin();
837 s
!= start
.end(); ++s
)
838 Cache
->GetDepCache()->SetCandidateVersion(s
->first
);
841 std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> > Changed
;
842 for (std::list
<std::pair
<pkgCache::VerIterator
, std::string
> >::const_iterator s
= start
.begin();
843 s
!= start
.end(); ++s
)
845 Changed
.push_back(std::make_pair(s
->first
, pkgCache::VerIterator(*Cache
)));
846 // We continue here even if it failed to enhance the ShowBroken output
847 Success
&= Cache
->GetDepCache()->SetCandidateRelease(s
->first
, s
->second
, Changed
);
849 for (std::list
<std::pair
<pkgCache::VerIterator
, pkgCache::VerIterator
> >::const_iterator c
= Changed
.begin();
850 c
!= Changed
.end(); ++c
)
852 if (c
->second
.end() == true)
853 ioprintf(out
, _("Selected version '%s' (%s) for '%s'\n"),
854 c
->first
.VerStr(), c
->first
.RelStr().c_str(), c
->first
.ParentPkg().FullName(true).c_str());
855 else if (c
->first
.ParentPkg()->Group
!= c
->second
.ParentPkg()->Group
)
857 pkgCache::VerIterator V
= (*Cache
)[c
->first
.ParentPkg()].CandidateVerIter(*Cache
);
858 ioprintf(out
, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V
.VerStr(),
859 V
.RelStr().c_str(), V
.ParentPkg().FullName(true).c_str(), c
->second
.ParentPkg().FullName(true).c_str());
865 void doAutoInstall() {
866 for (APT::PackageSet::const_iterator P
= doAutoInstallLater
.begin();
867 P
!= doAutoInstallLater
.end(); ++P
) {
868 pkgDepCache::StateCache
&State
= (*Cache
)[P
];
869 if (State
.InstBroken() == false && State
.InstPolicyBroken() == false)
871 Cache
->GetDepCache()->MarkInstall(P
, true);
873 doAutoInstallLater
.clear();
877 // TryToRemove - Mark a package for removal /*{{{*/
880 pkgProblemResolver
* Fix
;
883 unsigned long AutoMarkChanged
;
885 TryToRemove(pkgCacheFile
&Cache
, pkgProblemResolver
&PM
) : Cache(&Cache
), Fix(&PM
),
886 PurgePkgs(_config
->FindB("APT::Get::Purge", false)) {};
888 void operator() (pkgCache::VerIterator
const &Ver
)
890 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
896 if ((Pkg
->CurrentVer
== 0 && PurgePkgs
== false) ||
897 (PurgePkgs
== true && Pkg
->CurrentState
== pkgCache::State::NotInstalled
))
899 ioprintf(c1out
,_("Package %s is not installed, so not removed\n"),Pkg
.FullName(true).c_str());
900 // MarkInstall refuses to install packages on hold
901 Pkg
->SelectedState
= pkgCache::State::Hold
;
904 Cache
->GetDepCache()->MarkDelete(Pkg
, PurgePkgs
);
908 // CacheFile::NameComp - QSort compare by name /*{{{*/
909 // ---------------------------------------------------------------------
911 pkgCache
*CacheFile::SortCache
= 0;
912 int CacheFile::NameComp(const void *a
,const void *b
)
914 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
915 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
917 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
918 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
920 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
923 // CacheFile::Sort - Sort by name /*{{{*/
924 // ---------------------------------------------------------------------
926 void CacheFile::Sort()
929 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
930 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
931 pkgCache::PkgIterator I
= Cache
->PkgBegin();
932 for (;I
.end() != true; I
++)
936 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
939 // CacheFile::CheckDeps - Open the cache file /*{{{*/
940 // ---------------------------------------------------------------------
941 /* This routine generates the caches and then opens the dependency cache
942 and verifies that the system is OK. */
943 bool CacheFile::CheckDeps(bool AllowBroken
)
945 bool FixBroken
= _config
->FindB("APT::Get::Fix-Broken",false);
947 if (_error
->PendingError() == true)
950 // Check that the system is OK
951 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
952 return _error
->Error("Internal error, non-zero counts");
954 // Apply corrections for half-installed packages
955 if (pkgApplyStatus(*DCache
) == false)
958 if (_config
->FindB("APT::Get::Fix-Policy-Broken",false) == true)
961 if ((DCache
->PolicyBrokenCount() > 0))
963 // upgrade all policy-broken packages with ForceImportantDeps=True
964 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); !I
.end(); I
++)
965 if ((*DCache
)[I
].NowPolicyBroken() == true)
966 DCache
->MarkInstall(I
,true,0, false, true);
971 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
974 // Attempt to fix broken things
975 if (FixBroken
== true)
977 c1out
<< _("Correcting dependencies...") << flush
;
978 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
980 c1out
<< _(" failed.") << endl
;
981 ShowBroken(c1out
,*this,true);
983 return _error
->Error(_("Unable to correct dependencies"));
985 if (pkgMinimizeUpgrade(*DCache
) == false)
986 return _error
->Error(_("Unable to minimize the upgrade set"));
988 c1out
<< _(" Done") << endl
;
992 c1out
<< _("You might want to run 'apt-get -f install' to correct these.") << endl
;
993 ShowBroken(c1out
,*this,true);
995 return _error
->Error(_("Unmet dependencies. Try using -f."));
1001 // CheckAuth - check if each download comes form a trusted source /*{{{*/
1002 // ---------------------------------------------------------------------
1004 static bool CheckAuth(pkgAcquire
& Fetcher
)
1006 string UntrustedList
;
1007 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd(); ++I
)
1009 if (!(*I
)->IsTrusted())
1011 UntrustedList
+= string((*I
)->ShortDesc()) + " ";
1015 if (UntrustedList
== "")
1020 ShowList(c2out
,_("WARNING: The following packages cannot be authenticated!"),UntrustedList
,"");
1022 if (_config
->FindB("APT::Get::AllowUnauthenticated",false) == true)
1024 c2out
<< _("Authentication warning overridden.\n");
1028 if (_config
->FindI("quiet",0) < 2
1029 && _config
->FindB("APT::Get::Assume-Yes",false) == false)
1031 c2out
<< _("Install these packages without verification [y/N]? ") << flush
;
1032 if (!YnPrompt(false))
1033 return _error
->Error(_("Some packages could not be authenticated"));
1037 else if (_config
->FindB("APT::Get::Force-Yes",false) == true)
1042 return _error
->Error(_("There are problems and -y was used without --force-yes"));
1045 // InstallPackages - Actually download and install the packages /*{{{*/
1046 // ---------------------------------------------------------------------
1047 /* This displays the informative messages describing what is going to
1048 happen and then calls the download routines */
1049 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,
1052 if (_config
->FindB("APT::Get::Purge",false) == true)
1054 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1055 for (; I
.end() == false; I
++)
1057 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
1058 Cache
->MarkDelete(I
,true);
1063 bool Essential
= false;
1065 // Show all the various warning indicators
1066 ShowDel(c1out
,Cache
);
1067 ShowNew(c1out
,Cache
);
1068 if (ShwKept
== true)
1069 ShowKept(c1out
,Cache
);
1070 Fail
|= !ShowHold(c1out
,Cache
);
1071 if (_config
->FindB("APT::Get::Show-Upgraded",true) == true)
1072 ShowUpgraded(c1out
,Cache
);
1073 Fail
|= !ShowDowngraded(c1out
,Cache
);
1074 if (_config
->FindB("APT::Get::Download-Only",false) == false)
1075 Essential
= !ShowEssential(c1out
,Cache
);
1080 if (Cache
->BrokenCount() != 0)
1082 ShowBroken(c1out
,Cache
,false);
1083 return _error
->Error(_("Internal error, InstallPackages was called with broken packages!"));
1086 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
1087 Cache
->BadCount() == 0)
1091 if (Cache
->DelCount() != 0 && _config
->FindB("APT::Get::Remove",true) == false)
1092 return _error
->Error(_("Packages need to be removed but remove is disabled."));
1094 // Run the simulator ..
1095 if (_config
->FindB("APT::Get::Simulate") == true)
1097 pkgSimulate
PM(Cache
);
1098 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
1099 pkgPackageManager::OrderResult Res
= PM
.DoInstall(status_fd
);
1100 if (Res
== pkgPackageManager::Failed
)
1102 if (Res
!= pkgPackageManager::Completed
)
1103 return _error
->Error(_("Internal error, Ordering didn't finish"));
1107 // Create the text record parser
1108 pkgRecords
Recs(Cache
);
1109 if (_error
->PendingError() == true)
1112 // Create the download object
1114 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1115 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
1117 // force a hashsum for compatibility reasons
1118 _config
->CndSet("Acquire::ForceHash", "md5sum");
1120 else if (Fetcher
.Setup(&Stat
, _config
->FindDir("Dir::Cache::Archives")) == false)
1123 // Read the source list
1124 if (Cache
.BuildSourceList() == false)
1126 pkgSourceList
*List
= Cache
.GetSourceList();
1128 // Create the package manager and prepare to download
1129 SPtr
<pkgPackageManager
> PM
= _system
->CreatePM(Cache
);
1130 if (PM
->GetArchives(&Fetcher
,List
,&Recs
) == false ||
1131 _error
->PendingError() == true)
1134 // Display statistics
1135 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
1136 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
1137 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
1138 if (DebBytes
!= Cache
->DebSize())
1140 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
1141 c0out
<< _("How odd.. The sizes didn't match, email apt@packages.debian.org") << endl
;
1145 if (DebBytes
!= FetchBytes
)
1146 //TRANSLATOR: The required space between number and unit is already included
1147 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
1148 ioprintf(c1out
,_("Need to get %sB/%sB of archives.\n"),
1149 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
1150 else if (DebBytes
!= 0)
1151 //TRANSLATOR: The required space between number and unit is already included
1152 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
1153 ioprintf(c1out
,_("Need to get %sB of archives.\n"),
1154 SizeToStr(DebBytes
).c_str());
1157 if (Cache
->UsrSize() >= 0)
1158 //TRANSLATOR: The required space between number and unit is already included
1159 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
1160 ioprintf(c1out
,_("After this operation, %sB of additional disk space will be used.\n"),
1161 SizeToStr(Cache
->UsrSize()).c_str());
1163 //TRANSLATOR: The required space between number and unit is already included
1164 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
1165 ioprintf(c1out
,_("After this operation, %sB disk space will be freed.\n"),
1166 SizeToStr(-1*Cache
->UsrSize()).c_str());
1168 if (_error
->PendingError() == true)
1171 /* Check for enough free space, but only if we are actually going to
1173 if (_config
->FindB("APT::Get::Print-URIs") == false &&
1174 _config
->FindB("APT::Get::Download",true) == true)
1177 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
1178 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
1179 if (errno
== EOVERFLOW
)
1180 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
1183 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
1185 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1188 if (statfs(OutputDir
.c_str(),&Stat
) != 0
1189 #if HAVE_STRUCT_STATFS_F_TYPE
1190 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
1193 return _error
->Error(_("You don't have enough free space in %s."),
1199 if (_config
->FindI("quiet",0) >= 2 ||
1200 _config
->FindB("APT::Get::Assume-Yes",false) == true)
1202 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
1203 return _error
->Error(_("There are problems and -y was used without --force-yes"));
1206 if (Essential
== true && Safety
== true)
1208 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
1209 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
1211 const char *Prompt
= _("Yes, do as I say!");
1213 _("You are about to do something potentially harmful.\n"
1214 "To continue type in the phrase '%s'\n"
1217 if (AnalPrompt(Prompt
) == false)
1219 c2out
<< _("Abort.") << endl
;
1225 // Prompt to continue
1226 if (Ask
== true || Fail
== true)
1228 if (_config
->FindB("APT::Get::Trivial-Only",false) == true)
1229 return _error
->Error(_("Trivial Only specified but this is not a trivial operation."));
1231 if (_config
->FindI("quiet",0) < 2 &&
1232 _config
->FindB("APT::Get::Assume-Yes",false) == false)
1234 c2out
<< _("Do you want to continue [Y/n]? ") << flush
;
1236 if (YnPrompt() == false)
1238 c2out
<< _("Abort.") << endl
;
1245 // Just print out the uris an exit if the --print-uris flag was used
1246 if (_config
->FindB("APT::Get::Print-URIs") == true)
1248 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1249 for (; I
!= Fetcher
.UriEnd(); I
++)
1250 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1251 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
1255 if (!CheckAuth(Fetcher
))
1258 /* Unlock the dpkg lock if we are not going to be doing an install
1260 if (_config
->FindB("APT::Get::Download-Only",false) == true)
1266 bool Transient
= false;
1267 if (_config
->FindB("APT::Get::Download",true) == false)
1269 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
< Fetcher
.ItemsEnd();)
1271 if ((*I
)->Local
== true)
1277 // Close the item and check if it was found in cache
1279 if ((*I
)->Complete
== false)
1282 // Clear it out of the fetch list
1284 I
= Fetcher
.ItemsBegin();
1288 if (Fetcher
.Run() == pkgAcquire::Failed
)
1292 bool Failed
= false;
1293 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1295 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1296 (*I
)->Complete
== true)
1299 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
1306 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
1307 (*I
)->ErrorText
.c_str());
1311 /* If we are in no download mode and missing files and there were
1312 'failures' then the user must specify -m. Furthermore, there
1313 is no such thing as a transient error in no-download mode! */
1314 if (Transient
== true &&
1315 _config
->FindB("APT::Get::Download",true) == false)
1321 if (_config
->FindB("APT::Get::Download-Only",false) == true)
1323 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
1324 return _error
->Error(_("Some files failed to download"));
1325 c1out
<< _("Download complete and in download only mode") << endl
;
1329 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
1331 return _error
->Error(_("Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"));
1334 if (Transient
== true && Failed
== true)
1335 return _error
->Error(_("--fix-missing and media swapping is not currently supported"));
1337 // Try to deal with missing package files
1338 if (Failed
== true && PM
->FixMissing() == false)
1340 cerr
<< _("Unable to correct missing packages.") << endl
;
1341 return _error
->Error(_("Aborting install."));
1345 int status_fd
= _config
->FindI("APT::Status-Fd",-1);
1346 pkgPackageManager::OrderResult Res
= PM
->DoInstall(status_fd
);
1347 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
1349 if (Res
== pkgPackageManager::Completed
)
1352 // Reload the fetcher object and loop again for media swapping
1354 if (PM
->GetArchives(&Fetcher
,List
,&Recs
) == false)
1360 std::set
<std::string
> const disappearedPkgs
= PM
->GetDisappearedPackages();
1361 if (disappearedPkgs
.empty() == true)
1365 for (std::set
<std::string
>::const_iterator d
= disappearedPkgs
.begin();
1366 d
!= disappearedPkgs
.end(); ++d
)
1367 disappear
.append(*d
).append(" ");
1369 ShowList(c1out
, P_("The following package disappeared from your system as\n"
1370 "all files have been overwritten by other packages:",
1371 "The following packages disappeared from your system as\n"
1372 "all files have been overwritten by other packages:", disappearedPkgs
.size()), disappear
, "");
1373 c0out
<< _("Note: This is done automatic and on purpose by dpkg.") << std::endl
;
1378 // TryToInstallBuildDep - Try to install a single package /*{{{*/
1379 // ---------------------------------------------------------------------
1380 /* This used to be inlined in DoInstall, but with the advent of regex package
1381 name matching it was split out.. */
1382 bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg
,pkgCacheFile
&Cache
,
1383 pkgProblemResolver
&Fix
,bool Remove
,bool BrokenFix
,
1384 bool AllowFail
= true)
1386 if (Cache
[Pkg
].CandidateVer
== 0 && Pkg
->ProvidesList
!= 0)
1388 CacheSetHelperAPTGet
helper(c1out
);
1389 helper
.showErrors(AllowFail
== false);
1390 pkgCache::VerIterator Ver
= helper
.canNotFindNewestVer(Cache
, Pkg
);
1391 if (Ver
.end() == false)
1392 Pkg
= Ver
.ParentPkg();
1393 else if (helper
.showVirtualPackageErrors(Cache
) == false)
1399 TryToRemove
RemoveAction(Cache
, Fix
);
1400 RemoveAction(Pkg
.VersionList());
1401 } else if (Cache
[Pkg
].CandidateVer
!= 0) {
1402 TryToInstall
InstallAction(Cache
, Fix
, BrokenFix
);
1403 InstallAction(Cache
[Pkg
].CandidateVerIter(Cache
));
1404 InstallAction
.doAutoInstall();
1411 // FindSrc - Find a source record /*{{{*/
1412 // ---------------------------------------------------------------------
1414 pkgSrcRecords::Parser
*FindSrc(const char *Name
,pkgRecords
&Recs
,
1415 pkgSrcRecords
&SrcRecs
,string
&Src
,
1419 string DefRel
= _config
->Find("APT::Default-Release");
1420 string TmpSrc
= Name
;
1422 // extract the version/release from the pkgname
1423 const size_t found
= TmpSrc
.find_last_of("/=");
1424 if (found
!= string::npos
) {
1425 if (TmpSrc
[found
] == '/')
1426 DefRel
= TmpSrc
.substr(found
+1);
1428 VerTag
= TmpSrc
.substr(found
+1);
1429 TmpSrc
= TmpSrc
.substr(0,found
);
1432 /* Lookup the version of the package we would install if we were to
1433 install a version and determine the source package name, then look
1434 in the archive for a source package of the same name. */
1435 bool MatchSrcOnly
= _config
->FindB("APT::Get::Only-Source");
1436 const pkgCache::PkgIterator Pkg
= Cache
.FindPkg(TmpSrc
);
1437 if (MatchSrcOnly
== false && Pkg
.end() == false)
1439 if(VerTag
.empty() == false || DefRel
.empty() == false)
1442 // we have a default release, try to locate the pkg. we do it like
1443 // this because GetCandidateVer() will not "downgrade", that means
1444 // "apt-get source -t stable apt" won't work on a unstable system
1445 for (pkgCache::VerIterator Ver
= Pkg
.VersionList();; Ver
++)
1447 // try first only exact matches, later fuzzy matches
1448 if (Ver
.end() == true)
1453 Ver
= Pkg
.VersionList();
1454 // exit right away from the Pkg.VersionList() loop if we
1455 // don't have any versions
1456 if (Ver
.end() == true)
1459 // We match against a concrete version (or a part of this version)
1460 if (VerTag
.empty() == false &&
1461 (fuzzy
== true || Cache
.VS().CmpVersion(VerTag
, Ver
.VerStr()) != 0) && // exact match
1462 (fuzzy
== false || strncmp(VerTag
.c_str(), Ver
.VerStr(), VerTag
.size()) != 0)) // fuzzy match
1465 for (pkgCache::VerFileIterator VF
= Ver
.FileList();
1466 VF
.end() == false; VF
++)
1468 /* If this is the status file, and the current version is not the
1469 version in the status file (ie it is not installed, or somesuch)
1470 then it is not a candidate for installation, ever. This weeds
1471 out bogus entries that may be due to config-file states, or
1473 if ((VF
.File()->Flags
& pkgCache::Flag::NotSource
) ==
1474 pkgCache::Flag::NotSource
&& Pkg
.CurrentVer() != Ver
)
1477 // or we match against a release
1478 if(VerTag
.empty() == false ||
1479 (VF
.File().Archive() != 0 && VF
.File().Archive() == DefRel
) ||
1480 (VF
.File().Codename() != 0 && VF
.File().Codename() == DefRel
))
1482 pkgRecords::Parser
&Parse
= Recs
.Lookup(VF
);
1483 Src
= Parse
.SourcePkg();
1484 // no SourcePkg name, so it is the "binary" name
1485 if (Src
.empty() == true)
1487 // the Version we have is possibly fuzzy or includes binUploads,
1488 // so we use the Version of the SourcePkg (empty if same as package)
1489 VerTag
= Parse
.SourceVer();
1490 if (VerTag
.empty() == true)
1491 VerTag
= Ver
.VerStr();
1495 if (Src
.empty() == false)
1498 if (Src
.empty() == true)
1500 // Sources files have no codename information
1501 if (VerTag
.empty() == true && DefRel
.empty() == false)
1503 _error
->Error(_("Ignore unavailable target release '%s' of package '%s'"), DefRel
.c_str(), TmpSrc
.c_str());
1508 if (Src
.empty() == true)
1510 // if we don't have found a fitting package yet so we will
1511 // choose a good candidate and proceed with that.
1512 // Maybe we will find a source later on with the right VerTag
1513 pkgCache::VerIterator Ver
= Cache
.GetCandidateVer(Pkg
);
1514 if (Ver
.end() == false)
1516 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1517 Src
= Parse
.SourcePkg();
1518 if (VerTag
.empty() == true)
1519 VerTag
= Parse
.SourceVer();
1524 if (Src
.empty() == true)
1528 /* if we have a source pkg name, make sure to only search
1529 for srcpkg names, otherwise apt gets confused if there
1530 is a binary package "pkg1" and a source package "pkg1"
1531 with the same name but that comes from different packages */
1532 MatchSrcOnly
= true;
1535 ioprintf(c1out
, _("Picking '%s' as source package instead of '%s'\n"), Src
.c_str(), TmpSrc
.c_str());
1540 pkgSrcRecords::Parser
*Last
= 0;
1541 unsigned long Offset
= 0;
1544 /* Iterate over all of the hits, which includes the resulting
1545 binary packages in the search */
1546 pkgSrcRecords::Parser
*Parse
;
1550 while ((Parse
= SrcRecs
.Find(Src
.c_str(), MatchSrcOnly
)) != 0)
1552 const string Ver
= Parse
->Version();
1554 // Ignore all versions which doesn't fit
1555 if (VerTag
.empty() == false &&
1556 Cache
.VS().CmpVersion(VerTag
, Ver
) != 0) // exact match
1559 // Newer version or an exact match? Save the hit
1560 if (Last
== 0 || Cache
.VS().CmpVersion(Version
,Ver
) < 0) {
1562 Offset
= Parse
->Offset();
1566 // was the version check above an exact match? If so, we don't need to look further
1567 if (VerTag
.empty() == false && VerTag
.size() == Ver
.size())
1570 if (Last
!= 0 || VerTag
.empty() == true)
1572 //if (VerTag.empty() == false && Last == 0)
1573 _error
->Error(_("Ignore unavailable version '%s' of package '%s'"), VerTag
.c_str(), TmpSrc
.c_str());
1577 if (Last
== 0 || Last
->Jump(Offset
) == false)
1583 // DoUpdate - Update the package lists /*{{{*/
1584 // ---------------------------------------------------------------------
1586 bool DoUpdate(CommandLine
&CmdL
)
1588 if (CmdL
.FileSize() != 1)
1589 return _error
->Error(_("The update command takes no arguments"));
1593 // Get the source list
1594 if (Cache
.BuildSourceList() == false)
1596 pkgSourceList
*List
= Cache
.GetSourceList();
1598 // Create the progress
1599 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1601 // Just print out the uris an exit if the --print-uris flag was used
1602 if (_config
->FindB("APT::Get::Print-URIs") == true)
1604 // force a hashsum for compatibility reasons
1605 _config
->CndSet("Acquire::ForceHash", "md5sum");
1609 if (Fetcher
.Setup(&Stat
) == false)
1612 // Populate it with the source selection and get all Indexes
1614 if (List
->GetIndexes(&Fetcher
,true) == false)
1617 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1618 for (; I
!= Fetcher
.UriEnd(); I
++)
1619 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1620 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
1625 if (_config
->FindB("APT::Get::Download",true) == true)
1626 ListUpdate(Stat
, *List
);
1628 // Rebuild the cache.
1629 if (Cache
.BuildCaches() == false)
1635 // DoAutomaticRemove - Remove all automatic unused packages /*{{{*/
1636 // ---------------------------------------------------------------------
1637 /* Remove unused automatic packages */
1638 bool DoAutomaticRemove(CacheFile
&Cache
)
1640 bool Debug
= _config
->FindI("Debug::pkgAutoRemove",false);
1641 bool doAutoRemove
= _config
->FindB("APT::Get::AutomaticRemove", false);
1642 bool hideAutoRemove
= _config
->FindB("APT::Get::HideAutoRemove");
1644 pkgDepCache::ActionGroup
group(*Cache
);
1646 std::cout
<< "DoAutomaticRemove()" << std::endl
;
1648 if (doAutoRemove
== true &&
1649 _config
->FindB("APT::Get::Remove",true) == false)
1651 c1out
<< _("We are not supposed to delete stuff, can't start "
1652 "AutoRemover") << std::endl
;
1656 bool purgePkgs
= _config
->FindB("APT::Get::Purge", false);
1657 bool smallList
= (hideAutoRemove
== false &&
1658 strcasecmp(_config
->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
1660 string autoremovelist
, autoremoveversions
;
1661 unsigned long autoRemoveCount
= 0;
1662 // look over the cache to see what can be removed
1663 for (pkgCache::PkgIterator Pkg
= Cache
->PkgBegin(); ! Pkg
.end(); ++Pkg
)
1665 if (Cache
[Pkg
].Garbage
)
1667 if(Pkg
.CurrentVer() != 0 || Cache
[Pkg
].Install())
1669 std::cout
<< "We could delete %s" << Pkg
.FullName(true).c_str() << std::endl
;
1673 if(Pkg
.CurrentVer() != 0 &&
1674 Pkg
->CurrentState
!= pkgCache::State::ConfigFiles
)
1675 Cache
->MarkDelete(Pkg
, purgePkgs
);
1677 Cache
->MarkKeep(Pkg
, false, false);
1681 // if the package is a new install and already garbage we don't need to
1682 // install it in the first place, so nuke it instead of show it
1683 if (Cache
[Pkg
].Install() == true && Pkg
.CurrentVer() == 0)
1684 Cache
->MarkDelete(Pkg
, false);
1685 // only show stuff in the list that is not yet marked for removal
1686 else if(hideAutoRemove
== false && Cache
[Pkg
].Delete() == false)
1689 // we don't need to fill the strings if we don't need them
1690 if (smallList
== false)
1692 autoremovelist
+= Pkg
.FullName(true) + " ";
1693 autoremoveversions
+= string(Cache
[Pkg
].CandVersion
) + "\n";
1700 // Now see if we had destroyed anything (if we had done anything)
1701 if (Cache
->BrokenCount() != 0)
1703 c1out
<< _("Hmm, seems like the AutoRemover destroyed something which really\n"
1704 "shouldn't happen. Please file a bug report against apt.") << endl
;
1706 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1708 ShowBroken(c1out
,Cache
,false);
1710 return _error
->Error(_("Internal Error, AutoRemover broke stuff"));
1713 // if we don't remove them, we should show them!
1714 if (doAutoRemove
== false && (autoremovelist
.empty() == false || autoRemoveCount
!= 0))
1716 if (smallList
== false)
1717 ShowList(c1out
, P_("The following package was automatically installed and is no longer required:",
1718 "The following packages were automatically installed and are no longer required:",
1719 autoRemoveCount
), autoremovelist
, autoremoveversions
);
1721 ioprintf(c1out
, P_("%lu package was automatically installed and is no longer required.\n",
1722 "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount
), autoRemoveCount
);
1723 c1out
<< _("Use 'apt-get autoremove' to remove them.") << std::endl
;
1728 // DoUpgrade - Upgrade all packages /*{{{*/
1729 // ---------------------------------------------------------------------
1730 /* Upgrade all packages without installing new packages or erasing old
1732 bool DoUpgrade(CommandLine
&CmdL
)
1735 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
1739 if (pkgAllUpgrade(Cache
) == false)
1741 ShowBroken(c1out
,Cache
,false);
1742 return _error
->Error(_("Internal error, AllUpgrade broke stuff"));
1745 return InstallPackages(Cache
,true);
1748 // DoInstall - Install packages from the command line /*{{{*/
1749 // ---------------------------------------------------------------------
1750 /* Install named packages */
1751 bool DoInstall(CommandLine
&CmdL
)
1754 if (Cache
.OpenForInstall() == false ||
1755 Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
1758 // Enter the special broken fixing mode if the user specified arguments
1759 bool BrokenFix
= false;
1760 if (Cache
->BrokenCount() != 0)
1763 pkgProblemResolver
Fix(Cache
);
1765 static const unsigned short MOD_REMOVE
= 1;
1766 static const unsigned short MOD_INSTALL
= 2;
1768 unsigned short fallback
= MOD_INSTALL
;
1769 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
1770 fallback
= MOD_REMOVE
;
1771 else if (strcasecmp(CmdL
.FileList
[0], "purge") == 0)
1773 _config
->Set("APT::Get::Purge", true);
1774 fallback
= MOD_REMOVE
;
1776 else if (strcasecmp(CmdL
.FileList
[0], "autoremove") == 0)
1778 _config
->Set("APT::Get::AutomaticRemove", "true");
1779 fallback
= MOD_REMOVE
;
1782 std::list
<APT::VersionSet::Modifier
> mods
;
1783 mods
.push_back(APT::VersionSet::Modifier(MOD_INSTALL
, "+",
1784 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::CANDIDATE
));
1785 mods
.push_back(APT::VersionSet::Modifier(MOD_REMOVE
, "-",
1786 APT::VersionSet::Modifier::POSTFIX
, APT::VersionSet::NEWEST
));
1787 CacheSetHelperAPTGet
helper(c0out
);
1788 std::map
<unsigned short, APT::VersionSet
> verset
= APT::VersionSet::GroupedFromCommandLine(Cache
,
1789 CmdL
.FileList
+ 1, mods
, fallback
, helper
);
1791 if (_error
->PendingError() == true)
1793 helper
.showVirtualPackageErrors(Cache
);
1797 unsigned short const order
[] = { MOD_REMOVE
, MOD_INSTALL
, 0 };
1799 TryToInstall
InstallAction(Cache
, Fix
, BrokenFix
);
1800 TryToRemove
RemoveAction(Cache
, Fix
);
1802 // new scope for the ActionGroup
1804 pkgDepCache::ActionGroup
group(Cache
);
1806 for (unsigned short i
= 0; order
[i
] != 0; ++i
)
1808 if (order
[i
] == MOD_INSTALL
) {
1809 InstallAction
= std::for_each(verset
[MOD_INSTALL
].begin(), verset
[MOD_INSTALL
].end(), InstallAction
);
1810 InstallAction
.propergateReleaseCandiateSwitching(helper
.selectedByRelease
, c0out
);
1811 InstallAction
.doAutoInstall();
1813 else if (order
[i
] == MOD_REMOVE
)
1814 RemoveAction
= std::for_each(verset
[MOD_REMOVE
].begin(), verset
[MOD_REMOVE
].end(), RemoveAction
);
1817 if (_error
->PendingError() == true)
1820 /* If we are in the Broken fixing mode we do not attempt to fix the
1821 problems. This is if the user invoked install without -f and gave
1823 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
1825 c1out
<< _("You might want to run 'apt-get -f install' to correct these:") << endl
;
1826 ShowBroken(c1out
,Cache
,false);
1828 return _error
->Error(_("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution)."));
1831 // Call the scored problem resolver
1832 Fix
.InstallProtect();
1833 if (Fix
.Resolve(true) == false)
1836 // Now we check the state of the packages,
1837 if (Cache
->BrokenCount() != 0)
1840 _("Some packages could not be installed. This may mean that you have\n"
1841 "requested an impossible situation or if you are using the unstable\n"
1842 "distribution that some required packages have not yet been created\n"
1843 "or been moved out of Incoming.") << endl
;
1849 _("Since you only requested a single operation it is extremely likely that\n"
1850 "the package is simply not installable and a bug report against\n"
1851 "that package should be filed.") << endl;
1855 c1out
<< _("The following information may help to resolve the situation:") << endl
;
1857 ShowBroken(c1out
,Cache
,false);
1858 return _error
->Error(_("Broken packages"));
1861 if (!DoAutomaticRemove(Cache
))
1864 /* Print out a list of packages that are going to be installed extra
1865 to what the user asked */
1866 if (Cache
->InstCount() != verset
[MOD_INSTALL
].size())
1869 string VersionsList
;
1870 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1872 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
1873 if ((*Cache
)[I
].Install() == false)
1875 pkgCache::VerIterator Cand
= Cache
[I
].CandidateVerIter(Cache
);
1876 if (Cand
.Pseudo() == true)
1879 if (verset
[MOD_INSTALL
].find(Cand
) != verset
[MOD_INSTALL
].end())
1882 List
+= I
.FullName(true) + " ";
1883 VersionsList
+= string(Cache
[I
].CandVersion
) + "\n";
1886 ShowList(c1out
,_("The following extra packages will be installed:"),List
,VersionsList
);
1889 /* Print out a list of suggested and recommended packages */
1891 string SuggestsList
, RecommendsList
, List
;
1892 string SuggestsVersions
, RecommendsVersions
;
1893 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
1895 pkgCache::PkgIterator
Pkg(Cache
,Cache
.List
[J
]);
1897 /* Just look at the ones we want to install */
1898 if ((*Cache
)[Pkg
].Install() == false)
1901 // get the recommends/suggests for the candidate ver
1902 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
1903 for (pkgCache::DepIterator D
= CV
.DependsList(); D
.end() == false; )
1905 pkgCache::DepIterator Start
;
1906 pkgCache::DepIterator End
;
1907 D
.GlobOr(Start
,End
); // advances D
1909 // FIXME: we really should display a or-group as a or-group to the user
1910 // the problem is that ShowList is incapable of doing this
1911 string RecommendsOrList
,RecommendsOrVersions
;
1912 string SuggestsOrList
,SuggestsOrVersions
;
1913 bool foundInstalledInOrGroup
= false;
1916 /* Skip if package is installed already, or is about to be */
1917 string target
= Start
.TargetPkg().FullName(true) + " ";
1918 pkgCache::PkgIterator
const TarPkg
= Start
.TargetPkg();
1919 if (TarPkg
->SelectedState
== pkgCache::State::Install
||
1920 TarPkg
->SelectedState
== pkgCache::State::Hold
||
1921 Cache
[Start
.TargetPkg()].Install())
1923 foundInstalledInOrGroup
=true;
1927 /* Skip if we already saw it */
1928 if (int(SuggestsList
.find(target
)) != -1 || int(RecommendsList
.find(target
)) != -1)
1930 foundInstalledInOrGroup
=true;
1934 // this is a dep on a virtual pkg, check if any package that provides it
1935 // should be installed
1936 if(Start
.TargetPkg().ProvidesList() != 0)
1938 pkgCache::PrvIterator I
= Start
.TargetPkg().ProvidesList();
1939 for (; I
.end() == false; I
++)
1941 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
1942 if (Cache
[Pkg
].CandidateVerIter(Cache
) == I
.OwnerVer() &&
1943 Pkg
.CurrentVer() != 0)
1944 foundInstalledInOrGroup
=true;
1948 if (Start
->Type
== pkgCache::Dep::Suggests
)
1950 SuggestsOrList
+= target
;
1951 SuggestsOrVersions
+= string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
1954 if (Start
->Type
== pkgCache::Dep::Recommends
)
1956 RecommendsOrList
+= target
;
1957 RecommendsOrVersions
+= string(Cache
[Start
.TargetPkg()].CandVersion
) + "\n";
1965 if(foundInstalledInOrGroup
== false)
1967 RecommendsList
+= RecommendsOrList
;
1968 RecommendsVersions
+= RecommendsOrVersions
;
1969 SuggestsList
+= SuggestsOrList
;
1970 SuggestsVersions
+= SuggestsOrVersions
;
1976 ShowList(c1out
,_("Suggested packages:"),SuggestsList
,SuggestsVersions
);
1977 ShowList(c1out
,_("Recommended packages:"),RecommendsList
,RecommendsVersions
);
1981 // if nothing changed in the cache, but only the automark information
1982 // we write the StateFile here, otherwise it will be written in
1984 if (InstallAction
.AutoMarkChanged
> 0 &&
1985 Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
1986 Cache
->BadCount() == 0 &&
1987 _config
->FindB("APT::Get::Simulate",false) == false)
1988 Cache
->writeStateFile(NULL
);
1990 // See if we need to prompt
1991 // FIXME: check if really the packages in the set are going to be installed
1992 if (Cache
->InstCount() == verset
[MOD_INSTALL
].size() && Cache
->DelCount() == 0)
1993 return InstallPackages(Cache
,false,false);
1995 return InstallPackages(Cache
,false);
1998 /* mark packages as automatically/manually installed. */
1999 bool DoMarkAuto(CommandLine
&CmdL
)
2002 int AutoMarkChanged
= 0;
2003 OpTextProgress progress
;
2005 if (Cache
.Open() == false)
2008 if (strcasecmp(CmdL
.FileList
[0],"markauto") == 0)
2010 else if (strcasecmp(CmdL
.FileList
[0],"unmarkauto") == 0)
2013 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
2016 // Locate the package
2017 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
2018 if (Pkg
.end() == true) {
2019 return _error
->Error(_("Couldn't find package %s"),S
);
2024 ioprintf(c1out
,_("%s set to manually installed.\n"), Pkg
.Name());
2026 ioprintf(c1out
,_("%s set to automatically installed.\n"),
2029 Cache
->MarkAuto(Pkg
,Action
);
2033 if (AutoMarkChanged
&& ! _config
->FindB("APT::Get::Simulate",false))
2034 return Cache
->writeStateFile(NULL
);
2038 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
2039 // ---------------------------------------------------------------------
2040 /* Intelligent upgrader that will install and remove packages at will */
2041 bool DoDistUpgrade(CommandLine
&CmdL
)
2044 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
2047 c0out
<< _("Calculating upgrade... ") << flush
;
2048 if (pkgDistUpgrade(*Cache
) == false)
2050 c0out
<< _("Failed") << endl
;
2051 ShowBroken(c1out
,Cache
,false);
2055 c0out
<< _("Done") << endl
;
2057 return InstallPackages(Cache
,true);
2060 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
2061 // ---------------------------------------------------------------------
2062 /* Follows dselect's selections */
2063 bool DoDSelectUpgrade(CommandLine
&CmdL
)
2066 if (Cache
.OpenForInstall() == false || Cache
.CheckDeps() == false)
2069 pkgDepCache::ActionGroup
group(Cache
);
2071 // Install everything with the install flag set
2072 pkgCache::PkgIterator I
= Cache
->PkgBegin();
2073 for (;I
.end() != true; I
++)
2075 /* Install the package only if it is a new install, the autoupgrader
2076 will deal with the rest */
2077 if (I
->SelectedState
== pkgCache::State::Install
)
2078 Cache
->MarkInstall(I
,false);
2081 /* Now install their deps too, if we do this above then order of
2082 the status file is significant for | groups */
2083 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
2085 /* Install the package only if it is a new install, the autoupgrader
2086 will deal with the rest */
2087 if (I
->SelectedState
== pkgCache::State::Install
)
2088 Cache
->MarkInstall(I
,true);
2091 // Apply erasures now, they override everything else.
2092 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
2095 if (I
->SelectedState
== pkgCache::State::DeInstall
||
2096 I
->SelectedState
== pkgCache::State::Purge
)
2097 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
2100 /* Resolve any problems that dselect created, allupgrade cannot handle
2101 such things. We do so quite agressively too.. */
2102 if (Cache
->BrokenCount() != 0)
2104 pkgProblemResolver
Fix(Cache
);
2106 // Hold back held packages.
2107 if (_config
->FindB("APT::Ignore-Hold",false) == false)
2109 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
2111 if (I
->SelectedState
== pkgCache::State::Hold
)
2119 if (Fix
.Resolve() == false)
2121 ShowBroken(c1out
,Cache
,false);
2122 return _error
->Error(_("Internal error, problem resolver broke stuff"));
2126 // Now upgrade everything
2127 if (pkgAllUpgrade(Cache
) == false)
2129 ShowBroken(c1out
,Cache
,false);
2130 return _error
->Error(_("Internal error, problem resolver broke stuff"));
2133 return InstallPackages(Cache
,false);
2136 // DoClean - Remove download archives /*{{{*/
2137 // ---------------------------------------------------------------------
2139 bool DoClean(CommandLine
&CmdL
)
2141 if (_config
->FindB("APT::Get::Simulate") == true)
2143 cout
<< "Del " << _config
->FindDir("Dir::Cache::archives") << "* " <<
2144 _config
->FindDir("Dir::Cache::archives") << "partial/*" << endl
;
2148 // Lock the archive directory
2150 if (_config
->FindB("Debug::NoLocking",false) == false)
2152 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
2153 if (_error
->PendingError() == true)
2154 return _error
->Error(_("Unable to lock the download directory"));
2158 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
2159 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
2163 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
2164 // ---------------------------------------------------------------------
2165 /* This is similar to clean but it only purges things that cannot be
2166 downloaded, that is old versions of cached packages. */
2167 class LogCleaner
: public pkgArchiveCleaner
2170 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
2172 c1out
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
2174 if (_config
->FindB("APT::Get::Simulate") == false)
2179 bool DoAutoClean(CommandLine
&CmdL
)
2181 // Lock the archive directory
2183 if (_config
->FindB("Debug::NoLocking",false) == false)
2185 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
2186 if (_error
->PendingError() == true)
2187 return _error
->Error(_("Unable to lock the download directory"));
2191 if (Cache
.Open() == false)
2196 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
2197 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
2200 // DoDownload - download a binary /*{{{*/
2201 // ---------------------------------------------------------------------
2202 bool DoDownload(CommandLine
&CmdL
)
2205 if (Cache
.ReadOnlyOpen() == false)
2208 APT::CacheSetHelper
helper(c0out
);
2209 APT::VersionSet verset
= APT::VersionSet::FromCommandLine(Cache
,
2210 CmdL
.FileList
+ 1, APT::VersionSet::CANDIDATE
, helper
);
2212 if (verset
.empty() == true)
2216 AcqTextStatus
Stat(ScreenWidth
, _config
->FindI("quiet",0));
2217 if (_config
->FindB("APT::Get::Print-URIs") == true)
2218 Fetcher
.Setup(&Stat
);
2220 pkgRecords
Recs(Cache
);
2221 pkgSourceList
*SrcList
= Cache
.GetSourceList();
2222 for (APT::VersionSet::const_iterator Ver
= verset
.begin();
2223 Ver
!= verset
.end();
2227 // get the right version
2228 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
2229 pkgRecords::Parser
&rec
=Recs
.Lookup(Ver
.FileList());
2230 pkgCache::VerFileIterator Vf
= Ver
.FileList();
2231 if (Vf
.end() == true)
2232 return _error
->Error("Can not find VerFile");
2233 pkgCache::PkgFileIterator F
= Vf
.File();
2234 pkgIndexFile
*index
;
2235 if(SrcList
->FindIndex(F
, index
) == false)
2236 return _error
->Error("FindIndex failed");
2237 string uri
= index
->ArchiveURI(rec
.FileName());
2238 strprintf(descr
, _("Downloading %s %s"), Pkg
.Name(), Ver
.VerStr());
2239 // get the most appropriate hash
2241 if (rec
.SHA256Hash() != "")
2242 hash
= HashString("sha256", rec
.SHA256Hash());
2243 else if (rec
.SHA1Hash() != "")
2244 hash
= HashString("sha1", rec
.SHA1Hash());
2245 else if (rec
.MD5Hash() != "")
2246 hash
= HashString("md5", rec
.MD5Hash());
2248 new pkgAcqFile(&Fetcher
, uri
, hash
.toStr(), (*Ver
)->Size
, descr
, Pkg
.Name(), ".");
2251 // Just print out the uris and exit if the --print-uris flag was used
2252 if (_config
->FindB("APT::Get::Print-URIs") == true)
2254 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
2255 for (; I
!= Fetcher
.UriEnd(); I
++)
2256 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
2257 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
2261 return (Fetcher
.Run() == pkgAcquire::Continue
);
2264 // DoCheck - Perform the check operation /*{{{*/
2265 // ---------------------------------------------------------------------
2266 /* Opening automatically checks the system, this command is mostly used
2268 bool DoCheck(CommandLine
&CmdL
)
2277 // DoSource - Fetch a source archive /*{{{*/
2278 // ---------------------------------------------------------------------
2279 /* Fetch souce packages */
2287 bool DoSource(CommandLine
&CmdL
)
2290 if (Cache
.Open(false) == false)
2293 if (CmdL
.FileSize() <= 1)
2294 return _error
->Error(_("Must specify at least one package to fetch source for"));
2296 // Read the source list
2297 if (Cache
.BuildSourceList() == false)
2299 pkgSourceList
*List
= Cache
.GetSourceList();
2301 // Create the text record parsers
2302 pkgRecords
Recs(Cache
);
2303 pkgSrcRecords
SrcRecs(*List
);
2304 if (_error
->PendingError() == true)
2307 // Create the download object
2308 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
2310 if (Fetcher
.Setup(&Stat
) == false)
2313 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
2315 // insert all downloaded uris into this set to avoid downloading them
2319 // Diff only mode only fetches .diff files
2320 bool const diffOnly
= _config
->FindB("APT::Get::Diff-Only", false);
2321 // Tar only mode only fetches .tar files
2322 bool const tarOnly
= _config
->FindB("APT::Get::Tar-Only", false);
2323 // Dsc only mode only fetches .dsc files
2324 bool const dscOnly
= _config
->FindB("APT::Get::Dsc-Only", false);
2326 // Load the requestd sources into the fetcher
2328 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
2331 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
2334 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
2336 string srec
= Last
->AsStr();
2337 string::size_type pos
= srec
.find("\nVcs-");
2338 while (pos
!= string::npos
)
2340 pos
+= strlen("\nVcs-");
2341 string vcs
= srec
.substr(pos
,srec
.find(":",pos
)-pos
);
2342 if(vcs
== "Browser")
2344 pos
= srec
.find("\nVcs-", pos
);
2347 pos
+= vcs
.length()+2;
2348 string::size_type epos
= srec
.find("\n", pos
);
2349 string uri
= srec
.substr(pos
,epos
-pos
).c_str();
2350 ioprintf(c1out
, _("NOTICE: '%s' packaging is maintained in "
2351 "the '%s' version control system at:\n"
2353 Src
.c_str(), vcs
.c_str(), uri
.c_str());
2355 ioprintf(c1out
,_("Please use:\n"
2357 "to retrieve the latest (possibly unreleased) "
2358 "updates to the package.\n"),
2364 vector
<pkgSrcRecords::File
> Lst
;
2365 if (Last
->Files(Lst
) == false)
2368 // Load them into the fetcher
2369 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
2370 I
!= Lst
.end(); I
++)
2372 // Try to guess what sort of file it is we are getting.
2373 if (I
->Type
== "dsc")
2375 Dsc
[J
].Package
= Last
->Package();
2376 Dsc
[J
].Version
= Last
->Version();
2377 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
2380 // Handle the only options so that multiple can be used at once
2381 if (diffOnly
== true || tarOnly
== true || dscOnly
== true)
2383 if ((diffOnly
== true && I
->Type
== "diff") ||
2384 (tarOnly
== true && I
->Type
== "tar") ||
2385 (dscOnly
== true && I
->Type
== "dsc"))
2386 ; // Fine, we want this file downloaded
2391 // don't download the same uri twice (should this be moved to
2392 // the fetcher interface itself?)
2393 if(queued
.find(Last
->Index().ArchiveURI(I
->Path
)) != queued
.end())
2395 queued
.insert(Last
->Index().ArchiveURI(I
->Path
));
2397 // check if we have a file with that md5 sum already localy
2398 if(!I
->MD5Hash
.empty() && FileExists(flNotDir(I
->Path
)))
2400 FileFd
Fd(flNotDir(I
->Path
), FileFd::ReadOnly
);
2402 sum
.AddFD(Fd
.Fd(), Fd
.Size());
2404 if((string
)sum
.Result() == I
->MD5Hash
)
2406 ioprintf(c1out
,_("Skipping already downloaded file '%s'\n"),
2407 flNotDir(I
->Path
).c_str());
2412 new pkgAcqFile(&Fetcher
,Last
->Index().ArchiveURI(I
->Path
),
2414 Last
->Index().SourceInfo(*Last
,*I
),Src
);
2418 // Display statistics
2419 unsigned long long FetchBytes
= Fetcher
.FetchNeeded();
2420 unsigned long long FetchPBytes
= Fetcher
.PartialPresent();
2421 unsigned long long DebBytes
= Fetcher
.TotalNeeded();
2423 // Check for enough free space
2425 string OutputDir
= ".";
2426 if (statvfs(OutputDir
.c_str(),&Buf
) != 0) {
2427 if (errno
== EOVERFLOW
)
2428 return _error
->WarningE("statvfs",_("Couldn't determine free space in %s"),
2431 return _error
->Errno("statvfs",_("Couldn't determine free space in %s"),
2433 } else if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
2436 if (statfs(OutputDir
.c_str(),&Stat
) != 0
2437 #if HAVE_STRUCT_STATFS_F_TYPE
2438 || unsigned(Stat
.f_type
) != RAMFS_MAGIC
2441 return _error
->Error(_("You don't have enough free space in %s"),
2446 if (DebBytes
!= FetchBytes
)
2447 //TRANSLATOR: The required space between number and unit is already included
2448 // in the replacement strings, so %sB will be correctly translate in e.g. 1,5 MB
2449 ioprintf(c1out
,_("Need to get %sB/%sB of source archives.\n"),
2450 SizeToStr(FetchBytes
).c_str(),SizeToStr(DebBytes
).c_str());
2452 //TRANSLATOR: The required space between number and unit is already included
2453 // in the replacement string, so %sB will be correctly translate in e.g. 1,5 MB
2454 ioprintf(c1out
,_("Need to get %sB of source archives.\n"),
2455 SizeToStr(DebBytes
).c_str());
2457 if (_config
->FindB("APT::Get::Simulate",false) == true)
2459 for (unsigned I
= 0; I
!= J
; I
++)
2460 ioprintf(cout
,_("Fetch source %s\n"),Dsc
[I
].Package
.c_str());
2465 // Just print out the uris an exit if the --print-uris flag was used
2466 if (_config
->FindB("APT::Get::Print-URIs") == true)
2468 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
2469 for (; I
!= Fetcher
.UriEnd(); I
++)
2470 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
2471 I
->Owner
->FileSize
<< ' ' << I
->Owner
->HashSum() << endl
;
2477 if (Fetcher
.Run() == pkgAcquire::Failed
)
2480 // Print error messages
2481 bool Failed
= false;
2482 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
2484 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
2485 (*I
)->Complete
== true)
2488 fprintf(stderr
,_("Failed to fetch %s %s\n"),(*I
)->DescURI().c_str(),
2489 (*I
)->ErrorText
.c_str());
2493 return _error
->Error(_("Failed to fetch some archives."));
2495 if (_config
->FindB("APT::Get::Download-only",false) == true)
2497 c1out
<< _("Download complete and in download only mode") << endl
;
2502 // Unpack the sources
2503 pid_t Process
= ExecFork();
2507 bool const fixBroken
= _config
->FindB("APT::Get::Fix-Broken", false);
2508 for (unsigned I
= 0; I
!= J
; I
++)
2510 string Dir
= Dsc
[I
].Package
+ '-' + Cache
->VS().UpstreamVersion(Dsc
[I
].Version
.c_str());
2512 // Diff only mode only fetches .diff files
2513 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
2514 _config
->FindB("APT::Get::Tar-Only",false) == true ||
2515 Dsc
[I
].Dsc
.empty() == true)
2518 // See if the package is already unpacked
2520 if (fixBroken
== false && stat(Dir
.c_str(),&Stat
) == 0 &&
2521 S_ISDIR(Stat
.st_mode
) != 0)
2523 ioprintf(c0out
,_("Skipping unpack of already unpacked source in %s\n"),
2530 snprintf(S
,sizeof(S
),"%s -x %s",
2531 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
2532 Dsc
[I
].Dsc
.c_str());
2535 fprintf(stderr
,_("Unpack command '%s' failed.\n"),S
);
2536 fprintf(stderr
,_("Check if the 'dpkg-dev' package is installed.\n"));
2541 // Try to compile it with dpkg-buildpackage
2542 if (_config
->FindB("APT::Get::Compile",false) == true)
2544 // Call dpkg-buildpackage
2546 snprintf(S
,sizeof(S
),"cd %s && %s %s",
2548 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
2549 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
2553 fprintf(stderr
,_("Build command '%s' failed.\n"),S
);
2563 // Wait for the subprocess
2565 while (waitpid(Process
,&Status
,0) != Process
)
2569 return _error
->Errno("waitpid","Couldn't wait for subprocess");
2572 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
2573 return _error
->Error(_("Child process failed"));
2578 // DoBuildDep - Install/removes packages to satisfy build dependencies /*{{{*/
2579 // ---------------------------------------------------------------------
2580 /* This function will look at the build depends list of the given source
2581 package and install the necessary packages to make it true, or fail. */
2582 bool DoBuildDep(CommandLine
&CmdL
)
2585 if (Cache
.Open(true) == false)
2588 if (CmdL
.FileSize() <= 1)
2589 return _error
->Error(_("Must specify at least one package to check builddeps for"));
2591 // Read the source list
2592 if (Cache
.BuildSourceList() == false)
2594 pkgSourceList
*List
= Cache
.GetSourceList();
2596 // Create the text record parsers
2597 pkgRecords
Recs(Cache
);
2598 pkgSrcRecords
SrcRecs(*List
);
2599 if (_error
->PendingError() == true)
2602 // Create the download object
2603 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
2605 if (Fetcher
.Setup(&Stat
) == false)
2609 bool const StripMultiArch
= APT::Configuration::getArchitectures().size() <= 1;
2610 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
2613 pkgSrcRecords::Parser
*Last
= FindSrc(*I
,Recs
,SrcRecs
,Src
,*Cache
);
2615 return _error
->Error(_("Unable to find a source package for %s"),Src
.c_str());
2617 // Process the build-dependencies
2618 vector
<pkgSrcRecords::Parser::BuildDepRec
> BuildDeps
;
2619 if (Last
->BuildDepends(BuildDeps
, _config
->FindB("APT::Get::Arch-Only", false), StripMultiArch
) == false)
2620 return _error
->Error(_("Unable to get build-dependency information for %s"),Src
.c_str());
2622 // Also ensure that build-essential packages are present
2623 Configuration::Item
const *Opts
= _config
->Tree("APT::Build-Essential");
2626 for (; Opts
; Opts
= Opts
->Next
)
2628 if (Opts
->Value
.empty() == true)
2631 pkgSrcRecords::Parser::BuildDepRec rec
;
2632 rec
.Package
= Opts
->Value
;
2633 rec
.Type
= pkgSrcRecords::Parser::BuildDependIndep
;
2635 BuildDeps
.push_back(rec
);
2638 if (BuildDeps
.size() == 0)
2640 ioprintf(c1out
,_("%s has no build depends.\n"),Src
.c_str());
2644 // Install the requested packages
2645 vector
<pkgSrcRecords::Parser::BuildDepRec
>::iterator D
;
2646 pkgProblemResolver
Fix(Cache
);
2647 bool skipAlternatives
= false; // skip remaining alternatives in an or group
2648 for (D
= BuildDeps
.begin(); D
!= BuildDeps
.end(); D
++)
2650 bool hasAlternatives
= (((*D
).Op
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
);
2652 if (skipAlternatives
== true)
2654 if (!hasAlternatives
)
2655 skipAlternatives
= false; // end of or group
2659 if ((*D
).Type
== pkgSrcRecords::Parser::BuildConflict
||
2660 (*D
).Type
== pkgSrcRecords::Parser::BuildConflictIndep
)
2662 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
2663 // Build-conflicts on unknown packages are silently ignored
2664 if (Pkg
.end() == true)
2667 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
2670 * Remove if we have an installed version that satisfies the
2673 if (IV
.end() == false &&
2674 Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2675 TryToInstallBuildDep(Pkg
,Cache
,Fix
,true,false);
2677 else // BuildDep || BuildDepIndep
2679 pkgCache::PkgIterator Pkg
= Cache
->FindPkg((*D
).Package
);
2680 if (_config
->FindB("Debug::BuildDeps",false) == true)
2681 cout
<< "Looking for " << (*D
).Package
<< "...\n";
2683 if (Pkg
.end() == true)
2685 if (_config
->FindB("Debug::BuildDeps",false) == true)
2686 cout
<< " (not found)" << (*D
).Package
<< endl
;
2688 if (hasAlternatives
)
2691 return _error
->Error(_("%s dependency for %s cannot be satisfied "
2692 "because the package %s cannot be found"),
2693 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
2694 (*D
).Package
.c_str());
2698 * if there are alternatives, we've already picked one, so skip
2701 * TODO: this means that if there's a build-dep on A|B and B is
2702 * installed, we'll still try to install A; more importantly,
2703 * if A is currently broken, we cannot go back and try B. To fix
2704 * this would require we do a Resolve cycle for each package we
2705 * add to the install list. Ugh
2709 * If this is a virtual package, we need to check the list of
2710 * packages that provide it and see if any of those are
2713 pkgCache::PrvIterator Prv
= Pkg
.ProvidesList();
2714 for (; Prv
.end() != true; Prv
++)
2716 if (_config
->FindB("Debug::BuildDeps",false) == true)
2717 cout
<< " Checking provider " << Prv
.OwnerPkg().FullName() << endl
;
2719 if ((*Cache
)[Prv
.OwnerPkg()].InstVerIter(*Cache
).end() == false)
2723 // Get installed version and version we are going to install
2724 pkgCache::VerIterator IV
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
2726 if ((*D
).Version
[0] != '\0') {
2727 // Versioned dependency
2729 pkgCache::VerIterator CV
= (*Cache
)[Pkg
].CandidateVerIter(*Cache
);
2731 for (; CV
.end() != true; CV
++)
2733 if (Cache
->VS().CheckDep(CV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2736 if (CV
.end() == true)
2738 if (hasAlternatives
)
2744 return _error
->Error(_("%s dependency for %s cannot be satisfied "
2745 "because no available versions of package %s "
2746 "can satisfy version requirements"),
2747 Last
->BuildDepType((*D
).Type
),Src
.c_str(),
2748 (*D
).Package
.c_str());
2754 // Only consider virtual packages if there is no versioned dependency
2755 if (Prv
.end() == false)
2757 if (_config
->FindB("Debug::BuildDeps",false) == true)
2758 cout
<< " Is provided by installed package " << Prv
.OwnerPkg().FullName() << endl
;
2759 skipAlternatives
= hasAlternatives
;
2764 if (IV
.end() == false)
2766 if (_config
->FindB("Debug::BuildDeps",false) == true)
2767 cout
<< " Is installed\n";
2769 if (Cache
->VS().CheckDep(IV
.VerStr(),(*D
).Op
,(*D
).Version
.c_str()) == true)
2771 skipAlternatives
= hasAlternatives
;
2775 if (_config
->FindB("Debug::BuildDeps",false) == true)
2776 cout
<< " ...but the installed version doesn't meet the version requirement\n";
2778 if (((*D
).Op
& pkgCache::Dep::LessEq
) == pkgCache::Dep::LessEq
)
2780 return _error
->Error(_("Failed to satisfy %s dependency for %s: Installed package %s is too new"),
2781 Last
->BuildDepType((*D
).Type
),
2783 Pkg
.FullName(true).c_str());
2788 if (_config
->FindB("Debug::BuildDeps",false) == true)
2789 cout
<< " Trying to install " << (*D
).Package
<< endl
;
2791 if (TryToInstallBuildDep(Pkg
,Cache
,Fix
,false,false) == true)
2793 // We successfully installed something; skip remaining alternatives
2794 skipAlternatives
= hasAlternatives
;
2795 if(_config
->FindB("APT::Get::Build-Dep-Automatic", false) == true)
2796 Cache
->MarkAuto(Pkg
, true);
2799 else if (hasAlternatives
)
2801 if (_config
->FindB("Debug::BuildDeps",false) == true)
2802 cout
<< " Unsatisfiable, trying alternatives\n";
2807 return _error
->Error(_("Failed to satisfy %s dependency for %s: %s"),
2808 Last
->BuildDepType((*D
).Type
),
2810 (*D
).Package
.c_str());
2815 Fix
.InstallProtect();
2816 if (Fix
.Resolve(true) == false)
2819 // Now we check the state of the packages,
2820 if (Cache
->BrokenCount() != 0)
2822 ShowBroken(cout
, Cache
, false);
2823 return _error
->Error(_("Build-dependencies for %s could not be satisfied."),*I
);
2827 if (InstallPackages(Cache
, false, true) == false)
2828 return _error
->Error(_("Failed to process build dependencies"));
2832 // GetChangelogPath - return a path pointing to a changelog file or dir /*{{{*/
2833 // ---------------------------------------------------------------------
2834 /* This returns a "path" string for the changelog url construction.
2835 * Please note that its not complete, it either needs a "/changelog"
2836 * appended (for the packages.debian.org/changelogs site) or a
2837 * ".changelog" (for third party sites that store the changelog in the
2838 * pool/ next to the deb itself)
2839 * Example return: "pool/main/a/apt/apt_0.8.8ubuntu3"
2841 string
GetChangelogPath(CacheFile
&Cache
,
2842 pkgCache::PkgIterator Pkg
,
2843 pkgCache::VerIterator Ver
)
2847 pkgRecords
Recs(Cache
);
2848 pkgRecords::Parser
&rec
=Recs
.Lookup(Ver
.FileList());
2849 string srcpkg
= rec
.SourcePkg().empty() ? Pkg
.Name() : rec
.SourcePkg();
2850 string ver
= Ver
.VerStr();
2851 // if there is a source version it always wins
2852 if (rec
.SourceVer() != "")
2853 ver
= rec
.SourceVer();
2854 path
= flNotFile(rec
.FileName());
2855 path
+= srcpkg
+ "_" + StripEpoch(ver
);
2859 // GuessThirdPartyChangelogUri - return url /*{{{*/
2860 // ---------------------------------------------------------------------
2861 /* Contruct a changelog file path for third party sites that do not use
2862 * packages.debian.org/changelogs
2863 * This simply uses the ArchiveURI() of the source pkg and looks for
2864 * a .changelog file there, Example for "mediabuntu":
2865 * apt-get changelog mplayer-doc:
2866 * http://packages.medibuntu.org/pool/non-free/m/mplayer/mplayer_1.0~rc4~try1.dsfg1-1ubuntu1+medibuntu1.changelog
2868 bool GuessThirdPartyChangelogUri(CacheFile
&Cache
,
2869 pkgCache::PkgIterator Pkg
,
2870 pkgCache::VerIterator Ver
,
2873 // get the binary deb server path
2874 pkgCache::VerFileIterator Vf
= Ver
.FileList();
2875 if (Vf
.end() == true)
2877 pkgCache::PkgFileIterator F
= Vf
.File();
2878 pkgIndexFile
*index
;
2879 pkgSourceList
*SrcList
= Cache
.GetSourceList();
2880 if(SrcList
->FindIndex(F
, index
) == false)
2883 // get archive uri for the binary deb
2884 string path_without_dot_changelog
= GetChangelogPath(Cache
, Pkg
, Ver
);
2885 out_uri
= index
->ArchiveURI(path_without_dot_changelog
+ ".changelog");
2887 // now strip away the filename and add srcpkg_srcver.changelog
2891 // DownloadChangelog - Download the changelog /*{{{*/
2892 // ---------------------------------------------------------------------
2893 bool DownloadChangelog(CacheFile
&CacheFile
, pkgAcquire
&Fetcher
,
2894 pkgCache::VerIterator Ver
, string targetfile
)
2895 /* Download a changelog file for the given package version to
2896 * targetfile. This will first try the server from Apt::Changelogs::Server
2897 * (http://packages.debian.org/changelogs by default) and if that gives
2898 * a 404 tries to get it from the archive directly (see
2899 * GuessThirdPartyChangelogUri for details how)
2905 string changelog_uri
;
2907 // data structures we need
2908 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
2910 // make the server root configurable
2911 server
= _config
->Find("Apt::Changelogs::Server",
2912 "http://packages.debian.org/changelogs");
2913 path
= GetChangelogPath(CacheFile
, Pkg
, Ver
);
2914 strprintf(changelog_uri
, "%s/%s/changelog", server
.c_str(), path
.c_str());
2915 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
2917 std::cout
<< '\'' << changelog_uri
<< '\'' << std::endl
;
2921 strprintf(descr
, _("Changelog for %s (%s)"), Pkg
.Name(), changelog_uri
.c_str());
2923 new pkgAcqFile(&Fetcher
, changelog_uri
, "", 0, descr
, Pkg
.Name(), "ignored", targetfile
);
2925 // try downloading it, if that fails, try third-party-changelogs location
2926 // FIXME: Fetcher.Run() is "Continue" even if I get a 404?!?
2928 if (!FileExists(targetfile
))
2930 string third_party_uri
;
2931 if (GuessThirdPartyChangelogUri(CacheFile
, Pkg
, Ver
, third_party_uri
))
2933 strprintf(descr
, _("Changelog for %s (%s)"), Pkg
.Name(), third_party_uri
.c_str());
2934 new pkgAcqFile(&Fetcher
, third_party_uri
, "", 0, descr
, Pkg
.Name(), "ignored", targetfile
);
2939 if (FileExists(targetfile
))
2943 return _error
->Error("changelog download failed");
2946 // DisplayFileInPager - Display File with pager /*{{{*/
2947 void DisplayFileInPager(string filename
)
2949 pid_t Process
= ExecFork();
2952 const char *Args
[3];
2953 Args
[0] = "/usr/bin/sensible-pager";
2954 Args
[1] = filename
.c_str();
2956 execvp(Args
[0],(char **)Args
);
2960 // Wait for the subprocess
2961 ExecWait(Process
, "sensible-pager", false);
2964 // DoChangelog - Get changelog from the command line /*{{{*/
2965 // ---------------------------------------------------------------------
2966 bool DoChangelog(CommandLine
&CmdL
)
2969 if (Cache
.ReadOnlyOpen() == false)
2972 APT::CacheSetHelper
helper(c0out
);
2973 APT::VersionSet verset
= APT::VersionSet::FromCommandLine(Cache
,
2974 CmdL
.FileList
+ 1, APT::VersionSet::CANDIDATE
, helper
);
2975 if (verset
.empty() == true)
2979 if (_config
->FindB("APT::Get::Print-URIs", false) == true)
2980 for (APT::VersionSet::const_iterator Ver
= verset
.begin();
2981 Ver
!= verset
.end(); ++Ver
)
2982 return DownloadChangelog(Cache
, Fetcher
, Ver
, "");
2984 AcqTextStatus
Stat(ScreenWidth
, _config
->FindI("quiet",0));
2985 Fetcher
.Setup(&Stat
);
2987 bool const downOnly
= _config
->FindB("APT::Get::Download-Only", false);
2990 char* tmpdir
= NULL
;
2991 if (downOnly
== false)
2993 const char* const tmpDir
= getenv("TMPDIR");
2994 if (tmpDir
!= NULL
&& *tmpDir
!= '\0')
2995 snprintf(tmpname
, sizeof(tmpname
), "%s/apt-changelog-XXXXXX", tmpDir
);
2997 strncpy(tmpname
, "/tmp/apt-changelog-XXXXXX", sizeof(tmpname
));
2998 tmpdir
= mkdtemp(tmpname
);
3000 return _error
->Errno("mkdtemp", "mkdtemp failed");
3003 for (APT::VersionSet::const_iterator Ver
= verset
.begin();
3004 Ver
!= verset
.end();
3007 string changelogfile
;
3008 if (downOnly
== false)
3009 changelogfile
.append(tmpname
).append("changelog");
3011 changelogfile
.append(Ver
.ParentPkg().Name()).append(".changelog");
3012 if (DownloadChangelog(Cache
, Fetcher
, Ver
, changelogfile
) && downOnly
== false)
3014 DisplayFileInPager(changelogfile
);
3015 // cleanup temp file
3016 unlink(changelogfile
.c_str());
3025 // DoMoo - Never Ask, Never Tell /*{{{*/
3026 // ---------------------------------------------------------------------
3028 bool DoMoo(CommandLine
&CmdL
)
3037 "....\"Have you mooed today?\"...\n";
3042 // ShowHelp - Show a help screen /*{{{*/
3043 // ---------------------------------------------------------------------
3045 bool ShowHelp(CommandLine
&CmdL
)
3047 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,VERSION
,
3048 COMMON_ARCH
,__DATE__
,__TIME__
);
3050 if (_config
->FindB("version") == true)
3052 cout
<< _("Supported modules:") << endl
;
3054 for (unsigned I
= 0; I
!= pkgVersioningSystem::GlobalListLen
; I
++)
3056 pkgVersioningSystem
*VS
= pkgVersioningSystem::GlobalList
[I
];
3057 if (_system
!= 0 && _system
->VS
== VS
)
3061 cout
<< "Ver: " << VS
->Label
<< endl
;
3063 /* Print out all the packaging systems that will work with
3065 for (unsigned J
= 0; J
!= pkgSystem::GlobalListLen
; J
++)
3067 pkgSystem
*Sys
= pkgSystem::GlobalList
[J
];
3072 if (Sys
->VS
->TestCompatibility(*VS
) == true)
3073 cout
<< "Pkg: " << Sys
->Label
<< " (Priority " << Sys
->Score(*_config
) << ")" << endl
;
3077 for (unsigned I
= 0; I
!= pkgSourceList::Type::GlobalListLen
; I
++)
3079 pkgSourceList::Type
*Type
= pkgSourceList::Type::GlobalList
[I
];
3080 cout
<< " S.L: '" << Type
->Name
<< "' " << Type
->Label
<< endl
;
3083 for (unsigned I
= 0; I
!= pkgIndexFile::Type::GlobalListLen
; I
++)
3085 pkgIndexFile::Type
*Type
= pkgIndexFile::Type::GlobalList
[I
];
3086 cout
<< " Idx: " << Type
->Label
<< endl
;
3093 _("Usage: apt-get [options] command\n"
3094 " apt-get [options] install|remove pkg1 [pkg2 ...]\n"
3095 " apt-get [options] source pkg1 [pkg2 ...]\n"
3097 "apt-get is a simple command line interface for downloading and\n"
3098 "installing packages. The most frequently used commands are update\n"
3102 " update - Retrieve new lists of packages\n"
3103 " upgrade - Perform an upgrade\n"
3104 " install - Install new packages (pkg is libc6 not libc6.deb)\n"
3105 " remove - Remove packages\n"
3106 " autoremove - Remove automatically all unused packages\n"
3107 " purge - Remove packages and config files\n"
3108 " source - Download source archives\n"
3109 " build-dep - Configure build-dependencies for source packages\n"
3110 " dist-upgrade - Distribution upgrade, see apt-get(8)\n"
3111 " dselect-upgrade - Follow dselect selections\n"
3112 " clean - Erase downloaded archive files\n"
3113 " autoclean - Erase old downloaded archive files\n"
3114 " check - Verify that there are no broken dependencies\n"
3115 " markauto - Mark the given packages as automatically installed\n"
3116 " unmarkauto - Mark the given packages as manually installed\n"
3117 " changelog - Download and display the changelog for the given package\n"
3118 " download - Download the binary package into the current directory\n"
3121 " -h This help text.\n"
3122 " -q Loggable output - no progress indicator\n"
3123 " -qq No output except for errors\n"
3124 " -d Download only - do NOT install or unpack archives\n"
3125 " -s No-act. Perform ordering simulation\n"
3126 " -y Assume Yes to all queries and do not prompt\n"
3127 " -f Attempt to correct a system with broken dependencies in place\n"
3128 " -m Attempt to continue if archives are unlocatable\n"
3129 " -u Show a list of upgraded packages as well\n"
3130 " -b Build the source package after fetching it\n"
3131 " -V Show verbose version numbers\n"
3132 " -c=? Read this configuration file\n"
3133 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
3134 "See the apt-get(8), sources.list(5) and apt.conf(5) manual\n"
3135 "pages for more information and options.\n"
3136 " This APT has Super Cow Powers.\n");
3140 // SigWinch - Window size change signal handler /*{{{*/
3141 // ---------------------------------------------------------------------
3145 // Riped from GNU ls
3149 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
3150 ScreenWidth
= ws
.ws_col
- 1;
3154 int main(int argc
,const char *argv
[]) /*{{{*/
3156 CommandLine::Args Args
[] = {
3157 {'h',"help","help",0},
3158 {'v',"version","version",0},
3159 {'V',"verbose-versions","APT::Get::Show-Versions",0},
3160 {'q',"quiet","quiet",CommandLine::IntLevel
},
3161 {'q',"silent","quiet",CommandLine::IntLevel
},
3162 {'d',"download-only","APT::Get::Download-Only",0},
3163 {'b',"compile","APT::Get::Compile",0},
3164 {'b',"build","APT::Get::Compile",0},
3165 {'s',"simulate","APT::Get::Simulate",0},
3166 {'s',"just-print","APT::Get::Simulate",0},
3167 {'s',"recon","APT::Get::Simulate",0},
3168 {'s',"dry-run","APT::Get::Simulate",0},
3169 {'s',"no-act","APT::Get::Simulate",0},
3170 {'y',"yes","APT::Get::Assume-Yes",0},
3171 {'y',"assume-yes","APT::Get::Assume-Yes",0},
3172 {'f',"fix-broken","APT::Get::Fix-Broken",0},
3173 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
3174 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
3175 {'t',"target-release","APT::Default-Release",CommandLine::HasArg
},
3176 {'t',"default-release","APT::Default-Release",CommandLine::HasArg
},
3177 {0,"download","APT::Get::Download",0},
3178 {0,"fix-missing","APT::Get::Fix-Missing",0},
3179 {0,"ignore-hold","APT::Ignore-Hold",0},
3180 {0,"upgrade","APT::Get::upgrade",0},
3181 {0,"only-upgrade","APT::Get::Only-Upgrade",0},
3182 {0,"force-yes","APT::Get::force-yes",0},
3183 {0,"print-uris","APT::Get::Print-URIs",0},
3184 {0,"diff-only","APT::Get::Diff-Only",0},
3185 {0,"debian-only","APT::Get::Diff-Only",0},
3186 {0,"tar-only","APT::Get::Tar-Only",0},
3187 {0,"dsc-only","APT::Get::Dsc-Only",0},
3188 {0,"purge","APT::Get::Purge",0},
3189 {0,"list-cleanup","APT::Get::List-Cleanup",0},
3190 {0,"reinstall","APT::Get::ReInstall",0},
3191 {0,"trivial-only","APT::Get::Trivial-Only",0},
3192 {0,"remove","APT::Get::Remove",0},
3193 {0,"only-source","APT::Get::Only-Source",0},
3194 {0,"arch-only","APT::Get::Arch-Only",0},
3195 {0,"auto-remove","APT::Get::AutomaticRemove",0},
3196 {0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0},
3197 {0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean
},
3198 {0,"fix-policy","APT::Get::Fix-Policy-Broken",0},
3199 {'c',"config-file",0,CommandLine::ConfigFile
},
3200 {'o',"option",0,CommandLine::ArbItem
},
3202 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
3203 {"upgrade",&DoUpgrade
},
3204 {"install",&DoInstall
},
3205 {"remove",&DoInstall
},
3206 {"purge",&DoInstall
},
3207 {"autoremove",&DoInstall
},
3208 {"markauto",&DoMarkAuto
},
3209 {"unmarkauto",&DoMarkAuto
},
3210 {"dist-upgrade",&DoDistUpgrade
},
3211 {"dselect-upgrade",&DoDSelectUpgrade
},
3212 {"build-dep",&DoBuildDep
},
3214 {"autoclean",&DoAutoClean
},
3216 {"source",&DoSource
},
3217 {"download",&DoDownload
},
3218 {"changelog",&DoChangelog
},
3223 // Set up gettext support
3224 setlocale(LC_ALL
,"");
3225 textdomain(PACKAGE
);
3227 // Parse the command line and initialize the package library
3228 CommandLine
CmdL(Args
,_config
);
3229 if (pkgInitConfig(*_config
) == false ||
3230 CmdL
.Parse(argc
,argv
) == false ||
3231 pkgInitSystem(*_config
,_system
) == false)
3233 if (_config
->FindB("version") == true)
3236 _error
->DumpErrors();
3240 // See if the help should be shown
3241 if (_config
->FindB("help") == true ||
3242 _config
->FindB("version") == true ||
3243 CmdL
.FileSize() == 0)
3249 // simulate user-friendly if apt-get has no root privileges
3250 if (getuid() != 0 && _config
->FindB("APT::Get::Simulate") == true)
3252 if (_config
->FindB("APT::Get::Show-User-Simulation-Note",true) == true)
3253 cout
<< _("NOTE: This is only a simulation!\n"
3254 " apt-get needs root privileges for real execution.\n"
3255 " Keep also in mind that locking is deactivated,\n"
3256 " so don't depend on the relevance to the real current situation!"
3258 _config
->Set("Debug::NoLocking",true);
3261 // Deal with stdout not being a tty
3262 if (!isatty(STDOUT_FILENO
) && _config
->FindI("quiet", -1) == -1)
3263 _config
->Set("quiet","1");
3265 // Setup the output streams
3266 c0out
.rdbuf(cout
.rdbuf());
3267 c1out
.rdbuf(cout
.rdbuf());
3268 c2out
.rdbuf(cout
.rdbuf());
3269 if (_config
->FindI("quiet",0) > 0)
3270 c0out
.rdbuf(devnull
.rdbuf());
3271 if (_config
->FindI("quiet",0) > 1)
3272 c1out
.rdbuf(devnull
.rdbuf());
3274 // Setup the signals
3275 signal(SIGPIPE
,SIG_IGN
);
3276 signal(SIGWINCH
,SigWinch
);
3279 // Match the operation
3280 CmdL
.DispatchArg(Cmds
);
3282 // Print any errors or warnings found during parsing
3283 bool const Errors
= _error
->PendingError();
3284 if (_config
->FindI("quiet",0) > 0)
3285 _error
->DumpErrors();
3287 _error
->DumpErrors(GlobalError::DEBUG
);
3288 return Errors
== true ? 100 : 0;