summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/acquire-item.cc62
-rw-r--r--apt-pkg/contrib/configuration.cc41
-rw-r--r--apt-pkg/contrib/fileutl.cc50
-rw-r--r--apt-pkg/contrib/fileutl.h3
-rw-r--r--apt-pkg/indexcopy.cc4
-rw-r--r--apt-pkg/pkgcache.cc2
-rw-r--r--apt-pkg/policy.cc37
-rw-r--r--apt-pkg/sourcelist.cc43
8 files changed, 111 insertions, 131 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index afb3daad3..d2aca597e 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -219,19 +219,19 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile) /*{{{*/
if(TF.Step(Tags) == true)
{
- string local_sha1;
bool found = false;
DiffInfo d;
string size;
- string tmp = Tags.FindS("SHA1-Current");
+ string const tmp = Tags.FindS("SHA1-Current");
std::stringstream ss(tmp);
- ss >> ServerSha1;
+ ss >> ServerSha1 >> size;
+ unsigned long const ServerSize = atol(size.c_str());
FileFd fd(CurrentPackagesFile, FileFd::ReadOnly);
SHA1Summation SHA1;
SHA1.AddFD(fd.Fd(), fd.Size());
- local_sha1 = string(SHA1.Result());
+ string const local_sha1 = SHA1.Result();
if(local_sha1 == ServerSha1)
{
@@ -248,20 +248,56 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile) /*{{{*/
std::clog << "SHA1-Current: " << ServerSha1 << std::endl;
// check the historie and see what patches we need
- string history = Tags.FindS("SHA1-History");
+ string const history = Tags.FindS("SHA1-History");
std::stringstream hist(history);
- while(hist >> d.sha1 >> size >> d.file)
+ while(hist >> d.sha1 >> size >> d.file)
{
- d.size = atoi(size.c_str());
// read until the first match is found
+ // from that point on, we probably need all diffs
if(d.sha1 == local_sha1)
found=true;
- // from that point on, we probably need all diffs
- if(found)
+ else if (found == false)
+ continue;
+
+ if(Debug)
+ std::clog << "Need to get diff: " << d.file << std::endl;
+ available_patches.push_back(d);
+ }
+
+ if (available_patches.empty() == false)
+ {
+ // patching with too many files is rather slow compared to a fast download
+ unsigned long const fileLimit = _config->FindI("Acquire::PDiffs::FileLimit", 0);
+ if (fileLimit != 0 && fileLimit < available_patches.size())
+ {
+ if (Debug)
+ std::clog << "Need " << available_patches.size() << " diffs (Limit is " << fileLimit
+ << ") so fallback to complete download" << std::endl;
+ return false;
+ }
+
+ // see if the patches are too big
+ found = false; // it was true and it will be true again at the end
+ d = *available_patches.begin();
+ string const firstPatch = d.file;
+ unsigned long patchesSize = 0;
+ std::stringstream patches(Tags.FindS("SHA1-Patches"));
+ while(patches >> d.sha1 >> size >> d.file)
+ {
+ if (firstPatch == d.file)
+ found = true;
+ else if (found == false)
+ continue;
+
+ patchesSize += atol(size.c_str());
+ }
+ unsigned long const sizeLimit = ServerSize * _config->FindI("Acquire::PDiffs::SizeLimit", 100);
+ if (sizeLimit > 0 && (sizeLimit/100) < patchesSize)
{
- if(Debug)
- std::clog << "Need to get diff: " << d.file << std::endl;
- available_patches.push_back(d);
+ if (Debug)
+ std::clog << "Need " << patchesSize << " bytes (Limit is " << sizeLimit/100
+ << ") so fallback to complete download" << std::endl;
+ return false;
}
}
}
@@ -270,7 +306,7 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile) /*{{{*/
if(found)
{
// queue the diffs
- string::size_type last_space = Description.rfind(" ");
+ string::size_type const last_space = Description.rfind(" ");
if(last_space != string::npos)
Description.erase(last_space, Description.size()-last_space);
new pkgAcqIndexDiffs(Owner, RealURI, Description, Desc.ShortDesc,
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index 4e8586e83..08faf22b5 100644
--- a/apt-pkg/contrib/configuration.cc
+++ b/apt-pkg/contrib/configuration.cc
@@ -22,14 +22,8 @@
#include <apti18n.h>
#include <vector>
-#include <algorithm>
#include <fstream>
#include <iostream>
-
-#include <stdio.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <unistd.h>
using namespace std;
/*}}}*/
@@ -835,39 +829,8 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool AsSectional,
// ReadConfigDir - Read a directory of config files /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool ReadConfigDir(Configuration &Conf,const string &Dir,bool AsSectional,
- unsigned Depth)
-{
- DIR *D = opendir(Dir.c_str());
- if (D == 0)
- return _error->Errno("opendir",_("Unable to read %s"),Dir.c_str());
-
- vector<string> List;
-
- for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D))
- {
- if (Ent->d_name[0] == '.')
- continue;
-
- // Skip bad file names ala run-parts
- const char *C = Ent->d_name;
- for (; *C != 0; C++)
- if (isalpha(*C) == 0 && isdigit(*C) == 0 && *C != '_' && *C != '-')
- break;
- if (*C != 0)
- continue;
-
- // Make sure it is a file and not something else
- string File = flCombine(Dir,Ent->d_name);
- struct stat St;
- if (stat(File.c_str(),&St) != 0 || S_ISREG(St.st_mode) == 0)
- continue;
-
- List.push_back(File);
- }
- closedir(D);
-
- sort(List.begin(),List.end());
+{
+ vector<string> const List = GetListOfFilesInDir(Dir, "", true);
// Read the files
for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++)
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 4240d9f49..cce8a4512 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -34,9 +34,11 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
+#include <dirent.h>
#include <signal.h>
#include <errno.h>
#include <set>
+#include <algorithm>
/*}}}*/
using namespace std;
@@ -195,6 +197,54 @@ bool FileExists(string File)
return true;
}
/*}}}*/
+// GetListOfFilesInDir - returns a vector of files in the given dir /*{{{*/
+// ---------------------------------------------------------------------
+/* If an extension is given only files with this extension are included
+ in the returned vector, otherwise every "normal" file is included. */
+std::vector<string> GetListOfFilesInDir(string const &Dir, string const &Ext,
+ bool const &SortList)
+{
+ std::vector<string> List;
+ DIR *D = opendir(Dir.c_str());
+ if (D == 0)
+ {
+ _error->Errno("opendir",_("Unable to read %s"),Dir.c_str());
+ return List;
+ }
+
+ for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D))
+ {
+ if (Ent->d_name[0] == '.')
+ continue;
+
+ if (Ext.empty() == false && flExtension(Ent->d_name) != Ext)
+ continue;
+
+ // Skip bad file names ala run-parts
+ const char *C = Ent->d_name;
+ for (; *C != 0; ++C)
+ if (isalpha(*C) == 0 && isdigit(*C) == 0
+ && *C != '_' && *C != '-' && *C != '.')
+ break;
+
+ if (*C != 0)
+ continue;
+
+ // Make sure it is a file and not something else
+ string const File = flCombine(Dir,Ent->d_name);
+ struct stat St;
+ if (stat(File.c_str(),&St) != 0 || S_ISREG(St.st_mode) == 0)
+ continue;
+
+ List.push_back(File);
+ }
+ closedir(D);
+
+ if (SortList == true)
+ std::sort(List.begin(),List.end());
+ return List;
+}
+ /*}}}*/
// SafeGetCWD - This is a safer getcwd that returns a dynamic string /*{{{*/
// ---------------------------------------------------------------------
/* We return / on failure. */
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index 73b5ea3be..2807c29d9 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -23,6 +23,7 @@
#include <string>
+#include <vector>
using std::string;
@@ -81,6 +82,8 @@ bool RunScripts(const char *Cnf);
bool CopyFile(FileFd &From,FileFd &To);
int GetLock(string File,bool Errors = true);
bool FileExists(string File);
+std::vector<string> GetListOfFilesInDir(string const &Dir, string const &Ext,
+ bool const &SortList);
string SafeGetCWD();
void SetCloseExec(int Fd,bool Close);
void SetNonBlock(int Fd,bool Block);
diff --git a/apt-pkg/indexcopy.cc b/apt-pkg/indexcopy.cc
index 57c9f95ca..53eb11172 100644
--- a/apt-pkg/indexcopy.cc
+++ b/apt-pkg/indexcopy.cc
@@ -275,7 +275,7 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
_error->Warning("No valid records were found.");
if (NotFound + WrongSize > 10)
- _error->Warning("Alot of entries were discarded, something may be wrong.\n");
+ _error->Warning("A lot of entries were discarded, something may be wrong.\n");
return true;
@@ -847,7 +847,7 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name, /*{{{*/
_error->Warning("No valid records were found.");
if (NotFound + WrongSize > 10)
- _error->Warning("Alot of entries were discarded, something may be wrong.\n");
+ _error->Warning("A lot of entries were discarded, something may be wrong.\n");
return true;
diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc
index b0ce6e598..e8ee75b96 100644
--- a/apt-pkg/pkgcache.cc
+++ b/apt-pkg/pkgcache.cc
@@ -298,7 +298,7 @@ const char *
pkgCache::PkgIterator::CandVersion() const
{
//TargetVer is empty, so don't use it.
- VerIterator version = pkgPolicy::pkgPolicy(Owner).GetCandidateVer(*this);
+ VerIterator version = pkgPolicy(Owner).GetCandidateVer(*this);
if (version.IsGood())
return version.VerStr();
return 0;
diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc
index 81fdb0431..393181b6d 100644
--- a/apt-pkg/policy.cc
+++ b/apt-pkg/policy.cc
@@ -27,14 +27,12 @@
#include <apt-pkg/configuration.h>
#include <apt-pkg/tagfile.h>
#include <apt-pkg/strutl.h>
+#include <apt-pkg/fileutl.h>
#include <apt-pkg/error.h>
#include <apt-pkg/sptr.h>
-
+
#include <apti18n.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <algorithm>
#include <iostream>
#include <sstream>
/*}}}*/
@@ -282,36 +280,7 @@ bool ReadPinDir(pkgPolicy &Plcy,string Dir)
return true;
}
- DIR *D = opendir(Dir.c_str());
- if (D == 0)
- return _error->Errno("opendir",_("Unable to read %s"),Dir.c_str());
-
- vector<string> List;
-
- for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D))
- {
- if (Ent->d_name[0] == '.')
- continue;
-
- // Skip bad file names ala run-parts
- const char *C = Ent->d_name;
- for (; *C != 0; C++)
- if (isalpha(*C) == 0 && isdigit(*C) == 0 && *C != '_' && *C != '-')
- break;
- if (*C != 0)
- continue;
-
- // Make sure it is a file and not something else
- string File = flCombine(Dir,Ent->d_name);
- struct stat St;
- if (stat(File.c_str(),&St) != 0 || S_ISREG(St.st_mode) == 0)
- continue;
-
- List.push_back(File);
- }
- closedir(D);
-
- sort(List.begin(),List.end());
+ vector<string> const List = GetListOfFilesInDir(Dir, "", true);
// Read the files
for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++)
diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc
index 4b3abe918..929259961 100644
--- a/apt-pkg/sourcelist.cc
+++ b/apt-pkg/sourcelist.cc
@@ -17,13 +17,6 @@
#include <apti18n.h>
#include <fstream>
-
-// CNC:2003-03-03 - This is needed for ReadDir stuff.
-#include <algorithm>
-#include <stdio.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <unistd.h>
/*}}}*/
using namespace std;
@@ -322,41 +315,7 @@ bool pkgSourceList::GetIndexes(pkgAcquire *Owner, bool GetAll) const
/* */
bool pkgSourceList::ReadSourceDir(string Dir)
{
- DIR *D = opendir(Dir.c_str());
- if (D == 0)
- return _error->Errno("opendir",_("Unable to read %s"),Dir.c_str());
-
- vector<string> List;
-
- for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D))
- {
- if (Ent->d_name[0] == '.')
- continue;
-
- // CNC:2003-12-02 Only accept .list files as valid sourceparts
- if (flExtension(Ent->d_name) != "list")
- continue;
-
- // Skip bad file names ala run-parts
- const char *C = Ent->d_name;
- for (; *C != 0; C++)
- if (isalpha(*C) == 0 && isdigit(*C) == 0
- && *C != '_' && *C != '-' && *C != '.')
- break;
- if (*C != 0)
- continue;
-
- // Make sure it is a file and not something else
- string File = flCombine(Dir,Ent->d_name);
- struct stat St;
- if (stat(File.c_str(),&St) != 0 || S_ISREG(St.st_mode) == 0)
- continue;
-
- List.push_back(File);
- }
- closedir(D);
-
- sort(List.begin(),List.end());
+ vector<string> const List = GetListOfFilesInDir(Dir, "list", true);
// Read the files
for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++)