summaryrefslogtreecommitdiff
path: root/cmdline
diff options
context:
space:
mode:
Diffstat (limited to 'cmdline')
-rw-r--r--cmdline/apt-cache.cc46
-rw-r--r--cmdline/apt-extracttemplates.cc15
-rw-r--r--cmdline/apt-extracttemplates.h1
-rw-r--r--cmdline/apt-get.cc49
4 files changed, 91 insertions, 20 deletions
diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc
index 1414617eb..2ed1bf5d4 100644
--- a/cmdline/apt-cache.cc
+++ b/cmdline/apt-cache.cc
@@ -264,6 +264,44 @@ 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_ptrloc *Hashtable,
+ unsigned long Size)
+{
+ // hashtable stats for the HashTable
+ long NumBuckets = Size;
+ long UsedBuckets = 0;
+ long UnusedBuckets = 0;
+ long LongestBucket = 0;
+ long ShortestBucket = NumBuckets;
+ for (unsigned int i=0; i < NumBuckets; ++i)
+ {
+ T *P = StartP + Hashtable[i];
+ if(P == 0 || P == StartP)
+ {
+ UnusedBuckets++;
+ continue;
+ }
+ long ThisBucketSize = 0;
+ for (; P != StartP; P = StartP + P->Next)
+ ThisBucketSize++;
+ LongestBucket = std::max(ThisBucketSize, LongestBucket);
+ ShortestBucket = std::min(ThisBucketSize, ShortestBucket);
+ UsedBuckets += ThisBucketSize;
+ }
+ cout << "Total buckets " << Type << ": " << SizeToStr(NumBuckets) << std::endl;
+ cout << " Unused: " << SizeToStr(UnusedBuckets) << std::endl;
+ cout << " Used: " << UsedBuckets << std::endl;
+ cout << " Average entries: " << UsedBuckets/(double)NumBuckets << std::endl;
+ cout << " Longest: " << LongestBucket << std::endl;
+ cout << " Shortest: " << ShortestBucket << std::endl;
+}
+ /*}}}*/
// Stats - Dump some nice statistics /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -373,7 +411,13 @@ static bool Stats(CommandLine &)
Cache->Head().VerFileCount*Cache->Head().VerFileSz +
Cache->Head().ProvidesCount*Cache->Head().ProvidesSz;
cout << _("Total space accounted for: ") << SizeToStr(Total) << endl;
-
+
+ // hashtable stats
+ int HashTableSize = sizeof(Cache->HeaderP->PkgHashTable)/sizeof(map_ptrloc);
+ ShowHashTableStats<pkgCache::Package>("PkgHashTable", Cache->PkgP, Cache->HeaderP->PkgHashTable, HashTableSize);
+ HashTableSize = sizeof(Cache->HeaderP->GrpHashTable)/sizeof(map_ptrloc);
+ ShowHashTableStats<pkgCache::Group>("GrpHashTable", Cache->GrpP, Cache->HeaderP->GrpHashTable, HashTableSize);
+
return true;
}
/*}}}*/
diff --git a/cmdline/apt-extracttemplates.cc b/cmdline/apt-extracttemplates.cc
index e4428e051..0d568106f 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;
}
@@ -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..6d2870a02 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;
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)