summaryrefslogtreecommitdiff
path: root/cmdline
diff options
context:
space:
mode:
Diffstat (limited to 'cmdline')
-rw-r--r--cmdline/apt-cache.cc70
-rw-r--r--cmdline/apt-dump-solver.cc2
-rw-r--r--cmdline/apt-extracttemplates.cc17
-rw-r--r--cmdline/apt-extracttemplates.h3
-rw-r--r--cmdline/apt-get.cc49
-rw-r--r--cmdline/apt-internal-solver.cc3
6 files changed, 114 insertions, 30 deletions
diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc
index 1414617eb..88a323280 100644
--- a/cmdline/apt-cache.cc
+++ b/cmdline/apt-cache.cc
@@ -264,6 +264,46 @@ static bool DumpPackage(CommandLine &CmdL)
return true;
}
/*}}}*/
+// ShowHashTableStats - Show stats about a hashtable /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+template<class T>
+static void ShowHashTableStats(std::string Type,
+ T *StartP,
+ map_pointer_t *Hashtable,
+ unsigned long Size)
+{
+ // hashtable stats for the HashTable
+ unsigned long NumBuckets = Size;
+ unsigned long UsedBuckets = 0;
+ unsigned long UnusedBuckets = 0;
+ unsigned long LongestBucket = 0;
+ unsigned long ShortestBucket = NumBuckets;
+ unsigned long Entries = 0;
+ for (unsigned int i=0; i < NumBuckets; ++i)
+ {
+ T *P = StartP + Hashtable[i];
+ if(P == 0 || P == StartP)
+ {
+ ++UnusedBuckets;
+ continue;
+ }
+ ++UsedBuckets;
+ unsigned long ThisBucketSize = 0;
+ for (; P != StartP; P = StartP + P->Next)
+ ++ThisBucketSize;
+ Entries += ThisBucketSize;
+ LongestBucket = std::max(ThisBucketSize, LongestBucket);
+ ShortestBucket = std::min(ThisBucketSize, ShortestBucket);
+ }
+ cout << "Total buckets in " << Type << ": " << NumBuckets << std::endl;
+ cout << " Unused: " << UnusedBuckets << std::endl;
+ cout << " Used: " << UsedBuckets << std::endl;
+ cout << " Average entries: " << Entries/(double)NumBuckets << std::endl;
+ cout << " Longest: " << LongestBucket << std::endl;
+ cout << " Shortest: " << ShortestBucket << std::endl;
+}
+ /*}}}*/
// Stats - Dump some nice statistics /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -360,20 +400,32 @@ static bool Stats(CommandLine &)
}
}
cout << _("Total dependency version space: ") << SizeToStr(DepVerSize) << endl;
-
+
unsigned long Slack = 0;
for (int I = 0; I != 7; I++)
Slack += Cache->Head().Pools[I].ItemSize*Cache->Head().Pools[I].Count;
cout << _("Total slack space: ") << SizeToStr(Slack) << endl;
-
+
unsigned long Total = 0;
- Total = Slack + Size + Cache->Head().DependsCount*Cache->Head().DependencySz +
- Cache->Head().VersionCount*Cache->Head().VersionSz +
- Cache->Head().PackageCount*Cache->Head().PackageSz +
- Cache->Head().VerFileCount*Cache->Head().VerFileSz +
- Cache->Head().ProvidesCount*Cache->Head().ProvidesSz;
+#define APT_CACHESIZE(X,Y) (Cache->Head().X * Cache->Head().Y)
+ Total = Slack + Size +
+ APT_CACHESIZE(GroupCount, GroupSz) +
+ APT_CACHESIZE(PackageCount, PackageSz) +
+ APT_CACHESIZE(VersionCount, VersionSz) +
+ APT_CACHESIZE(DescriptionCount, DescriptionSz) +
+ APT_CACHESIZE(DependsCount, DependencySz) +
+ APT_CACHESIZE(PackageFileCount, PackageFileSz) +
+ APT_CACHESIZE(VerFileCount, VerFileSz) +
+ APT_CACHESIZE(DescFileCount, DescFileSz) +
+ APT_CACHESIZE(ProvidesCount, ProvidesSz) +
+ (2 * Cache->Head().HashTableSize * sizeof(map_id_t));
cout << _("Total space accounted for: ") << SizeToStr(Total) << endl;
-
+#undef APT_CACHESIZE
+
+ // hashtable stats
+ ShowHashTableStats<pkgCache::Package>("PkgHashTable", Cache->PkgP, Cache->Head().PkgHashTable(), Cache->Head().HashTableSize);
+ ShowHashTableStats<pkgCache::Group>("GrpHashTable", Cache->GrpP, Cache->Head().GrpHashTable(), Cache->Head().HashTableSize);
+
return true;
}
/*}}}*/
@@ -1231,7 +1283,7 @@ static bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V)
struct ExDescFile
{
pkgCache::DescFile *Df;
- map_ptrloc ID;
+ map_id_t ID;
};
// Search - Perform a search /*{{{*/
diff --git a/cmdline/apt-dump-solver.cc b/cmdline/apt-dump-solver.cc
index 04e13bde9..424764b3c 100644
--- a/cmdline/apt-dump-solver.cc
+++ b/cmdline/apt-dump-solver.cc
@@ -40,6 +40,8 @@ int main(int argc,const char *argv[]) /*{{{*/
ShowHelp();
return 0;
}
+ // we really don't need anything
+ DropPrivs();
FILE* input = fdopen(STDIN_FILENO, "r");
FILE* output = fopen("/tmp/dump.edsp", "w");
diff --git a/cmdline/apt-extracttemplates.cc b/cmdline/apt-extracttemplates.cc
index e4428e051..f95b9e5ba 100644
--- a/cmdline/apt-extracttemplates.cc
+++ b/cmdline/apt-extracttemplates.cc
@@ -52,7 +52,7 @@ pkgCache *DebFile::Cache = 0;
// ---------------------------------------------------------------------
/* */
DebFile::DebFile(const char *debfile)
- : File(debfile, FileFd::ReadOnly), Size(0), Control(NULL), ControlLen(0),
+ : File(debfile, FileFd::ReadOnly), Control(NULL), ControlLen(0),
DepOp(0), PreDepOp(0), Config(0), Template(0), Which(None)
{
}
@@ -103,10 +103,12 @@ bool DebFile::DoItem(Item &I, int &Fd)
if (strcmp(I.Name, "control") == 0)
{
delete [] Control;
- Control = new char[I.Size+1];
- Control[I.Size] = 0;
+ Control = new char[I.Size+3];
+ Control[I.Size] = '\n';
+ Control[I.Size + 1] = '\n';
+ Control[I.Size + 2] = '\0';
Which = IsControl;
- ControlLen = I.Size;
+ ControlLen = I.Size + 3;
// make it call the Process method below. this is so evil
Fd = -2;
}
@@ -138,7 +140,7 @@ bool DebFile::DoItem(Item &I, int &Fd)
// ---------------------------------------------------------------------
/* */
bool DebFile::Process(Item &/*I*/, const unsigned char *data,
- unsigned long size, unsigned long pos)
+ unsigned long long size, unsigned long long pos)
{
switch (Which)
{
@@ -162,9 +164,10 @@ bool DebFile::Process(Item &/*I*/, const unsigned char *data,
bool DebFile::ParseInfo()
{
if (Control == NULL) return false;
-
+
pkgTagSection Section;
- Section.Scan(Control, ControlLen);
+ if (Section.Scan(Control, ControlLen) == false)
+ return false;
Package = Section.FindS("Package");
Version = GetInstalledVer(Package);
diff --git a/cmdline/apt-extracttemplates.h b/cmdline/apt-extracttemplates.h
index 9cc3f5f25..829cdae75 100644
--- a/cmdline/apt-extracttemplates.h
+++ b/cmdline/apt-extracttemplates.h
@@ -20,7 +20,6 @@ class pkgCache;
class DebFile : public pkgDirStream
{
FileFd File;
- unsigned long Size;
char *Control;
unsigned long ControlLen;
@@ -29,7 +28,7 @@ public:
~DebFile();
bool DoItem(Item &I, int &fd);
bool Process(pkgDirStream::Item &I, const unsigned char *data,
- unsigned long size, unsigned long pos);
+ unsigned long long size, unsigned long long pos);
bool Go();
bool ParseInfo();
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc
index a58386eb0..bd866bc8c 100644
--- a/cmdline/apt-get.cc
+++ b/cmdline/apt-get.cc
@@ -832,23 +832,25 @@ static bool DoSource(CommandLine &CmdL)
queued.insert(Last->Index().ArchiveURI(I->Path));
// check if we have a file with that md5 sum already localy
- if(!I->MD5Hash.empty() && FileExists(flNotDir(I->Path)))
- {
- FileFd Fd(flNotDir(I->Path), FileFd::ReadOnly);
- MD5Summation sum;
- sum.AddFD(Fd.Fd(), Fd.Size());
- Fd.Close();
- if((string)sum.Result() == I->MD5Hash)
+ std::string localFile = flNotDir(I->Path);
+ if (FileExists(localFile) == true)
+ if(I->Hashes.VerifyFile(localFile) == true)
{
ioprintf(c1out,_("Skipping already downloaded file '%s'\n"),
- flNotDir(I->Path).c_str());
+ localFile.c_str());
continue;
}
+
+ // see if we have a hash (Acquire::ForceHash is the only way to have none)
+ if (I->Hashes.usable() == false && _config->FindB("APT::Get::AllowUnauthenticated",false) == false)
+ {
+ ioprintf(c1out, "Skipping download of file '%s' as requested hashsum is not available for authentication\n",
+ localFile.c_str());
+ continue;
}
new pkgAcqFile(&Fetcher,Last->Index().ArchiveURI(I->Path),
- I->MD5Hash,I->Size,
- Last->Index().SourceInfo(*Last,*I),Src);
+ I->Hashes, I->Size, Last->Index().SourceInfo(*Last,*I), Src);
}
}
@@ -1061,7 +1063,30 @@ static bool DoBuildDep(CommandLine &CmdL)
for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
{
string Src;
- pkgSrcRecords::Parser *Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
+ pkgSrcRecords::Parser *Last = 0;
+
+ // a unpacked debian source tree
+ if (DirectoryExists(*I))
+ {
+ // FIXME: how can we make this more elegant?
+ std::string TypeName = "debian/control File Source Index";
+ pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
+ if(Type != NULL)
+ Last = Type->CreateSrcPkgParser(*I);
+ }
+ // if its a local file (e.g. .dsc) use this
+ else if (FileExists(*I))
+ {
+ // see if we can get a parser for this pkgIndexFile type
+ string TypeName = flExtension(*I) + " File Source Index";
+ pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(TypeName.c_str());
+ if(Type != NULL)
+ Last = Type->CreateSrcPkgParser(*I);
+ } else {
+ // normal case, search the cache for the source file
+ Last = FindSrc(*I,Recs,SrcRecs,Src,Cache);
+ }
+
if (Last == 0)
return _error->Error(_("Unable to find a source package for %s"),Src.c_str());
@@ -1079,7 +1104,7 @@ static bool DoBuildDep(CommandLine &CmdL)
}
else if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false)
return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
-
+
// Also ensure that build-essential packages are present
Configuration::Item const *Opts = _config->Tree("APT::Build-Essential");
if (Opts)
diff --git a/cmdline/apt-internal-solver.cc b/cmdline/apt-internal-solver.cc
index 5fda7b6a0..c24a96cdf 100644
--- a/cmdline/apt-internal-solver.cc
+++ b/cmdline/apt-internal-solver.cc
@@ -76,6 +76,9 @@ int main(int argc,const char *argv[]) /*{{{*/
{'o',"option",0,CommandLine::ArbItem},
{0,0,0,0}};
+ // we really don't need anything
+ DropPrivs();
+
CommandLine CmdL(Args,_config);
if (pkgInitConfig(*_config) == false ||
CmdL.Parse(argc,argv) == false) {