summaryrefslogtreecommitdiff
path: root/cmdline
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2015-08-18 11:57:35 +0200
committerMichael Vogt <mvo@debian.org>2015-08-18 11:57:35 +0200
commitb53c9cea2902572822bbbece5bac236c1bbf846e (patch)
tree6c6b0524e0971c0623ccbff71383523ee0b2a5cc /cmdline
parent21248c0f00ee71412dbadc6ebf84011cf974346d (diff)
parent2a22cd60f04c4291ea9b9b72e15b6d2ec378b001 (diff)
Merge remote-tracking branch 'upstream/debian/experimental' into feature/srv-records
Diffstat (limited to 'cmdline')
-rw-r--r--cmdline/apt-cache.cc111
-rw-r--r--cmdline/apt-cdrom.cc10
-rw-r--r--cmdline/apt-extracttemplates.h6
-rw-r--r--cmdline/apt-get.cc407
-rw-r--r--cmdline/apt-internal-solver.cc1
-rw-r--r--cmdline/apt-key.in218
-rw-r--r--cmdline/apt-mark.cc2
-rw-r--r--cmdline/apt.cc3
8 files changed, 421 insertions, 337 deletions
diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc
index 690b03bcc..f7abb823d 100644
--- a/cmdline/apt-cache.cc
+++ b/cmdline/apt-cache.cc
@@ -253,12 +253,12 @@ static bool DumpPackage(CommandLine &CmdL)
{
cout << Cur.VerStr() << " - ";
for (pkgCache::PrvIterator Prv = Cur.ProvidesList(); Prv.end() != true; ++Prv)
- cout << Prv.ParentPkg().FullName(true) << " ";
+ cout << Prv.ParentPkg().FullName(true) << " (= " << (Prv->ProvideVersion == 0 ? "" : Prv.ProvideVersion()) << ") ";
cout << endl;
}
cout << "Reverse Provides: " << endl;
for (pkgCache::PrvIterator Prv = Pkg.ProvidesList(); Prv.end() != true; ++Prv)
- cout << Prv.OwnerPkg().FullName(true) << " " << Prv.OwnerVer().VerStr() << endl;
+ cout << Prv.OwnerPkg().FullName(true) << " " << Prv.OwnerVer().VerStr() << " (= " << (Prv->ProvideVersion == 0 ? "" : Prv.ProvideVersion()) << ")"<< endl;
}
return true;
@@ -310,10 +310,15 @@ static void ShowHashTableStats(std::string Type,
// Stats - Dump some nice statistics /*{{{*/
// ---------------------------------------------------------------------
/* */
-static bool Stats(CommandLine &)
+static bool Stats(CommandLine &CmdL)
{
pkgCacheFile CacheFile;
pkgCache *Cache = CacheFile.GetPkgCache();
+
+ if (CmdL.FileSize() > 1) {
+ _error->Error(_("apt-cache stats does not take any arguments"));
+ return false;
+ }
if (unlikely(Cache == NULL))
return false;
@@ -364,14 +369,14 @@ static bool Stats(CommandLine &)
cout << _(" Single virtual packages: ") << DVirt << endl;
cout << _(" Mixed virtual packages: ") << NVirt << endl;
cout << _(" Missing: ") << Missing << endl;
-
+
cout << _("Total distinct versions: ") << Cache->Head().VersionCount << " (" <<
SizeToStr(Cache->Head().VersionCount*Cache->Head().VersionSz) << ')' << endl;
cout << _("Total distinct descriptions: ") << Cache->Head().DescriptionCount << " (" <<
SizeToStr(Cache->Head().DescriptionCount*Cache->Head().DescriptionSz) << ')' << endl;
- cout << _("Total dependencies: ") << Cache->Head().DependsCount << " (" <<
- SizeToStr(Cache->Head().DependsCount*Cache->Head().DependencySz) << ')' << endl;
-
+ cout << _("Total dependencies: ") << Cache->Head().DependsCount << "/" << Cache->Head().DependsDataCount << " (" <<
+ SizeToStr((Cache->Head().DependsCount*Cache->Head().DependencySz) +
+ (Cache->Head().DependsDataCount*Cache->Head().DependencyDataSz)) << ')' << endl;
cout << _("Total ver/file relations: ") << Cache->Head().VerFileCount << " (" <<
SizeToStr(Cache->Head().VerFileCount*Cache->Head().VerFileSz) << ')' << endl;
cout << _("Total Desc/File relations: ") << Cache->Head().DescFileCount << " (" <<
@@ -392,10 +397,8 @@ static bool Stats(CommandLine &)
stritems.insert(V->VerStr);
if (V->Section != 0)
stritems.insert(V->Section);
-#if APT_PKG_ABI >= 413
stritems.insert(V->SourcePkgName);
stritems.insert(V->SourceVerStr);
-#endif
for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; ++D)
{
if (D->Version != 0)
@@ -413,23 +416,27 @@ static bool Stats(CommandLine &)
stritems.insert(Prv->ProvideVersion);
}
}
- for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); ++F)
+ for (pkgCache::RlsFileIterator F = Cache->RlsFileBegin(); F != Cache->RlsFileEnd(); ++F)
{
stritems.insert(F->FileName);
stritems.insert(F->Archive);
stritems.insert(F->Codename);
- stritems.insert(F->Component);
stritems.insert(F->Version);
stritems.insert(F->Origin);
stritems.insert(F->Label);
- stritems.insert(F->Architecture);
stritems.insert(F->Site);
+ }
+ for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); ++F)
+ {
+ stritems.insert(F->FileName);
+ stritems.insert(F->Architecture);
+ stritems.insert(F->Component);
stritems.insert(F->IndexType);
}
+
unsigned long Size = 0;
for (std::set<map_stringitem_t>::const_iterator i = stritems.begin(); i != stritems.end(); ++i)
Size += strlen(Cache->StrP + *i) + 1;
-
cout << _("Total globbed strings: ") << stritems.size() << " (" << SizeToStr(Size) << ')' << endl;
stritems.clear();
@@ -446,6 +453,8 @@ static bool Stats(CommandLine &)
APT_CACHESIZE(VersionCount, VersionSz) +
APT_CACHESIZE(DescriptionCount, DescriptionSz) +
APT_CACHESIZE(DependsCount, DependencySz) +
+ APT_CACHESIZE(DependsDataCount, DependencyDataSz) +
+ APT_CACHESIZE(ReleaseFileCount, ReleaseFileSz) +
APT_CACHESIZE(PackageFileCount, PackageFileSz) +
APT_CACHESIZE(VerFileCount, VerFileSz) +
APT_CACHESIZE(DescFileCount, DescFileSz) +
@@ -685,6 +694,7 @@ static bool ShowDepends(CommandLine &CmdL, bool const RevDepends)
bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false);
bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false);
bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false);
+ bool const ShowImplicit = _config->FindB("APT::Cache::ShowImplicit", false);
while (verset.empty() != true)
{
@@ -705,12 +715,16 @@ static bool ShowDepends(CommandLine &CmdL, bool const RevDepends)
case pkgCache::Dep::Depends: if (!ShowDepends) continue; break;
case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break;
case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break;
- case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break; case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break;
+ case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break;
+ case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break;
case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break;
case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break;
}
+ if (ShowImplicit == false && D.IsImplicit())
+ continue;
pkgCache::PkgIterator Trg = RevDepends ? D.ParentPkg() : D.TargetPkg();
+ bool const showNoArch = RevDepends || (D->CompareOp & pkgCache::Dep::ArchSpecific) != pkgCache::Dep::ArchSpecific;
if((Installed && Trg->CurrentVer != 0) || !Installed)
{
@@ -724,9 +738,9 @@ static bool ShowDepends(CommandLine &CmdL, bool const RevDepends)
if (ShowDepType == true)
cout << D.DepType() << ": ";
if (Trg->VersionList == 0)
- cout << "<" << Trg.FullName(true) << ">";
+ cout << "<" << Trg.FullName(showNoArch) << ">";
else
- cout << Trg.FullName(true);
+ cout << Trg.FullName(showNoArch);
if (ShowVersion == true && D->Version != 0)
cout << " (" << pkgCache::CompTypeDeb(D->CompareOp) << ' ' << D.TargetVer() << ')';
cout << std::endl;
@@ -740,9 +754,9 @@ static bool ShowDepends(CommandLine &CmdL, bool const RevDepends)
}
// Display all solutions
- SPtrArray<pkgCache::Version *> List = D.AllTargets();
- pkgPrioSortList(*Cache,List);
- for (pkgCache::Version **I = List; *I != 0; I++)
+ std::unique_ptr<pkgCache::Version *[]> List(D.AllTargets());
+ pkgPrioSortList(*Cache,List.get());
+ for (pkgCache::Version **I = List.get(); *I != 0; I++)
{
pkgCache::VerIterator V(*Cache,*I);
if (V != Cache->VerP + V.ParentPkg()->VersionList ||
@@ -1318,6 +1332,7 @@ static bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V)
struct ExDescFile
{
pkgCache::DescFile *Df;
+ pkgCache::VerIterator V;
map_id_t ID;
};
@@ -1403,6 +1418,7 @@ static bool Search(CommandLine &CmdL)
if (D.end() == true)
continue;
DFList[G->ID].Df = D.FileList();
+ DFList[G->ID].V = V;
DFList[G->ID].ID = G->ID;
}
@@ -1422,11 +1438,12 @@ static bool Search(CommandLine &CmdL)
if (D.end() == true)
continue;
DFList[id].Df = D.FileList();
+ DFList[id].V = V;
DFList[id].ID = id;
size_t const PrvPatternOffset = id * NumPatterns;
for (unsigned I = 0; I < NumPatterns; ++I)
- PatternMatch[PrvPatternOffset + I] = PatternMatch[PatternOffset + I];
+ PatternMatch[PrvPatternOffset + I] |= PatternMatch[PatternOffset + I];
}
}
@@ -1463,13 +1480,7 @@ static bool Search(CommandLine &CmdL)
if (matchedAll == true)
{
if (ShowFull == true)
- {
- const char *Start;
- const char *End;
- P.GetRec(Start,End);
- fwrite(Start,End-Start,1,stdout);
- putc('\n',stdout);
- }
+ DisplayRecord(CacheFile, J->V);
else
printf("%s - %s\n",P.Name().c_str(),P.ShortDesc().c_str());
}
@@ -1479,6 +1490,7 @@ static bool Search(CommandLine &CmdL)
delete [] PatternMatch;
for (unsigned I = 0; I != NumPatterns; I++)
regfree(&Patterns[I]);
+ delete [] Patterns;
if (ferror(stdout))
return _error->Error("Write to stdout failed");
return true;
@@ -1633,6 +1645,8 @@ static bool Policy(CommandLine &CmdL)
cout << _("Package files:") << endl;
for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F.end() == false; ++F)
{
+ if (F.Flagged(pkgCache::Flag::NoPackages))
+ continue;
// Locate the associated index files so we can derive a description
pkgIndexFile *Indx;
if (SrcList->FindIndex(F,Indx) == false &&
@@ -1655,19 +1669,33 @@ static bool Policy(CommandLine &CmdL)
pkgCache::PkgIterator I = Cache->PkgBegin();
for (;I.end() != true; ++I)
{
- if (Plcy->GetPriority(I) == 0)
+ // Old code for debugging
+ if (_config->FindI("APT::Policy", 1) < 1) {
+ if (Plcy->GetPriority(I) == 0)
+ continue;
+
+ // Print the package name and the version we are forcing to
+ cout << " " << I.FullName(true) << " -> ";
+
+ pkgCache::VerIterator V = Plcy->GetMatch(I);
+ if (V.end() == true)
+ cout << _("(not found)") << endl;
+ else
+ cout << V.VerStr() << endl;
+
continue;
+ }
+ // New code
+ for (pkgCache::VerIterator V = I.VersionList(); !V.end(); V++) {
+ auto Prio = Plcy->GetPriority(V, false);
+ if (Prio == 0)
+ continue;
- // Print the package name and the version we are forcing to
- cout << " " << I.FullName(true) << " -> ";
-
- pkgCache::VerIterator V = Plcy->GetMatch(I);
- if (V.end() == true)
- cout << _("(not found)") << endl;
- else
- cout << V.VerStr() << endl;
- }
-
+ cout << " ";
+ // Print the package name and the version we are forcing to
+ ioprintf(cout, _("%s -> %s with priority %d\n"), I.FullName(true).c_str(), V.VerStr(), Prio);
+ }
+ }
return true;
}
@@ -1703,7 +1731,7 @@ static bool Policy(CommandLine &CmdL)
cout << V.VerStr() << endl;
// Pinned version
- if (Plcy->GetPriority(Pkg) != 0)
+ if (_config->FindI("APT::Policy", 1) < 1 && Plcy->GetPriority(Pkg) != 0)
{
cout << _(" Package pin: ");
V = Plcy->GetMatch(Pkg);
@@ -1721,7 +1749,10 @@ static bool Policy(CommandLine &CmdL)
cout << " *** " << V.VerStr();
else
cout << " " << V.VerStr();
- cout << " " << Plcy->GetPriority(Pkg) << endl;
+ if (_config->FindI("APT::Policy", 1) < 1)
+ cout << " " << Plcy->GetPriority(Pkg) << endl;
+ else
+ cout << " " << Plcy->GetPriority(V) << endl;
for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; ++VF)
{
// Locate the associated index files so we can derive a description
diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc
index d95c169cd..dcc784746 100644
--- a/cmdline/apt-cdrom.cc
+++ b/cmdline/apt-cdrom.cc
@@ -44,12 +44,12 @@ protected:
OpTextProgress Progress;
void Prompt(const char *Text);
string PromptLine(const char *Text);
- bool AskCdromName(string &name);
+ bool AskCdromName(string &name) APT_OVERRIDE;
public:
- virtual void Update(string text, int current);
- virtual bool ChangeCdrom();
- virtual OpProgress* GetOpProgress();
+ virtual void Update(string text, int current) APT_OVERRIDE;
+ virtual bool ChangeCdrom() APT_OVERRIDE;
+ virtual OpProgress* GetOpProgress() APT_OVERRIDE;
};
void pkgCdromTextStatus::Prompt(const char *Text)
@@ -89,7 +89,7 @@ void pkgCdromTextStatus::Update(string text, int /*current*/)
bool pkgCdromTextStatus::ChangeCdrom()
{
- Prompt(_("Please insert a Disc in the drive and press enter"));
+ Prompt(_("Please insert a Disc in the drive and press [Enter]"));
return true;
}
diff --git a/cmdline/apt-extracttemplates.h b/cmdline/apt-extracttemplates.h
index 829cdae75..91e385e70 100644
--- a/cmdline/apt-extracttemplates.h
+++ b/cmdline/apt-extracttemplates.h
@@ -24,11 +24,11 @@ class DebFile : public pkgDirStream
unsigned long ControlLen;
public:
- DebFile(const char *FileName);
+ explicit DebFile(const char *FileName);
~DebFile();
- bool DoItem(Item &I, int &fd);
+ bool DoItem(Item &I, int &fd) APT_OVERRIDE;
bool Process(pkgDirStream::Item &I, const unsigned char *data,
- unsigned long long size, unsigned long long pos);
+ unsigned long long size, unsigned long long pos) APT_OVERRIDE;
bool Go();
bool ParseInfo();
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc
index c1f78523c..acf6c2155 100644
--- a/cmdline/apt-get.cc
+++ b/cmdline/apt-get.cc
@@ -39,7 +39,6 @@
#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/indexfile.h>
-#include <apt-pkg/indexrecords.h>
#include <apt-pkg/init.h>
#include <apt-pkg/md5.h>
#include <apt-pkg/metaindex.h>
@@ -56,6 +55,7 @@
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/cacheiterators.h>
#include <apt-pkg/upgrade.h>
+#include <apt-pkg/sptr.h>
#include <apt-private/acqprogress.h>
#include <apt-private/private-cacheset.h>
@@ -86,6 +86,7 @@
#include <algorithm>
#include <fstream>
#include <iostream>
+#include <sstream>
#include <set>
#include <string>
#include <vector>
@@ -136,11 +137,9 @@ static bool TryToInstallBuildDep(pkgCache::PkgIterator Pkg,pkgCacheFile &Cache,
return true;
}
/*}}}*/
-// GetReleaseForSourceRecord - Return Suite for the given srcrecord /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static std::string GetReleaseForSourceRecord(pkgSourceList *SrcList,
- pkgSrcRecords::Parser *Parse)
+// GetReleaseFileForSourceRecord - Return Suite for the given srcrecord /*{{{*/
+static pkgCache::RlsFileIterator GetReleaseFileForSourceRecord(CacheFile &CacheFile,
+ pkgSourceList *SrcList, pkgSrcRecords::Parser *Parse)
{
// try to find release
const pkgIndexFile& CurrentIndexFile = Parse->Index();
@@ -153,28 +152,16 @@ static std::string GetReleaseForSourceRecord(pkgSourceList *SrcList,
IF != Indexes->end(); ++IF)
{
if (&CurrentIndexFile == (*IF))
- {
- std::string const path = (*S)->LocalFileName();
- if (path != "")
- {
- indexRecords records;
- records.Load(path);
- return records.GetSuite();
- }
- }
+ return (*S)->FindInCache(CacheFile, false);
}
}
- return "";
+ return pkgCache::RlsFileIterator(CacheFile);
}
/*}}}*/
// FindSrc - Find a source record /*{{{*/
// ---------------------------------------------------------------------
/* */
-#if APT_PKG_ABI >= 413
static pkgSrcRecords::Parser *FindSrc(const char *Name,
-#else
-static pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
-#endif
pkgSrcRecords &SrcRecs,string &Src,
CacheFile &CacheFile)
{
@@ -284,19 +271,8 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
{
// the Version we have is possibly fuzzy or includes binUploads,
// so we use the Version of the SourcePkg (empty if same as package)
-#if APT_PKG_ABI >= 413
Src = Ver.SourcePkgName();
VerTag = Ver.SourceVerStr();
-#else
- pkgRecords::Parser &Parse = Recs.Lookup(VF);
- Src = Parse.SourcePkg();
- // no SourcePkg name, so it is the "binary" name
- if (Src.empty() == true)
- Src = TmpSrc;
- VerTag = Parse.SourceVer();
- if (VerTag.empty() == true)
- VerTag = Ver.VerStr();
-#endif
break;
}
}
@@ -327,17 +303,10 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
pkgCache::VerIterator Ver = Cache->GetCandidateVer(Pkg);
if (Ver.end() == false)
{
-#if APT_PKG_ABI >= 413
if (strcmp(Ver.SourcePkgName(),Ver.ParentPkg().Name()) != 0)
Src = Ver.SourcePkgName();
if (VerTag.empty() == true && strcmp(Ver.SourceVerStr(),Ver.VerStr()) != 0)
VerTag = Ver.SourceVerStr();
-#else
- pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
- Src = Parse.SourcePkg();
- if (VerTag.empty() == true)
- VerTag = Parse.SourceVer();
-#endif
}
}
}
@@ -378,13 +347,16 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
// See if we need to look for a specific release tag
if (RelTag != "" && UserRequestedVerTag == "")
{
- const string Rel = GetReleaseForSourceRecord(SrcList, Parse);
-
- if (Rel == RelTag)
+ pkgCache::RlsFileIterator const Rls = GetReleaseFileForSourceRecord(CacheFile, SrcList, Parse);
+ if (Rls.end() == false)
{
- Last = Parse;
- Offset = Parse->Offset();
- Version = Ver;
+ if ((Rls->Archive != 0 && RelTag == Rls.Archive()) ||
+ (Rls->Codename != 0 && RelTag == Rls.Codename()))
+ {
+ Last = Parse;
+ Offset = Parse->Offset();
+ Version = Ver;
+ }
}
}
@@ -578,7 +550,7 @@ static bool DoClean(CommandLine &)
class LogCleaner : public pkgArchiveCleaner
{
protected:
- virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St)
+ virtual void Erase(const char *File,string Pkg,string Ver,struct stat &St) APT_OVERRIDE
{
c1out << "Del " << Pkg << " " << Ver << " [" << SizeToStr(St.st_size) << "B]" << endl;
@@ -721,9 +693,6 @@ static bool DoSource(CommandLine &CmdL)
pkgSourceList *List = Cache.GetSourceList();
// Create the text record parsers
-#if APT_PKG_ABI < 413
- pkgRecords Recs(Cache);
-#endif
pkgSrcRecords SrcRecs(*List);
if (_error->PendingError() == true)
return false;
@@ -732,7 +701,7 @@ static bool DoSource(CommandLine &CmdL)
AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
pkgAcquire Fetcher(&Stat);
- SPtrArray<DscFile> Dsc = new DscFile[CmdL.FileSize()];
+ std::unique_ptr<DscFile[]> Dsc(new DscFile[CmdL.FileSize()]);
// insert all downloaded uris into this set to avoid downloading them
// twice
@@ -747,22 +716,18 @@ static bool DoSource(CommandLine &CmdL)
// Load the requestd sources into the fetcher
unsigned J = 0;
- std::string UntrustedList;
+ std::vector<std::string> UntrustedList;
for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
{
string Src;
-#if APT_PKG_ABI >= 413
pkgSrcRecords::Parser *Last = FindSrc(*I,SrcRecs,Src,Cache);
-#else
- pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
-#endif
if (Last == 0) {
return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
}
if (Last->Index().IsTrusted() == false)
- UntrustedList += Src + " ";
-
+ UntrustedList.push_back(Src);
+
string srec = Last->AsStr();
string::size_type pos = srec.find("\nVcs-");
while (pos != string::npos)
@@ -889,7 +854,7 @@ static bool DoSource(CommandLine &CmdL)
CheckDropPrivsMustBeDisabled(Fetcher);
// check authentication status of the source as well
- if (UntrustedList != "" && !AuthPrompt(UntrustedList, false))
+ if (UntrustedList.empty() == false && AuthPrompt(UntrustedList, false) == false)
return false;
// Run it
@@ -1001,8 +966,10 @@ static bool DoBuildDep(CommandLine &CmdL)
CacheFile Cache;
_config->Set("APT::Install-Recommends", false);
+
+ bool WantLock = _config->FindB("APT::Get::Print-URIs", false) == false;
- if (Cache.Open(true) == false)
+ if (Cache.Open(WantLock) == false)
return false;
if (CmdL.FileSize() <= 1)
@@ -1014,9 +981,6 @@ static bool DoBuildDep(CommandLine &CmdL)
pkgSourceList *List = Cache.GetSourceList();
// Create the text record parsers
-#if APT_PKG_ABI < 413
- pkgRecords Recs(Cache);
-#endif
pkgSrcRecords SrcRecs(*List);
if (_error->PendingError() == true)
return false;
@@ -1038,6 +1002,7 @@ static bool DoBuildDep(CommandLine &CmdL)
{
string Src;
pkgSrcRecords::Parser *Last = 0;
+ std::unique_ptr<pkgSrcRecords::Parser> LastOwner;
// an unpacked debian source tree
using APT::String::Startswith;
@@ -1046,10 +1011,10 @@ static bool DoBuildDep(CommandLine &CmdL)
{
ioprintf(c1out, _("Note, using directory '%s' to get the build dependencies\n"), *I);
// FIXME: how can we make this more elegant?
- std::string TypeName = "debian/control File Source Index";
+ std::string TypeName = "Debian control file";
pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
if(Type != NULL)
- Last = Type->CreateSrcPkgParser(*I);
+ LastOwner.reset(Last = Type->CreateSrcPkgParser(*I));
}
// if its a local file (e.g. .dsc) use this
else if (FileExists(*I))
@@ -1057,17 +1022,13 @@ static bool DoBuildDep(CommandLine &CmdL)
ioprintf(c1out, _("Note, using file '%s' to get the build dependencies\n"), *I);
// see if we can get a parser for this pkgIndexFile type
- string TypeName = flExtension(*I) + " File Source Index";
+ string TypeName = "Debian " + flExtension(*I) + " file";
pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
if(Type != NULL)
- Last = Type->CreateSrcPkgParser(*I);
+ LastOwner.reset(Last = Type->CreateSrcPkgParser(*I));
} else {
// normal case, search the cache for the source file
-#if APT_PKG_ABI >= 413
Last = FindSrc(*I,SrcRecs,Src,Cache);
-#else
- Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
-#endif
}
if (Last == 0)
@@ -1212,12 +1173,12 @@ static bool DoBuildDep(CommandLine &CmdL)
for (; Ver != verlist.end(); ++Ver)
{
forbidden.clear();
- if (Ver->MultiArch == pkgCache::Version::None || Ver->MultiArch == pkgCache::Version::All)
+ if (Ver->MultiArch == pkgCache::Version::No || Ver->MultiArch == pkgCache::Version::All)
{
if (colon == string::npos)
Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
- forbidden = "Multi-Arch: none";
+ forbidden = "Multi-Arch: no";
else if (strcmp(D->Package.c_str() + colon, ":native") == 0)
Pkg = Ver.ParentPkg().Group().FindPkg("native");
}
@@ -1409,196 +1370,175 @@ static bool DoBuildDep(CommandLine &CmdL)
return true;
}
/*}}}*/
-// GetChangelogPath - return a path pointing to a changelog file or dir /*{{{*/
-// ---------------------------------------------------------------------
-/* This returns a "path" string for the changelog url construction.
- * Please note that its not complete, it either needs a "/changelog"
- * appended (for the packages.debian.org/changelogs site) or a
- * ".changelog" (for third party sites that store the changelog in the
- * pool/ next to the deb itself)
- * Example return: "pool/main/a/apt/apt_0.8.8ubuntu3"
- */
-static string GetChangelogPath(CacheFile &Cache,
- pkgCache::VerIterator Ver)
-{
- pkgRecords Recs(Cache);
- pkgRecords::Parser &rec=Recs.Lookup(Ver.FileList());
- string path = flNotFile(rec.FileName());
-#if APT_PKG_ABI >= 413
- path.append(Ver.SourcePkgName());
- path.append("_");
- path.append(StripEpoch(Ver.SourceVerStr()));
-#else
- string srcpkg = rec.SourcePkg().empty() ? Ver.ParentPkg().Name() : rec.SourcePkg();
- string ver = Ver.VerStr();
- // if there is a source version it always wins
- if (rec.SourceVer() != "")
- ver = rec.SourceVer();
- path += srcpkg + "_" + StripEpoch(ver);
-#endif
- return path;
-}
- /*}}}*/
-// GuessThirdPartyChangelogUri - return url /*{{{*/
-// ---------------------------------------------------------------------
-/* Contruct a changelog file path for third party sites that do not use
- * packages.debian.org/changelogs
- * This simply uses the ArchiveURI() of the source pkg and looks for
- * a .changelog file there, Example for "mediabuntu":
- * apt-get changelog mplayer-doc:
- * http://packages.medibuntu.org/pool/non-free/m/mplayer/mplayer_1.0~rc4~try1.dsfg1-1ubuntu1+medibuntu1.changelog
- */
-static bool GuessThirdPartyChangelogUri(CacheFile &Cache,
- pkgCache::VerIterator Ver,
- string &out_uri)
-{
- // get the binary deb server path
- pkgCache::VerFileIterator Vf = Ver.FileList();
- if (Vf.end() == true)
- return false;
- pkgCache::PkgFileIterator F = Vf.File();
- pkgIndexFile *index;
- pkgSourceList *SrcList = Cache.GetSourceList();
- if(SrcList->FindIndex(F, index) == false)
- return false;
-
- // get archive uri for the binary deb
- string path_without_dot_changelog = GetChangelogPath(Cache, Ver);
- out_uri = index->ArchiveURI(path_without_dot_changelog + ".changelog");
-
- // now strip away the filename and add srcpkg_srcver.changelog
- return true;
-}
- /*}}}*/
-// DownloadChangelog - Download the changelog /*{{{*/
-// ---------------------------------------------------------------------
-static bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher,
- pkgCache::VerIterator Ver, string targetfile)
-/* Download a changelog file for the given package version to
- * targetfile. This will first try the server from Apt::Changelogs::Server
- * (http://packages.debian.org/changelogs by default) and if that gives
- * a 404 tries to get it from the archive directly (see
- * GuessThirdPartyChangelogUri for details how)
- */
-{
- // make the server root configurable
- string const server = _config->Find("Apt::Changelogs::Server",
- "http://packages.debian.org/changelogs");
- string const path = GetChangelogPath(CacheFile, Ver);
- string changelog_uri;
- if (APT::String::Endswith(server, "/") == true)
- strprintf(changelog_uri, "%s%s/changelog", server.c_str(), path.c_str());
- else
- strprintf(changelog_uri, "%s/%s/changelog", server.c_str(), path.c_str());
- if (_config->FindB("APT::Get::Print-URIs", false) == true)
- {
- std::cout << '\'' << changelog_uri << '\'' << std::endl;
- return true;
- }
- pkgCache::PkgIterator const Pkg = Ver.ParentPkg();
-
- string descr;
- strprintf(descr, _("Changelog for %s (%s)"), Pkg.Name(), changelog_uri.c_str());
- // queue it
- pkgAcquire::Item const * itm = new pkgAcqFile(&Fetcher, changelog_uri, "", 0, descr, Pkg.Name(), "ignored", targetfile);
-
- // Disable drop-privs if "_apt" can not write to the target dir
- CheckDropPrivsMustBeDisabled(Fetcher);
-
- // try downloading it, if that fails, try third-party-changelogs location
- // FIXME: Fetcher.Run() is "Continue" even if I get a 404?!?
- Fetcher.Run();
- if (itm->Status != pkgAcquire::Item::StatDone)
- {
- string third_party_uri;
- if (GuessThirdPartyChangelogUri(CacheFile, Ver, third_party_uri))
- {
- strprintf(descr, _("Changelog for %s (%s)"), Pkg.Name(), third_party_uri.c_str());
- itm = new pkgAcqFile(&Fetcher, third_party_uri, "", 0, descr, Pkg.Name(), "ignored", targetfile);
- Fetcher.Run();
- }
- }
-
- if (itm->Status == pkgAcquire::Item::StatDone)
- return true;
-
- // error
- return _error->Error("changelog download failed");
-}
- /*}}}*/
// DoChangelog - Get changelog from the command line /*{{{*/
-// ---------------------------------------------------------------------
static bool DoChangelog(CommandLine &CmdL)
{
CacheFile Cache;
if (Cache.ReadOnlyOpen() == false)
return false;
-
+
APT::CacheSetHelper helper;
APT::VersionList verset = APT::VersionList::FromCommandLine(Cache,
CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper);
if (verset.empty() == true)
return false;
pkgAcquire Fetcher;
+ AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
+ Fetcher.SetLog(&Stat);
- if (_config->FindB("APT::Get::Print-URIs", false) == true)
+ bool const downOnly = _config->FindB("APT::Get::Download-Only", false);
+ bool const printOnly = _config->FindB("APT::Get::Print-URIs", false);
+
+ for (APT::VersionList::const_iterator Ver = verset.begin();
+ Ver != verset.end();
+ ++Ver)
{
- bool Success = true;
- for (APT::VersionList::const_iterator Ver = verset.begin();
- Ver != verset.end(); ++Ver)
- Success &= DownloadChangelog(Cache, Fetcher, Ver, "");
- return Success;
+ if (printOnly)
+ new pkgAcqChangelog(&Fetcher, Ver, "/dev/null");
+ else if (downOnly)
+ new pkgAcqChangelog(&Fetcher, Ver, ".");
+ else
+ new pkgAcqChangelog(&Fetcher, Ver);
}
- AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
- Fetcher.SetLog(&Stat);
+ if (printOnly == false)
+ {
+ // Disable drop-privs if "_apt" can not write to the target dir
+ CheckDropPrivsMustBeDisabled(Fetcher);
+ if (_error->PendingError() == true)
+ return false;
- bool const downOnly = _config->FindB("APT::Get::Download-Only", false);
+ bool Failed = false;
+ if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
+ return false;
+ }
- char tmpname[100];
- const char* tmpdir = NULL;
- if (downOnly == false)
+ if (downOnly == false || printOnly == true)
{
- std::string systemTemp = GetTempDir();
- snprintf(tmpname, sizeof(tmpname), "%s/apt-changelog-XXXXXX",
- systemTemp.c_str());
- tmpdir = mkdtemp(tmpname);
- if (tmpdir == NULL)
- return _error->Errno("mkdtemp", "mkdtemp failed");
-
- std::string const SandboxUser = _config->Find("APT::Sandbox::User");
- if (getuid() == 0 && SandboxUser.empty() == false) // if we aren't root, we can't chown, so don't try it
+ bool Failed = false;
+ for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
{
- struct passwd const * const pw = getpwnam(SandboxUser.c_str());
- struct group const * const gr = getgrnam("root");
- if (pw != NULL && gr != NULL)
+ if (printOnly)
{
- // chown the tmp dir directory we use to the sandbox user
- if(chown(tmpdir, pw->pw_uid, gr->gr_gid) != 0)
- _error->WarningE("DoChangelog", "chown to %s:%s of directory %s failed", SandboxUser.c_str(), "root", tmpdir);
+ if ((*I)->ErrorText.empty() == false)
+ {
+ Failed = true;
+ _error->Error("%s", (*I)->ErrorText.c_str());
+ }
+ else
+ cout << '\'' << (*I)->DescURI() << "' " << flNotDir((*I)->DestFile) << std::endl;
}
+ else
+ DisplayFileInPager((*I)->DestFile);
}
+ return Failed == false;
}
- for (APT::VersionList::const_iterator Ver = verset.begin();
- Ver != verset.end();
- ++Ver)
+ return true;
+}
+ /*}}}*/
+// DoIndexTargets - Lists all IndexTargets /*{{{*/
+static std::string format_key(std::string key)
+{
+ // deb822 is case-insensitive, but the human eye prefers candy
+ std::transform(key.begin(), key.end(), key.begin(), ::tolower);
+ key[0] = ::toupper(key[0]);
+ size_t found = key.find("_uri");
+ if (found != std::string::npos)
+ key.replace(found, 4, "-URI");
+ while ((found = key.find('_')) != std::string::npos)
{
- string changelogfile;
- if (downOnly == false)
- changelogfile.append(tmpname).append("/changelog");
- else
- changelogfile.append(Ver.ParentPkg().Name()).append(".changelog");
- if (DownloadChangelog(Cache, Fetcher, Ver, changelogfile) && downOnly == false)
+ key[found] = '-';
+ key[found + 1] = ::toupper(key[found + 1]);
+ }
+ return key;
+}
+static bool DoIndexTargets(CommandLine &CmdL)
+{
+ pkgCacheFile CacheFile;
+ pkgSourceList *SrcList = CacheFile.GetSourceList();
+
+ if (SrcList == NULL)
+ return false;
+
+ std::string const Format = _config->Find("APT::Get::IndexTargets::Format");
+ bool const ReleaseInfo = _config->FindB("APT::Get::IndexTargets::ReleaseInfo", true);
+ bool Filtered = CmdL.FileSize() > 1;
+ for (pkgSourceList::const_iterator S = SrcList->begin(); S != SrcList->end(); ++S)
+ {
+ std::vector<IndexTarget> const targets = (*S)->GetIndexTargets();
+ std::map<std::string, string> AddOptions;
+ if (ReleaseInfo)
{
- DisplayFileInPager(changelogfile);
- // cleanup temp file
- unlink(changelogfile.c_str());
+ AddOptions.insert(std::make_pair("TRUSTED", ((*S)->IsTrusted() ? "yes" : "no")));
+ pkgCache &Cache = *CacheFile.GetPkgCache();
+ pkgCache::RlsFileIterator const RlsFile = (*S)->FindInCache(Cache, false);
+ if (RlsFile.end())
+ continue;
+#define APT_RELEASE(X,Y) if (RlsFile.Y() != NULL) AddOptions.insert(std::make_pair(X, RlsFile.Y()))
+ APT_RELEASE("CODENAME", Codename);
+ APT_RELEASE("SUITE", Archive);
+ APT_RELEASE("VERSION", Version);
+ APT_RELEASE("ORIGIN", Origin);
+ APT_RELEASE("LABEL", Label);
+#undef APT_RELEASE
+ }
+
+ for (std::vector<IndexTarget>::const_iterator T = targets.begin(); T != targets.end(); ++T)
+ {
+ std::string filename = T->Option(ReleaseInfo ? IndexTarget::EXISTING_FILENAME : IndexTarget::FILENAME);
+ if (filename.empty())
+ continue;
+
+ std::ostringstream stanza;
+ if (Filtered || Format.empty())
+ {
+ stanza << "MetaKey: " << T->MetaKey << "\n"
+ << "ShortDesc: " << T->ShortDesc << "\n"
+ << "Description: " << T->Description << "\n"
+ << "URI: " << T->URI << "\n"
+ << "Filename: " << filename << "\n"
+ << "Optional: " << (T->IsOptional ? "yes" : "no") << "\n";
+ for (std::map<std::string,std::string>::const_iterator O = AddOptions.begin(); O != AddOptions.end(); ++O)
+ stanza << format_key(O->first) << ": " << O->second << "\n";
+ for (std::map<std::string,std::string>::const_iterator O = T->Options.begin(); O != T->Options.end(); ++O)
+ stanza << format_key(O->first) << ": " << O->second << "\n";
+ stanza << "\n";
+
+ if (Filtered)
+ {
+ // that is a bit crude, but good enough for now
+ bool found = true;
+ std::string haystack = std::string("\n") + stanza.str() + "\n";
+ std::transform(haystack.begin(), haystack.end(), haystack.begin(), ::tolower);
+ size_t const filesize = CmdL.FileSize() - 1;
+ for (size_t i = 0; i != filesize; ++i)
+ {
+ std::string needle = std::string("\n") + CmdL.FileList[i + 1] + "\n";
+ std::transform(needle.begin(), needle.end(), needle.begin(), ::tolower);
+ if (haystack.find(needle) != std::string::npos)
+ continue;
+ found = false;
+ break;
+ }
+ if (found == false)
+ continue;
+ }
+ }
+
+ if (Format.empty())
+ cout << stanza.str();
+ else
+ {
+ std::string out = SubstVar(Format, "$(FILENAME)", filename);
+ out = T->Format(out);
+ for (std::map<std::string,std::string>::const_iterator O = AddOptions.begin(); O != AddOptions.end(); ++O)
+ out = SubstVar(out, std::string("$(") + O->first + ")", O->second);
+ cout << out << std::endl;
+ }
}
}
- // clenaup tmp dir
- if (tmpdir != NULL)
- rmdir(tmpdir);
+
return true;
}
/*}}}*/
@@ -1705,6 +1645,7 @@ int main(int argc,const char *argv[]) /*{{{*/
{"remove",&DoInstall},
{"purge",&DoInstall},
{"autoremove",&DoInstall},
+ {"auto-remove",&DoInstall},
{"markauto",&DoMarkAuto},
{"unmarkauto",&DoMarkAuto},
{"dist-upgrade",&DoDistUpgrade},
@@ -1712,10 +1653,12 @@ int main(int argc,const char *argv[]) /*{{{*/
{"build-dep",&DoBuildDep},
{"clean",&DoClean},
{"autoclean",&DoAutoClean},
+ {"auto-clean",&DoAutoClean},
{"check",&DoCheck},
{"source",&DoSource},
{"download",&DoDownload},
{"changelog",&DoChangelog},
+ {"indextargets",&DoIndexTargets},
{"moo",&DoMoo},
{"help",&ShowHelp},
{0,0}};
diff --git a/cmdline/apt-internal-solver.cc b/cmdline/apt-internal-solver.cc
index 939061b93..af301dbcd 100644
--- a/cmdline/apt-internal-solver.cc
+++ b/cmdline/apt-internal-solver.cc
@@ -109,6 +109,7 @@ int main(int argc,const char *argv[]) /*{{{*/
if (_config->FindI("quiet", 0) < 1)
_config->Set("Debug::EDSP::WriteSolution", true);
+ _config->Set("APT::System", "Debian APT solver interface");
_config->Set("APT::Solver", "internal");
_config->Set("edsp::scenario", "stdin");
int input = STDIN_FILENO;
diff --git a/cmdline/apt-key.in b/cmdline/apt-key.in
index 2a66ad74d..881f8a990 100644
--- a/cmdline/apt-key.in
+++ b/cmdline/apt-key.in
@@ -34,7 +34,8 @@ get_fingerprints_of_keyring() {
elif [ "${fprline%%:*}" != 'fpr' ]; then continue; fi
echo "$fprline" | cut -d':' -f 10
done
- done
+ # order in the keyring shouldn't be important
+ done | sort
}
add_keys_with_verify_against_master_keyring() {
@@ -73,7 +74,7 @@ add_keys_with_verify_against_master_keyring() {
local TMP_KEYRING="${GPGHOMEDIR}/tmp-keyring.gpg"
$GPG_CMD --batch --yes --keyring "$ADD_KEYRING" --output "$TMP_KEYRING" --export "$add_key"
if ! $GPG_CMD --batch --yes --keyring "$TMP_KEYRING" --import "$MASTER" > "${GPGHOMEDIR}/gpgoutput.log" 2>&1; then
- cat "${GPGHOMEDIR}/gpgoutput.log"
+ cat >&2 "${GPGHOMEDIR}/gpgoutput.log"
false
fi
# check if signed with the master key and only add in this case
@@ -145,7 +146,7 @@ update() {
# attacker might as well replace the master-archive-keyring file
# in the package and add his own keys. so this check wouldn't
# add any security. we *need* this check on net-update though
- $GPG_CMD --quiet --batch --keyring $ARCHIVE_KEYRING --export | $GPG --import
+ import_keyring_into_keyring "$ARCHIVE_KEYRING" '' && cat "${GPGHOMEDIR}/gpgoutput.log"
if [ -r "$REMOVED_KEYS" ]; then
# remove no-longer supported/used keys
@@ -167,8 +168,10 @@ remove_key_from_keyring() {
local GPG="$GPG_CMD --keyring $KEYRINGFILE"
for KEY in "$@"; do
- # check if the key is in this keyring: the key id is in the 5 column at the end
- if ! get_fingerprints_of_keyring "$KEYRINGFILE" | grep -iq "^[0-9A-F]*${KEY}$"; then
+ local FINGERPRINTS="${GPGHOMEDIR}/keyringfile.keylst"
+ get_fingerprints_of_keyring "$KEYRINGFILE" > "$FINGERPRINTS"
+ # check if the key is in this keyring
+ if ! grep -iq "^[0-9A-F]*${KEY}$" "$FINGERPRINTS"; then
continue
fi
if [ ! -w "$KEYRINGFILE" ]; then
@@ -176,7 +179,7 @@ remove_key_from_keyring() {
continue
fi
# check if it is the only key in the keyring and if so remove the keyring altogether
- if [ '1' = "$(get_fingerprints_of_keyring "$KEYRINGFILE" | wc -l)" ]; then
+ if [ '1' = "$(uniq "$FINGERPRINTS" | wc -l)" ]; then
mv -f "$KEYRINGFILE" "${KEYRINGFILE}~" # behave like gpg
return
fi
@@ -188,7 +191,7 @@ remove_key_from_keyring() {
cp -a "$REALTARGET" "$KEYRINGFILE"
fi
# delete the key from the keyring
- $GPG --batch --delete-key --yes "$KEY"
+ $GPG --batch --delete-keys --yes "$KEY"
if [ -n "$REALTARGET" ]; then
# the real backup is the old link, not the copy we made
mv -f "${KEYRINGFILE}.dpkg-tmp" "${KEYRINGFILE}~"
@@ -199,7 +202,7 @@ remove_key_from_keyring() {
foreach_keyring_do() {
local ACTION="$1"
shift
- # if a --keyring was given, just remove from there
+ # if a --keyring was given, just work on this one
if [ -n "$FORCED_KEYRING" ]; then
$ACTION "$FORCED_KEYRING" "$@"
else
@@ -231,24 +234,78 @@ run_cmd_on_keyring() {
$GPG_CMD --keyring "$KEYRINGFILE" --batch "$@" 2>/dev/null || true
}
-import_keys_from_keyring() {
- local IMPORT="$1"
- local KEYRINGFILE="$2"
- if ! $GPG_CMD --keyring "$KEYRINGFILE" --batch --import "$IMPORT" > "${GPGHOMEDIR}/gpgoutput.log" 2>&1; then
- cat "${GPGHOMEDIR}/gpgoutput.log"
- false
+import_keyring_into_keyring() {
+ local FROM="${1:-${GPGHOMEDIR}/pubring.gpg}"
+ local TO="${2:-${GPGHOMEDIR}/pubring.gpg}"
+ shift 2
+ rm -f "${GPGHOMEDIR}/gpgoutput.log"
+ # the idea is simple: We take keys from one keyring and copy it to another
+ # we do this with so many checks inbetween to ensure that WE control the
+ # creation, so we know that the (potentially) created $TO keyring is a
+ # simple keyring rather than a keybox as gpg2 would create it which in turn
+ # can't be read by gpgv.
+ # BEWARE: This is designed more in the way to work with the current
+ # callers, than to have a well defined it would be easy to add new callers to.
+ if [ ! -s "$TO" ]; then
+ if [ -s "$FROM" ]; then
+ if [ -z "$2" ]; then
+ if ! $GPG_CMD --keyring "$FROM" --export ${1:+"$1"} > "$TO" 2> "${GPGHOMEDIR}/gpgoutput.log"; then
+ cat >&2 "${GPGHOMEDIR}/gpgoutput.log"
+ false
+ else
+ chmod 0644 -- "$TO"
+ fi
+ else
+ create_new_keyring "$TO"
+ fi
+ else
+ create_new_keyring "$TO"
+ fi
+ elif [ -s "$FROM" ]; then
+ local EXPORTLIMIT="$1"
+ if [ -n "$1$2" ]; then shift; fi
+ if ! $GPG_CMD --keyring "$FROM" --export ${EXPORTLIMIT:+"$EXPORTLIMIT"} | $GPG_CMD --keyring "$TO" --batch --import "$@" > "${GPGHOMEDIR}/gpgoutput.log" 2>&1; then
+ cat >&2 "${GPGHOMEDIR}/gpgoutput.log"
+ false
+ fi
fi
}
-merge_keys_into_keyrings() {
- local KEYRINGFILE="$1"
- local IMPORT="$2"
- if ! $GPG_CMD --keyring "$KEYRINGFILE" --batch --import --import-options 'merge-only' "$IMPORT" > "${GPGHOMEDIR}/gpgoutput.log" 2>&1; then
- cat "${GPGHOMEDIR}/gpgoutput.log"
- false
+merge_all_trusted_keyrings_into_pubring() {
+ # does the same as:
+ # foreach_keyring_do 'import_keys_from_keyring' "${GPGHOMEDIR}/pubring.gpg"
+ # but without using gpg, just cat and find
+ local PUBRING="${GPGHOMEDIR}/pubring.gpg"
+ # if a --keyring was given, just use this one
+ if [ -n "$FORCED_KEYRING" ]; then
+ if [ -s "$FORCED_KEYRING" ]; then
+ cp --dereference "$FORCED_KEYRING" "$PUBRING"
+ fi
+ else
+ # otherwise all known keyrings are merged
+ local TRUSTEDPARTS="/etc/apt/trusted.gpg.d"
+ eval $(apt-config shell TRUSTEDPARTS Dir::Etc::TrustedParts/d)
+ if [ -d "$TRUSTEDPARTS" ]; then
+ # ignore errors mostly for non-existing $TRUSTEDFILE
+ cat /dev/null "$TRUSTEDFILE" $(find -L "$TRUSTEDPARTS" -type f -name '*.gpg') > "$PUBRING" 2>/dev/null || true
+ elif [ -s "$TRUSTEDFILE" ]; then
+ cp --dereference "$TRUSTEDFILE" "$PUBRING"
+ fi
+ fi
+
+ if [ ! -s "$PUBRING" ]; then
+ touch "$PUBRING"
fi
}
+import_keys_from_keyring() {
+ import_keyring_into_keyring "$1" "$2"
+}
+
+merge_keys_into_keyrings() {
+ import_keyring_into_keyring "$2" "$1" '' --import-options 'merge-only'
+}
+
merge_back_changes() {
if [ -n "$FORCED_KEYRING" ]; then
# if the keyring was forced merge is already done
@@ -261,26 +318,29 @@ merge_back_changes() {
# look for keys which were added or removed
get_fingerprints_of_keyring "${GPGHOMEDIR}/pubring.orig.gpg" > "${GPGHOMEDIR}/pubring.orig.keylst"
get_fingerprints_of_keyring "${GPGHOMEDIR}/pubring.gpg" > "${GPGHOMEDIR}/pubring.keylst"
- sort "${GPGHOMEDIR}/pubring.keylst" "${GPGHOMEDIR}/pubring.orig.keylst" | uniq --unique | while read key; do
- if grep -q "^${key}$" "${GPGHOMEDIR}/pubring.orig.keylst"; then
- # key isn't part of new keyring, so remove
- foreach_keyring_do 'remove_key_from_keyring' "$key"
- elif grep -q "^${key}$" "${GPGHOMEDIR}/pubring.keylst"; then
- # key is part of new keyring, so we need to import it
- create_new_keyring "$TRUSTEDFILE"
- if ! $GPG --batch --yes --export "$key" | $GPG_CMD --keyring "$TRUSTEDFILE" --batch --yes --import > "${GPGHOMEDIR}/gpgoutput.log" 2>&1; then
- cat "${GPGHOMEDIR}/gpgoutput.log"
- false
- fi
- else
- echo >&2 "Errror: Key ${key} (dis)appeared out of nowhere"
- fi
+ comm -3 "${GPGHOMEDIR}/pubring.keylst" "${GPGHOMEDIR}/pubring.orig.keylst" > "${GPGHOMEDIR}/pubring.diff"
+ # key isn't part of new keyring, so remove
+ cut -f 2 "${GPGHOMEDIR}/pubring.diff" | while read key; do
+ if [ -z "$key" ]; then continue; fi
+ foreach_keyring_do 'remove_key_from_keyring' "$key"
+ done
+ # key is only part of new keyring, so we need to import it
+ cut -f 1 "${GPGHOMEDIR}/pubring.diff" | while read key; do
+ if [ -z "$key" ]; then continue; fi
+ import_keyring_into_keyring '' "$TRUSTEDFILE" "$key"
done
}
setup_merged_keyring() {
- if [ -z "$FORCED_KEYRING" ]; then
- foreach_keyring_do 'import_keys_from_keyring' "${GPGHOMEDIR}/pubring.gpg"
+ if [ -n "$FORCED_KEYID" ]; then
+ merge_all_trusted_keyrings_into_pubring
+ FORCED_KEYRING="${GPGHOMEDIR}/forcedkeyid.gpg"
+ TRUSTEDFILE="${FORCED_KEYRING}"
+ GPG="$GPG --keyring $TRUSTEDFILE"
+ # ignore error as this "just" means we haven't found the forced keyid and the keyring will be empty
+ import_keyring_into_keyring '' "$TRUSTEDFILE" "$FORCED_KEYID" || true
+ elif [ -z "$FORCED_KEYRING" ]; then
+ merge_all_trusted_keyrings_into_pubring
if [ -r "${GPGHOMEDIR}/pubring.gpg" ]; then
cp -a "${GPGHOMEDIR}/pubring.gpg" "${GPGHOMEDIR}/pubring.orig.gpg"
else
@@ -288,8 +348,8 @@ setup_merged_keyring() {
fi
GPG="$GPG --keyring ${GPGHOMEDIR}/pubring.gpg"
else
- GPG="$GPG --keyring $TRUSTEDFILE"
create_new_keyring "$TRUSTEDFILE"
+ GPG="$GPG --keyring $TRUSTEDFILE"
fi
}
@@ -328,12 +388,17 @@ while [ -n "$1" ]; do
TRUSTEDFILE="$1"
FORCED_KEYRING="$1"
;;
+ --keyid)
+ shift
+ FORCED_KEYID="$1"
+ ;;
--secret-keyring)
shift
FORCED_SECRET_KEYRING="$1"
;;
--readonly)
merge_back_changes() { true; }
+ create_new_keyring() { if [ ! -r $FORCED_KEYRING ]; then TRUSTEDFILE='/dev/null'; FORCED_KEYRING="$TRUSTEDFILE"; fi; }
;;
--fakeroot)
requires_root() { true; }
@@ -341,6 +406,14 @@ while [ -n "$1" ]; do
--quiet)
aptkey_echo() { true; }
;;
+ --debug1)
+ # some cmds like finger redirect stderr to /dev/null …
+ aptkey_execute() { echo 'EXEC:' "$@"; "$@"; }
+ ;;
+ --debug2)
+ # … other more complicated ones pipe gpg into gpg.
+ aptkey_execute() { echo >&2 'EXEC:' "$@"; "$@"; }
+ ;;
--*)
echo >&2 "Unknown option: $1"
usage
@@ -364,7 +437,23 @@ if [ -z "$command" ]; then
fi
shift
-if [ "$command" != "help" ]; then
+create_gpg_home() {
+ # gpg needs (in different versions more or less) files to function correctly,
+ # so we give it its own homedir and generate some valid content for it later on
+ if [ -n "$TMPDIR" ]; then
+ # tmpdir is a directory and current user has rwx access to it
+ # same tests as in apt-pkg/contrib/fileutl.cc GetTempDir()
+ if [ ! -d "$TMPDIR" ] || [ ! -r "$TMPDIR" ] || [ ! -w "$TMPDIR" ] || [ ! -x "$TMPDIR" ]; then
+ unset TMPDIR
+ fi
+ fi
+ GPGHOMEDIR="$(mktemp -d)"
+ CURRENTTRAP="${CURRENTTRAP} rm -rf '${GPGHOMEDIR}';"
+ trap "${CURRENTTRAP}" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
+ chmod 700 "$GPGHOMEDIR"
+}
+
+prepare_gpg_home() {
eval $(apt-config shell GPG_EXE Apt::Key::gpgcommand)
if [ -n "$GPG_EXE" ] && which "$GPG_EXE" >/dev/null 2>&1; then
@@ -375,26 +464,18 @@ if [ "$command" != "help" ]; then
GPG_EXE="gpg2"
else
echo >&2 "Error: gnupg or gnupg2 do not seem to be installed,"
- echo >&2 "Error: but apt-key requires gnupg or gnupg2 for operation."
+ echo >&2 "Error: but apt-key requires gnupg or gnupg2 for this operation."
echo >&2
exit 255
fi
+ if type aptkey_execute >/dev/null 2>&1; then
+ GPG_EXE="aptkey_execute $GPG_EXE"
+ fi
GPG_CMD="$GPG_EXE --ignore-time-conflict --no-options --no-default-keyring"
- # gpg needs (in different versions more or less) files to function correctly,
- # so we give it its own homedir and generate some valid content for it
- if [ -n "$TMPDIR" ]; then
- # tmpdir is a directory and current user has rwx access to it
- # same tests as in apt-pkg/contrib/fileutl.cc GetTempDir()
- if [ ! -d "$TMPDIR" ] || [ ! -r "$TMPDIR" ] || [ ! -w "$TMPDIR" ] || [ ! -x "$TMPDIR" ]; then
- unset TMPDIR
- fi
- fi
- GPGHOMEDIR="$(mktemp -d)"
- CURRENTTRAP="${CURRENTTRAP} rm -rf '${GPGHOMEDIR}';"
- trap "${CURRENTTRAP}" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
- chmod 700 "$GPGHOMEDIR"
+ create_gpg_home
+
# We don't use a secret keyring, of course, but gpg panics and
# implodes if there isn't one available - and writeable for imports
SECRETKEYRING="${GPGHOMEDIR}/secring.gpg"
@@ -414,6 +495,16 @@ if [ "$command" != "help" ]; then
rm -f "$SECRETKEYRING"
cp -a "$FORCED_SECRET_KEYRING" "$SECRETKEYRING"
fi
+
+ # older gpg versions need a secring file, but newer versions take it as
+ # a hint to start a migration from earlier versions. The file is empty
+ # anyhow, so nothing actually happens, but its three lines of output
+ # nobody expects to see in apt-key context, so trigger it in silence
+ echo -n | $GPG --batch --import >/dev/null 2>&1 || true
+}
+
+if [ "$command" != 'help' ] && [ "$command" != 'verify' ]; then
+ prepare_gpg_home
fi
case "$command" in
@@ -448,7 +539,7 @@ case "$command" in
foreach_keyring_do 'run_cmd_on_keyring' --fingerprint "$@"
;;
export|exportall)
- foreach_keyring_do 'import_keys_from_keyring' "${GPGHOMEDIR}/pubring.gpg"
+ merge_all_trusted_keyrings_into_pubring
$GPG_CMD --keyring "${GPGHOMEDIR}/pubring.gpg" --armor --export "$@"
;;
adv*)
@@ -458,11 +549,26 @@ case "$command" in
merge_back_changes
;;
verify)
+ GPGV=''
+ eval $(apt-config shell GPGV Apt::Key::gpgvcommand)
+ if [ -n "$GPGV" ] && which "$GPGV" >/dev/null 2>&1; then true;
+ elif which gpgv >/dev/null 2>&1; then GPGV='gpgv';
+ elif which gpgv2 >/dev/null 2>&1; then GPGV='gpgv2';
+ else
+ echo >&2 'ERROR: gpgv or gpgv2 required for verification'
+ exit 29
+ fi
+ # for a forced keyid we need gpg --export, so full wrapping required
+ if [ -n "$FORCED_KEYID" ]; then
+ prepare_gpg_home
+ else
+ create_gpg_home
+ fi
setup_merged_keyring
- if which gpgv >/dev/null 2>&1; then
- gpgv --homedir "${GPGHOMEDIR}" --keyring "${GPGHOMEDIR}/pubring.gpg" --ignore-time-conflict "$@"
+ if [ -n "$FORCED_KEYRING" ]; then
+ $GPGV --homedir "${GPGHOMEDIR}" --keyring "${FORCED_KEYRING}" --ignore-time-conflict "$@"
else
- $GPG --verify "$@"
+ $GPGV --homedir "${GPGHOMEDIR}" --keyring "${GPGHOMEDIR}/pubring.gpg" --ignore-time-conflict "$@"
fi
;;
help)
diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc
index de1c80309..02c73fc2e 100644
--- a/cmdline/apt-mark.cc
+++ b/cmdline/apt-mark.cc
@@ -238,7 +238,7 @@ static bool DoHold(CommandLine &CmdL)
ioprintf(c1out,_("%s was already set on hold.\n"), Pkg.FullName(true).c_str());
else
ioprintf(c1out,_("%s was already not hold.\n"), Pkg.FullName(true).c_str());
- Pkg = pkgset.erase(Pkg, true);
+ Pkg = pkgset.erase(Pkg);
}
else
++Pkg;
diff --git a/cmdline/apt.cc b/cmdline/apt.cc
index 2f7eddb61..92db34cfa 100644
--- a/cmdline/apt.cc
+++ b/cmdline/apt.cc
@@ -55,6 +55,7 @@ static bool ShowHelp(CommandLine &)
"\n"
" install - install packages\n"
" remove - remove packages\n"
+ " autoremove - Remove automatically all unused packages\n"
"\n"
" upgrade - upgrade the system by installing/upgrading packages\n"
" full-upgrade - upgrade the system by removing/installing/upgrading packages\n"
@@ -76,6 +77,8 @@ int main(int argc, const char *argv[]) /*{{{*/
// package stuff
{"install",&DoInstall},
{"remove", &DoInstall},
+ {"autoremove", &DoInstall},
+ {"auto-remove", &DoInstall},
{"purge", &DoInstall},
// system wide stuff