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/aptconfiguration.cc2
-rw-r--r--apt-pkg/cdrom.cc5
-rw-r--r--apt-pkg/contrib/cdromutl.cc51
-rw-r--r--apt-pkg/contrib/configuration.cc43
-rw-r--r--apt-pkg/contrib/error.h29
-rw-r--r--apt-pkg/contrib/fileutl.cc124
-rw-r--r--apt-pkg/contrib/fileutl.h8
-rw-r--r--apt-pkg/contrib/hashes.cc4
-rw-r--r--apt-pkg/contrib/macros.h (renamed from apt-pkg/contrib/system.h)16
-rw-r--r--apt-pkg/contrib/md5.cc3
-rw-r--r--apt-pkg/contrib/netrc.cc211
-rw-r--r--apt-pkg/contrib/netrc.h29
-rw-r--r--apt-pkg/contrib/sha1.cc2
-rw-r--r--apt-pkg/contrib/strutl.cc49
-rw-r--r--apt-pkg/deb/debindexfile.cc30
-rw-r--r--apt-pkg/deb/deblistparser.cc3
-rw-r--r--apt-pkg/deb/dpkgpm.cc11
-rw-r--r--apt-pkg/depcache.cc8
-rw-r--r--apt-pkg/indexcopy.cc10
-rw-r--r--apt-pkg/init.cc2
-rw-r--r--apt-pkg/init.h2
-rw-r--r--apt-pkg/makefile10
-rw-r--r--apt-pkg/packagemanager.cc10
-rw-r--r--apt-pkg/pkgcache.cc2
-rw-r--r--apt-pkg/pkgcachegen.cc67
-rw-r--r--apt-pkg/policy.cc37
-rw-r--r--apt-pkg/sourcelist.cc43
28 files changed, 640 insertions, 233 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index 10e80eb56..4f0abbb91 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/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc
index 1ec526646..0fe84db74 100644
--- a/apt-pkg/aptconfiguration.cc
+++ b/apt-pkg/aptconfiguration.cc
@@ -11,7 +11,7 @@
#include <apt-pkg/fileutl.h>
#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/configuration.h>
-#include <system.h>
+#include <apt-pkg/macros.h>
#include <vector>
#include <string>
diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc
index 271bca409..83165c6c0 100644
--- a/apt-pkg/cdrom.cc
+++ b/apt-pkg/cdrom.cc
@@ -821,8 +821,6 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
}
}
-
-
// Unmount and finish
if (_config->FindB("APT::CDROM::NoMount",false) == false) {
log->Update(_("Unmounting CD-ROM...\n"), STEP_LAST);
@@ -913,6 +911,7 @@ pkgUdevCdromDevices::Scan() /*{{{*/
pkgUdevCdromDevices::~pkgUdevCdromDevices() /*{{{*/
{
- dlclose(libudev_handle);
+ if (libudev_handle != NULL)
+ dlclose(libudev_handle);
}
/*}}}*/
diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc
index 0cf9697ac..6dce82fe1 100644
--- a/apt-pkg/contrib/cdromutl.cc
+++ b/apt-pkg/contrib/cdromutl.cc
@@ -64,35 +64,44 @@ bool UnmountCdrom(string Path)
{
if (IsMounted(Path) == false)
return true;
-
- int Child = ExecFork();
- // The child
- if (Child == 0)
+ for (int i=0;i<3;i++)
{
- // Make all the fds /dev/null
- for (int I = 0; I != 3; I++)
- dup2(open("/dev/null",O_RDWR),I);
+
+ int Child = ExecFork();
- if (_config->Exists("Acquire::cdrom::"+Path+"::UMount") == true)
+ // The child
+ if (Child == 0)
{
- if (system(_config->Find("Acquire::cdrom::"+Path+"::UMount").c_str()) != 0)
+ // Make all the fds /dev/null
+ for (int I = 0; I != 3; I++)
+ dup2(open("/dev/null",O_RDWR),I);
+
+ if (_config->Exists("Acquire::cdrom::"+Path+"::UMount") == true)
+ {
+ if (system(_config->Find("Acquire::cdrom::"+Path+"::UMount").c_str()) != 0)
+ _exit(100);
+ _exit(0);
+ }
+ else
+ {
+ const char *Args[10];
+ Args[0] = "umount";
+ Args[1] = Path.c_str();
+ Args[2] = 0;
+ execvp(Args[0],(char **)Args);
_exit(100);
- _exit(0);
+ }
}
- else
- {
- const char *Args[10];
- Args[0] = "umount";
- Args[1] = Path.c_str();
- Args[2] = 0;
- execvp(Args[0],(char **)Args);
- _exit(100);
- }
+
+ // if it can not be umounted, give it a bit more time
+ // this can happen when auto-mount magic or fs/cdrom prober attack
+ if (ExecWait(Child,"umount",true) == true)
+ return true;
+ sleep(1);
}
- // Wait for mount
- return ExecWait(Child,"umount",true);
+ return false;
}
/*}}}*/
// MountCdrom - Mount a cdrom /*{{{*/
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index ff49ce857..7588b041c 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,10 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool const &AsSectio
// ReadConfigDir - Read a directory of config files /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool ReadConfigDir(Configuration &Conf,const string &Dir,bool const &AsSectional,
- unsigned const &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());
+bool ReadConfigDir(Configuration &Conf,const string &Dir,
+ bool const &AsSectional, unsigned const &Depth)
+{
+ vector<string> const List = GetListOfFilesInDir(Dir, "conf", true, true);
// Read the files
for (vector<string>::const_iterator I = List.begin(); I != List.end(); I++)
diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h
index d92e40e9c..90747ff7e 100644
--- a/apt-pkg/contrib/error.h
+++ b/apt-pkg/contrib/error.h
@@ -40,27 +40,15 @@
#ifndef PKGLIB_ERROR_H
#define PKGLIB_ERROR_H
+#include <apt-pkg/macros.h>
-
-#ifdef __GNUG__
-// Methods have a hidden this parameter that is visible to this attribute
-#define APT_MFORMAT1 __attribute__ ((format (printf, 2, 3)))
-#define APT_MFORMAT2 __attribute__ ((format (printf, 3, 4)))
-#else
-#define APT_MFORMAT1
-#define APT_MFORMAT2
-#endif
-
#include <string>
-#include <system.h>
-
-using std::string;
class GlobalError
{
struct Item
{
- string Text;
+ std::string Text;
bool Error;
Item *Next;
};
@@ -72,18 +60,18 @@ class GlobalError
public:
// Call to generate an error from a library call.
- bool Errno(const char *Function,const char *Description,...) APT_MFORMAT2 __cold;
- bool WarningE(const char *Function,const char *Description,...) APT_MFORMAT2 __cold;
+ bool Errno(const char *Function,const char *Description,...) __like_printf_2 __cold;
+ bool WarningE(const char *Function,const char *Description,...) __like_printf_2 __cold;
/* A warning should be considered less severe than an error, and may be
ignored by the client. */
- bool Error(const char *Description,...) APT_MFORMAT1 __cold;
- bool Warning(const char *Description,...) APT_MFORMAT1 __cold;
+ bool Error(const char *Description,...) __like_printf_1 __cold;
+ bool Warning(const char *Description,...) __like_printf_1 __cold;
// Simple accessors
inline bool PendingError() {return PendingFlag;};
inline bool empty() {return List == 0;};
- bool PopMessage(string &Text);
+ bool PopMessage(std::string &Text);
void Discard();
// Usefull routine to dump to cerr
@@ -96,7 +84,4 @@ class GlobalError
GlobalError *_GetErrorObj();
#define _error _GetErrorObj()
-#undef APT_MFORMAT1
-#undef APT_MFORMAT2
-
#endif
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 4240d9f49..da32983f1 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,128 @@ 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)
+{
+ return GetListOfFilesInDir(Dir, Ext, SortList, false);
+}
+std::vector<string> GetListOfFilesInDir(string const &Dir, string const &Ext,
+ bool const &SortList, bool const &AllowNoExt)
+{
+ std::vector<string> ext;
+ ext.reserve(2);
+ if (Ext.empty() == false)
+ ext.push_back(Ext);
+ if (AllowNoExt == true && ext.empty() == false)
+ ext.push_back("");
+ return GetListOfFilesInDir(Dir, ext, SortList);
+}
+std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<string> const &Ext,
+ bool const &SortList)
+{
+ // Attention debuggers: need to be set with the environment config file!
+ bool const Debug = _config->FindB("Debug::GetListOfFilesInDir", false);
+ if (Debug == true)
+ {
+ std::clog << "Accept in " << Dir << " only files with the following " << Ext.size() << " extensions:" << std::endl;
+ if (Ext.empty() == true)
+ std::clog << "\tNO extension" << std::endl;
+ else
+ for (std::vector<string>::const_iterator e = Ext.begin();
+ e != Ext.end(); ++e)
+ std::clog << '\t' << (e->empty() == true ? "NO" : *e) << " extension" << std::endl;
+ }
+
+ 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))
+ {
+ // skip "hidden" files
+ if (Ent->d_name[0] == '.')
+ continue;
+
+ // check for accepted extension:
+ // no extension given -> periods are bad as hell!
+ // extensions given -> "" extension allows no extension
+ if (Ext.empty() == false)
+ {
+ string d_ext = flExtension(Ent->d_name);
+ if (d_ext == Ent->d_name) // no extension
+ {
+ if (std::find(Ext.begin(), Ext.end(), "") == Ext.end())
+ {
+ if (Debug == true)
+ std::clog << "Bad file: " << Ent->d_name << " → no extension" << std::endl;
+ continue;
+ }
+ }
+ else if (std::find(Ext.begin(), Ext.end(), d_ext) == Ext.end())
+ {
+ if (Debug == true)
+ std::clog << "Bad file: " << Ent->d_name << " → bad extension »" << flExtension(Ent->d_name) << "«" << std::endl;
+ continue;
+ }
+ }
+
+ // Skip bad filenames ala run-parts
+ const char *C = Ent->d_name;
+ for (; *C != 0; ++C)
+ if (isalpha(*C) == 0 && isdigit(*C) == 0
+ && *C != '_' && *C != '-') {
+ // no required extension -> dot is a bad character
+ if (*C == '.' && Ext.empty() == false)
+ continue;
+ break;
+ }
+
+ // we don't reach the end of the name -> bad character included
+ if (*C != 0)
+ {
+ if (Debug == true)
+ std::clog << "Bad file: " << Ent->d_name << " → bad character »"
+ << *C << "« in filename (period allowed: " << (Ext.empty() ? "no" : "yes") << ")" << std::endl;
+ continue;
+ }
+
+ // skip filenames which end with a period. These are never valid
+ if (*(C - 1) == '.')
+ {
+ if (Debug == true)
+ std::clog << "Bad file: " << Ent->d_name << " → Period as last character" << std::endl;
+ 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)
+ {
+ if (Debug == true)
+ std::clog << "Bad file: " << Ent->d_name << " → stat says not a good file" << std::endl;
+ continue;
+ }
+
+ if (Debug == true)
+ std::clog << "Accept file: " << Ent->d_name << " in " << Dir << std::endl;
+ 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..85a94898c 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,13 @@ bool RunScripts(const char *Cnf);
bool CopyFile(FileFd &From,FileFd &To);
int GetLock(string File,bool Errors = true);
bool FileExists(string File);
+// FIXME: next ABI-Break: merge the two method-headers
+std::vector<string> GetListOfFilesInDir(string const &Dir, string const &Ext,
+ bool const &SortList);
+std::vector<string> GetListOfFilesInDir(string const &Dir, string const &Ext,
+ bool const &SortList, bool const &AllowNoExt);
+std::vector<string> GetListOfFilesInDir(string const &Dir, std::vector<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/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc
index b43771ea7..985d89d90 100644
--- a/apt-pkg/contrib/hashes.cc
+++ b/apt-pkg/contrib/hashes.cc
@@ -14,9 +14,9 @@
#include <apt-pkg/hashes.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/configuration.h>
-
+#include <apt-pkg/macros.h>
+
#include <unistd.h>
-#include <system.h>
#include <string>
#include <iostream>
/*}}}*/
diff --git a/apt-pkg/contrib/system.h b/apt-pkg/contrib/macros.h
index f68df6265..c39caf198 100644
--- a/apt-pkg/contrib/system.h
+++ b/apt-pkg/contrib/macros.h
@@ -1,9 +1,8 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: system.h,v 1.3 1999/12/10 23:40:29 jgg Exp $
/* ######################################################################
- System Header - Usefull private definitions
+ Macros Header - Various useful macro definitions
This source is placed in the Public Domain, do with it what you will
It was originally written by Brian C. White.
@@ -11,8 +10,8 @@
##################################################################### */
/*}}}*/
// Private header
-#ifndef SYSTEM_H
-#define SYSTEM_H
+#ifndef MACROS_H
+#define MACROS_H
// MIN_VAL(SINT16) will return -0x8000 and MAX_VAL(SINT16) = 0x7FFF
#define MIN_VAL(t) (((t)(-1) > 0) ? (t)( 0) : (t)(((1L<<(sizeof(t)*8-1)) )))
@@ -77,4 +76,13 @@
#define __cold /* no cold marker */
#endif
+#ifdef __GNUG__
+// Methods have a hidden this parameter that is visible to this attribute
+ #define __like_printf_1 __attribute__ ((format (printf, 2, 3)))
+ #define __like_printf_2 __attribute__ ((format (printf, 3, 4)))
+#else
+ #define __like_printf_1 /* no like-printf */
+ #define __like_printf_2 /* no like-printf */
+#endif
+
#endif
diff --git a/apt-pkg/contrib/md5.cc b/apt-pkg/contrib/md5.cc
index 2bfd70f1b..c0fa8493d 100644
--- a/apt-pkg/contrib/md5.cc
+++ b/apt-pkg/contrib/md5.cc
@@ -37,14 +37,13 @@
// Include Files /*{{{*/
#include <apt-pkg/md5.h>
#include <apt-pkg/strutl.h>
+#include <apt-pkg/macros.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h> // For htonl
#include <inttypes.h>
#include <config.h>
-#include <system.h>
-
/*}}}*/
// byteSwap - Swap bytes in a buffer /*{{{*/
diff --git a/apt-pkg/contrib/netrc.cc b/apt-pkg/contrib/netrc.cc
new file mode 100644
index 000000000..d8027fc24
--- /dev/null
+++ b/apt-pkg/contrib/netrc.cc
@@ -0,0 +1,211 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: netrc.c,v 1.38 2007-11-07 09:21:35 bagder Exp $
+/* ######################################################################
+
+ netrc file parser - returns the login and password of a give host in
+ a specified netrc-type file
+
+ Originally written by Daniel Stenberg, <daniel@haxx.se>, et al. and
+ placed into the Public Domain, do with it what you will.
+
+ ##################################################################### */
+ /*}}}*/
+
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/fileutl.h>
+#include <iostream>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <pwd.h>
+
+#include "netrc.h"
+
+
+/* Get user and password from .netrc when given a machine name */
+
+enum {
+ NOTHING,
+ HOSTFOUND, /* the 'machine' keyword was found */
+ HOSTCOMPLETE, /* the machine name following the keyword was found too */
+ HOSTVALID, /* this is "our" machine! */
+ HOSTEND /* LAST enum */
+};
+
+/* make sure we have room for at least this size: */
+#define LOGINSIZE 64
+#define PASSWORDSIZE 64
+#define NETRC DOT_CHAR "netrc"
+
+/* returns -1 on failure, 0 if the host is found, 1 is the host isn't found */
+int parsenetrc (char *host, char *login, char *password, char *netrcfile = NULL)
+{
+ FILE *file;
+ int retcode = 1;
+ int specific_login = (login[0] != 0);
+ char *home = NULL;
+ bool netrc_alloc = false;
+ int state = NOTHING;
+
+ char state_login = 0; /* Found a login keyword */
+ char state_password = 0; /* Found a password keyword */
+ int state_our_login = false; /* With specific_login,
+ found *our* login name */
+
+ if (!netrcfile) {
+ home = getenv ("HOME"); /* portable environment reader */
+
+ if (!home) {
+ struct passwd *pw;
+ pw = getpwuid (geteuid ());
+ if(pw)
+ home = pw->pw_dir;
+ }
+
+ if (!home)
+ return -1;
+
+ asprintf (&netrcfile, "%s%s%s", home, DIR_CHAR, NETRC);
+ if(!netrcfile)
+ return -1;
+ else
+ netrc_alloc = true;
+ }
+
+ file = fopen (netrcfile, "r");
+ if(file) {
+ char *tok;
+ char *tok_buf;
+ bool done = false;
+ char netrcbuffer[256];
+
+ while (!done && fgets(netrcbuffer, sizeof (netrcbuffer), file)) {
+ tok = strtok_r (netrcbuffer, " \t\n", &tok_buf);
+ while (!done && tok) {
+ if(login[0] && password[0]) {
+ done = true;
+ break;
+ }
+
+ switch(state) {
+ case NOTHING:
+ if (!strcasecmp ("machine", tok)) {
+ /* the next tok is the machine name, this is in itself the
+ delimiter that starts the stuff entered for this machine,
+ after this we need to search for 'login' and
+ 'password'. */
+ state = HOSTFOUND;
+ }
+ break;
+ case HOSTFOUND:
+ /* extended definition of a "machine" if we have a "/"
+ we match the start of the string (host.startswith(token) */
+ if ((strchr(host, '/') && strstr(host, tok) == host) ||
+ (!strcasecmp (host, tok))) {
+ /* and yes, this is our host! */
+ state = HOSTVALID;
+ retcode = 0; /* we did find our host */
+ }
+ else
+ /* not our host */
+ state = NOTHING;
+ break;
+ case HOSTVALID:
+ /* we are now parsing sub-keywords concerning "our" host */
+ if (state_login) {
+ if (specific_login)
+ state_our_login = !strcasecmp (login, tok);
+ else
+ strncpy (login, tok, LOGINSIZE - 1);
+ state_login = 0;
+ } else if (state_password) {
+ if (state_our_login || !specific_login)
+ strncpy (password, tok, PASSWORDSIZE - 1);
+ state_password = 0;
+ } else if (!strcasecmp ("login", tok))
+ state_login = 1;
+ else if (!strcasecmp ("password", tok))
+ state_password = 1;
+ else if(!strcasecmp ("machine", tok)) {
+ /* ok, there's machine here go => */
+ state = HOSTFOUND;
+ state_our_login = false;
+ }
+ break;
+ } /* switch (state) */
+
+ tok = strtok_r (NULL, " \t\n", &tok_buf);
+ } /* while(tok) */
+ } /* while fgets() */
+
+ fclose(file);
+ }
+
+ if (netrc_alloc)
+ free(netrcfile);
+
+ return retcode;
+}
+
+void maybe_add_auth (URI &Uri, string NetRCFile)
+{
+ if (_config->FindB("Debug::Acquire::netrc", false) == true)
+ std::clog << "maybe_add_auth: " << (string)Uri
+ << " " << NetRCFile << std::endl;
+ if (Uri.Password.empty () == true || Uri.User.empty () == true)
+ {
+ if (NetRCFile.empty () == false)
+ {
+ char login[64] = "";
+ char password[64] = "";
+ char *netrcfile = strdupa (NetRCFile.c_str ());
+
+ // first check for a generic host based netrc entry
+ char *host = strdupa (Uri.Host.c_str ());
+ if (host && parsenetrc (host, login, password, netrcfile) == 0)
+ {
+ if (_config->FindB("Debug::Acquire::netrc", false) == true)
+ std::clog << "host: " << host
+ << " user: " << login
+ << " pass-size: " << strlen(password)
+ << std::endl;
+ Uri.User = string (login);
+ Uri.Password = string (password);
+ return;
+ }
+
+ // if host did not work, try Host+Path next, this will trigger
+ // a lookup uri.startswith(host) in the netrc file parser (because
+ // of the "/"
+ char *hostpath = strdupa (string(Uri.Host+Uri.Path).c_str ());
+ if (hostpath && parsenetrc (hostpath, login, password, netrcfile) == 0)
+ {
+ if (_config->FindB("Debug::Acquire::netrc", false) == true)
+ std::clog << "hostpath: " << hostpath
+ << " user: " << login
+ << " pass-size: " << strlen(password)
+ << std::endl;
+ Uri.User = string (login);
+ Uri.Password = string (password);
+ return;
+ }
+ }
+ }
+}
+
+#ifdef DEBUG
+int main(int argc, char* argv[])
+{
+ char login[64] = "";
+ char password[64] = "";
+
+ if(argc < 2)
+ return -1;
+
+ if(0 == parsenetrc (argv[1], login, password, argv[2])) {
+ printf("HOST: %s LOGIN: %s PASSWORD: %s\n", argv[1], login, password);
+ }
+}
+#endif
diff --git a/apt-pkg/contrib/netrc.h b/apt-pkg/contrib/netrc.h
new file mode 100644
index 000000000..02a5eb09f
--- /dev/null
+++ b/apt-pkg/contrib/netrc.h
@@ -0,0 +1,29 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: netrc.h,v 1.11 2004/01/07 09:19:35 bagder Exp $
+/* ######################################################################
+
+ netrc file parser - returns the login and password of a give host in
+ a specified netrc-type file
+
+ Originally written by Daniel Stenberg, <daniel@haxx.se>, et al. and
+ placed into the Public Domain, do with it what you will.
+
+ ##################################################################### */
+ /*}}}*/
+#ifndef NETRC_H
+#define NETRC_H
+
+#include <apt-pkg/strutl.h>
+
+#define DOT_CHAR "."
+#define DIR_CHAR "/"
+
+// Assume: password[0]=0, host[0] != 0.
+// If login[0] = 0, search for login and password within a machine section
+// in the netrc.
+// If login[0] != 0, search for password within machine and login.
+int parsenetrc (char *host, char *login, char *password, char *filename);
+
+void maybe_add_auth (URI &Uri, string NetRCFile);
+#endif
diff --git a/apt-pkg/contrib/sha1.cc b/apt-pkg/contrib/sha1.cc
index b70f31dc6..eae52d52f 100644
--- a/apt-pkg/contrib/sha1.cc
+++ b/apt-pkg/contrib/sha1.cc
@@ -31,12 +31,12 @@
// Include Files /*{{{*/
#include <apt-pkg/sha1.h>
#include <apt-pkg/strutl.h>
+#include <apt-pkg/macros.h>
#include <string.h>
#include <unistd.h>
#include <inttypes.h>
#include <config.h>
-#include <system.h>
/*}}}*/
// SHA1Transform - Alters an existing SHA-1 hash /*{{{*/
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index bed51881f..b285a9f2e 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -43,9 +43,10 @@ bool UTF8ToCodeset(const char *codeset, const string &orig, string *dest)
{
iconv_t cd;
const char *inbuf;
- char *inptr, *outbuf, *outptr;
- size_t insize, outsize;
-
+ char *inptr, *outbuf;
+ size_t insize, bufsize;
+ dest->clear();
+
cd = iconv_open(codeset, "UTF-8");
if (cd == (iconv_t)(-1)) {
// Something went wrong
@@ -55,33 +56,49 @@ bool UTF8ToCodeset(const char *codeset, const string &orig, string *dest)
else
perror("iconv_open");
- // Clean the destination string
- *dest = "";
-
return false;
}
- insize = outsize = orig.size();
+ insize = bufsize = orig.size();
inbuf = orig.data();
inptr = (char *)inbuf;
- outbuf = new char[insize+1];
- outptr = outbuf;
+ outbuf = new char[bufsize];
+ size_t lastError = -1;
while (insize != 0)
{
+ char *outptr = outbuf;
+ size_t outsize = bufsize;
size_t const err = iconv(cd, &inptr, &insize, &outptr, &outsize);
+ dest->append(outbuf, outptr - outbuf);
if (err == (size_t)(-1))
{
- insize--;
- outsize++;
- inptr++;
- *outptr = '?';
- outptr++;
+ switch (errno)
+ {
+ case EILSEQ:
+ insize--;
+ inptr++;
+ // replace a series of unknown multibytes with a single "?"
+ if (lastError != insize) {
+ lastError = insize - 1;
+ dest->append("?");
+ }
+ break;
+ case EINVAL:
+ insize = 0;
+ break;
+ case E2BIG:
+ if (outptr == outbuf)
+ {
+ bufsize *= 2;
+ delete[] outbuf;
+ outbuf = new char[bufsize];
+ }
+ break;
+ }
}
}
- *outptr = '\0';
- *dest = outbuf;
delete[] outbuf;
iconv_close(cd);
diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc
index 73d72c729..bb8fae7cb 100644
--- a/apt-pkg/deb/debindexfile.cc
+++ b/apt-pkg/deb/debindexfile.cc
@@ -313,9 +313,19 @@ pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const
struct stat St;
if (stat(File.FileName(),&St) != 0)
+ {
+ if (_config->FindB("Debug::pkgCacheGen", false))
+ std::clog << "PackagesIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
return pkgCache::PkgFileIterator(Cache);
+ }
if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
+ {
+ if (_config->FindB("Debug::pkgCacheGen", false))
+ std::clog << "PackagesIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
+ << ") or mtime (" << St.st_mtime << " <> " << File->mtime
+ << ") doesn't match for " << File.FileName() << std::endl;
return pkgCache::PkgFileIterator(Cache);
+ }
return File;
}
@@ -480,9 +490,19 @@ pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) con
struct stat St;
if (stat(File.FileName(),&St) != 0)
+ {
+ if (_config->FindB("Debug::pkgCacheGen", false))
+ std::clog << "TranslationIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
return pkgCache::PkgFileIterator(Cache);
+ }
if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
+ {
+ if (_config->FindB("Debug::pkgCacheGen", false))
+ std::clog << "TranslationIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
+ << ") or mtime (" << St.st_mtime << " <> " << File->mtime
+ << ") doesn't match for " << File.FileName() << std::endl;
return pkgCache::PkgFileIterator(Cache);
+ }
return File;
}
return File;
@@ -549,9 +569,19 @@ pkgCache::PkgFileIterator debStatusIndex::FindInCache(pkgCache &Cache) const
struct stat St;
if (stat(File.FileName(),&St) != 0)
+ {
+ if (_config->FindB("Debug::pkgCacheGen", false))
+ std::clog << "StatusIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
return pkgCache::PkgFileIterator(Cache);
+ }
if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
+ {
+ if (_config->FindB("Debug::pkgCacheGen", false))
+ std::clog << "StatusIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
+ << ") or mtime (" << St.st_mtime << " <> " << File->mtime
+ << ") doesn't match for " << File.FileName() << std::endl;
return pkgCache::PkgFileIterator(Cache);
+ }
return File;
}
return File;
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index 1948aedf3..bfc0e762e 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -17,10 +17,9 @@
#include <apt-pkg/strutl.h>
#include <apt-pkg/crc-16.h>
#include <apt-pkg/md5.h>
+#include <apt-pkg/macros.h>
#include <ctype.h>
-
-#include <system.h>
/*}}}*/
static debListParser::WordList PrioList[] = {{"important",pkgCache::State::Important},
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index adaf362fa..565f01b84 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -49,6 +49,7 @@ namespace
std::make_pair("install", N_("Installing %s")),
std::make_pair("configure", N_("Configuring %s")),
std::make_pair("remove", N_("Removing %s")),
+ std::make_pair("purge", N_("Completely removing %s")),
std::make_pair("trigproc", N_("Running post-installation trigger %s"))
};
@@ -560,15 +561,16 @@ bool pkgDPkgPM::OpenLog()
if (!logfile_name.empty())
{
term_out = fopen(logfile_name.c_str(),"a");
+ if (term_out == NULL)
+ return _error->WarningE(_("Could not open file '%s'"), logfile_name.c_str());
+
chmod(logfile_name.c_str(), 0600);
// output current time
char outstr[200];
time_t t = time(NULL);
struct tm *tmp = localtime(&t);
strftime(outstr, sizeof(outstr), "%F %T", tmp);
- fprintf(term_out, "\nLog started: ");
- fprintf(term_out, "%s", outstr);
- fprintf(term_out, "\n");
+ fprintf(term_out, "\nLog started: %s\n", outstr);
}
return true;
}
@@ -878,7 +880,8 @@ bool pkgDPkgPM::Go(int OutStatusFd)
const char *s = _("Can not write log, openpty() "
"failed (/dev/pts not mounted?)\n");
fprintf(stderr, "%s",s);
- fprintf(term_out, "%s",s);
+ if(term_out)
+ fprintf(term_out, "%s",s);
master = slave = -1;
} else {
struct termios rtt;
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc
index e817adb77..eeb74a434 100644
--- a/apt-pkg/depcache.cc
+++ b/apt-pkg/depcache.cc
@@ -193,10 +193,10 @@ bool pkgDepCache::readStateFile(OpProgress *Prog) /*{{{*/
Prog->OverallProgress(amt, file_size, 1,
_("Reading state information"));
}
- if(Prog != NULL)
- Prog->OverallProgress(file_size, file_size, 1,
- _("Reading state information"));
}
+ if(Prog != NULL)
+ Prog->OverallProgress(file_size, file_size, 1,
+ _("Reading state information"));
}
return true;
@@ -244,7 +244,7 @@ bool pkgDepCache::writeStateFile(OpProgress *prog, bool InstalledOnly) /*{{{*/
continue;
bool newAuto = (PkgState[pkg->ID].Flags & Flag::Auto);
if(_config->FindB("Debug::pkgAutoRemove",false))
- std::clog << "Update exisiting AutoInstall info: "
+ std::clog << "Update existing AutoInstall info: "
<< pkg.Name() << std::endl;
TFRewriteData rewrite[2];
rewrite[0].Tag = "Auto-Installed";
diff --git a/apt-pkg/indexcopy.cc b/apt-pkg/indexcopy.cc
index 0142d7dbe..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;
@@ -527,19 +527,19 @@ bool SigVerify::Verify(string prefix, string file, indexRecords *MetaIndex)
// (non-existing files are not considered a error)
if(!FileExists(prefix+file))
{
- _error->Warning("Skipping non-exisiting file %s", string(prefix+file).c_str());
+ _error->Warning(_("Skipping nonexistent file %s"), string(prefix+file).c_str());
return true;
}
if (!Record)
{
- _error->Warning("Can't find authentication record for: %s",file.c_str());
+ _error->Warning(_("Can't find authentication record for: %s"), file.c_str());
return false;
}
if (!Record->Hash.VerifyFile(prefix+file))
{
- _error->Warning("Hash mismatch for: %s",file.c_str());
+ _error->Warning(_("Hash mismatch for: %s"),file.c_str());
return false;
}
@@ -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/init.cc b/apt-pkg/init.cc
index 15efb1a3d..d8c201b9d 100644
--- a/apt-pkg/init.cc
+++ b/apt-pkg/init.cc
@@ -65,10 +65,12 @@ bool pkgInitConfig(Configuration &Cnf)
Cnf.Set("Dir::Etc::vendorlist","vendors.list");
Cnf.Set("Dir::Etc::vendorparts","vendors.list.d");
Cnf.Set("Dir::Etc::main","apt.conf");
+ Cnf.Set("Dir::Etc::netrc", "auth.conf");
Cnf.Set("Dir::Etc::parts","apt.conf.d");
Cnf.Set("Dir::Etc::preferences","preferences");
Cnf.Set("Dir::Etc::preferencesparts","preferences.d");
Cnf.Set("Dir::Bin::methods","/usr/lib/apt/methods");
+ Cnf.Set("Dir::Media::MountPath","/media/apt");
// State
Cnf.Set("Dir::Log","var/log/apt");
diff --git a/apt-pkg/init.h b/apt-pkg/init.h
index b3e4b147f..f0757f644 100644
--- a/apt-pkg/init.h
+++ b/apt-pkg/init.h
@@ -22,7 +22,7 @@
// Non-ABI-Breaks should only increase RELEASE number.
// See also buildlib/libversion.mak
#define APT_PKG_MAJOR 4
-#define APT_PKG_MINOR 9
+#define APT_PKG_MINOR 8
#define APT_PKG_RELEASE 0
extern const char *pkgVersion;
diff --git a/apt-pkg/makefile b/apt-pkg/makefile
index f71367ace..bdd49c089 100644
--- a/apt-pkg/makefile
+++ b/apt-pkg/makefile
@@ -21,10 +21,11 @@ APT_DOMAIN:=libapt-pkg$(LIBAPTPKG_MAJOR)
SOURCE = contrib/mmap.cc contrib/error.cc contrib/strutl.cc \
contrib/configuration.cc contrib/progress.cc contrib/cmndline.cc \
contrib/md5.cc contrib/sha1.cc contrib/sha256.cc contrib/hashes.cc \
- contrib/cdromutl.cc contrib/crc-16.cc \
+ contrib/cdromutl.cc contrib/crc-16.cc contrib/netrc.cc \
contrib/fileutl.cc
-HEADERS = mmap.h error.h configuration.h fileutl.h cmndline.h \
- md5.h crc-16.h cdromutl.h strutl.h sptr.h sha1.h sha256.h hashes.h
+HEADERS = mmap.h error.h configuration.h fileutl.h cmndline.h netrc.h\
+ md5.h crc-16.h cdromutl.h strutl.h sptr.h sha1.h sha256.h hashes.h \
+ macros.h
# Source code for the core main library
SOURCE+= pkgcache.cc version.cc depcache.cc \
@@ -53,7 +54,4 @@ HEADERS+= debversion.h debsrcrecords.h dpkgpm.h debrecords.h \
HEADERS := $(addprefix apt-pkg/,$(HEADERS))
-# Private header files
-HEADERS+= system.h
-
include $(LIBRARY_H)
diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc
index 08e7fc00f..db882721e 100644
--- a/apt-pkg/packagemanager.cc
+++ b/apt-pkg/packagemanager.cc
@@ -298,6 +298,9 @@ bool pkgPackageManager::ConfigureAll()
of it's dependents. */
bool pkgPackageManager::SmartConfigure(PkgIterator Pkg)
{
+ if (Debug == true)
+ clog << "SmartConfigure " << Pkg.Name() << endl;
+
pkgOrderList OList(&Cache);
if (DepAdd(OList,Pkg) == false)
@@ -499,6 +502,9 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
while (End->Type == pkgCache::Dep::PreDepends)
{
+ if (Debug == true)
+ clog << "PreDepends order for " << Pkg.Name() << std::endl;
+
// Look for possible ok targets.
SPtrArray<Version *> VList = Start.AllTargets();
bool Bad = true;
@@ -512,6 +518,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
Pkg.State() == PkgIterator::NeedsNothing)
{
Bad = false;
+ if (Debug == true)
+ clog << "Found ok package " << Pkg.Name() << endl;
continue;
}
}
@@ -527,6 +535,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
(Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing))
continue;
+ if (Debug == true)
+ clog << "Trying to SmartConfigure " << Pkg.Name() << endl;
Bad = !SmartConfigure(Pkg);
}
diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc
index d4268b31c..29c27b58e 100644
--- a/apt-pkg/pkgcache.cc
+++ b/apt-pkg/pkgcache.cc
@@ -27,6 +27,7 @@
#include <apt-pkg/strutl.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/aptconfiguration.h>
+#include <apt-pkg/macros.h>
#include <apti18n.h>
@@ -35,7 +36,6 @@
#include <unistd.h>
#include <ctype.h>
-#include <system.h>
/*}}}*/
using std::string;
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index 6d103c6b6..3d1a654d1 100644
--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -22,6 +22,7 @@
#include <apt-pkg/strutl.h>
#include <apt-pkg/sptr.h>
#include <apt-pkg/pkgsystem.h>
+#include <apt-pkg/macros.h>
#include <apt-pkg/tagfile.h>
@@ -33,7 +34,6 @@
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
-#include <system.h>
/*}}}*/
typedef vector<pkgIndexFile *>::iterator FileIterator;
@@ -808,16 +808,23 @@ unsigned long pkgCacheGenerator::WriteUniqString(const char *S,
static bool CheckValidity(const string &CacheFile, FileIterator Start,
FileIterator End,MMap **OutMap = 0)
{
+ bool const Debug = _config->FindB("Debug::pkgCacheGen", false);
// No file, certainly invalid
if (CacheFile.empty() == true || FileExists(CacheFile) == false)
+ {
+ if (Debug == true)
+ std::clog << "CacheFile doesn't exist" << std::endl;
return false;
-
+ }
+
// Map it
FileFd CacheF(CacheFile,FileFd::ReadOnly);
SPtr<MMap> Map = new MMap(CacheF,0);
pkgCache Cache(Map);
if (_error->PendingError() == true || Map->Size() == 0)
{
+ if (Debug == true)
+ std::clog << "Errors are pending or Map is empty()" << std::endl;
_error->Discard();
return false;
}
@@ -827,9 +834,15 @@ static bool CheckValidity(const string &CacheFile, FileIterator Start,
SPtrArray<bool> Visited = new bool[Cache.HeaderP->PackageFileCount];
memset(Visited,0,sizeof(*Visited)*Cache.HeaderP->PackageFileCount);
for (; Start != End; Start++)
- {
+ {
+ if (Debug == true)
+ std::clog << "Checking PkgFile " << (*Start)->Describe() << ": ";
if ((*Start)->HasPackages() == false)
+ {
+ if (Debug == true)
+ std::clog << "Has NO packages" << std::endl;
continue;
+ }
if ((*Start)->Exists() == false)
{
@@ -837,23 +850,40 @@ static bool CheckValidity(const string &CacheFile, FileIterator Start,
_error->WarningE("stat",_("Couldn't stat source package list %s"),
(*Start)->Describe().c_str());
#endif
+ if (Debug == true)
+ std::clog << "file doesn't exist" << std::endl;
continue;
}
// FindInCache is also expected to do an IMS check.
pkgCache::PkgFileIterator File = (*Start)->FindInCache(Cache);
if (File.end() == true)
+ {
+ if (Debug == true)
+ std::clog << "FindInCache returned end-Pointer" << std::endl;
return false;
+ }
Visited[File->ID] = true;
+ if (Debug == true)
+ std::clog << "with ID " << File->ID << " is valid" << std::endl;
}
for (unsigned I = 0; I != Cache.HeaderP->PackageFileCount; I++)
if (Visited[I] == false)
+ {
+ if (Debug == true)
+ std::clog << "File with ID" << I << " wasn't visited" << std::endl;
return false;
+ }
if (_error->PendingError() == true)
{
+ if (Debug == true)
+ {
+ std::clog << "Validity failed because of pending errors:" << std::endl;
+ _error->DumpErrors();
+ }
_error->Discard();
return false;
}
@@ -940,7 +970,8 @@ static bool BuildCache(pkgCacheGenerator &Gen,
bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
MMap **OutMap,bool AllowMem)
{
- unsigned long MapSize = _config->FindI("APT::Cache-Limit",24*1024*1024);
+ bool const Debug = _config->FindB("Debug::pkgCacheGen", false);
+ unsigned long const MapSize = _config->FindI("APT::Cache-Limit",24*1024*1024);
vector<pkgIndexFile *> Files;
for (vector<metaIndex *>::const_iterator i = List.begin();
@@ -954,13 +985,13 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
Files.push_back (*j);
}
- unsigned long EndOfSource = Files.size();
+ unsigned long const EndOfSource = Files.size();
if (_system->AddStatusFiles(Files) == false)
return false;
// Decide if we can write to the files..
- string CacheFile = _config->FindFile("Dir::Cache::pkgcache");
- string SrcCacheFile = _config->FindFile("Dir::Cache::srcpkgcache");
+ string const CacheFile = _config->FindFile("Dir::Cache::pkgcache");
+ string const SrcCacheFile = _config->FindFile("Dir::Cache::srcpkgcache");
// Decide if we can write to the cache
bool Writeable = false;
@@ -969,7 +1000,9 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
else
if (SrcCacheFile.empty() == false)
Writeable = access(flNotFile(SrcCacheFile).c_str(),W_OK) == 0;
-
+ if (Debug == true)
+ std::clog << "Do we have write-access to the cache files? " << (Writeable ? "YES" : "NO") << std::endl;
+
if (Writeable == false && AllowMem == false && CacheFile.empty() == false)
return _error->Error(_("Unable to write to %s"),flNotFile(CacheFile).c_str());
@@ -979,8 +1012,12 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
if (CheckValidity(CacheFile,Files.begin(),Files.end(),OutMap) == true)
{
Progress.OverallProgress(1,1,1,_("Reading package lists"));
+ if (Debug == true)
+ std::clog << "pkgcache.bin is valid - no need to build anything" << std::endl;
return true;
}
+ else if (Debug == true)
+ std::clog << "pkgcache.bin is NOT valid" << std::endl;
/* At this point we know we need to reconstruct the package cache,
begin. */
@@ -994,11 +1031,15 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
Map = new DynamicMMap(*CacheF,MMap::Public,MapSize);
if (_error->PendingError() == true)
return false;
+ if (Debug == true)
+ std::clog << "Open filebased MMap" << std::endl;
}
else
{
// Just build it in memory..
Map = new DynamicMMap(0,MapSize);
+ if (Debug == true)
+ std::clog << "Open memory Map (not filebased)" << std::endl;
}
// Lets try the source cache.
@@ -1007,16 +1048,18 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
if (CheckValidity(SrcCacheFile,Files.begin(),
Files.begin()+EndOfSource) == true)
{
+ if (Debug == true)
+ std::clog << "srcpkgcache.bin is valid - populate MMap with it." << std::endl;
// Preload the map with the source cache
FileFd SCacheF(SrcCacheFile,FileFd::ReadOnly);
- unsigned long alloc = Map->RawAllocate(SCacheF.Size());
+ unsigned long const alloc = Map->RawAllocate(SCacheF.Size());
if ((alloc == 0 && _error->PendingError())
|| SCacheF.Read((unsigned char *)Map->Data() + alloc,
SCacheF.Size()) == false)
return false;
TotalSize = ComputeSize(Files.begin()+EndOfSource,Files.end());
-
+
// Build the status cache
pkgCacheGenerator Gen(Map.Get(),&Progress);
if (_error->PendingError() == true)
@@ -1030,6 +1073,8 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
}
else
{
+ if (Debug == true)
+ std::clog << "srcpkgcache.bin is NOT valid - rebuild" << std::endl;
TotalSize = ComputeSize(Files.begin(),Files.end());
// Build the source cache
@@ -1071,6 +1116,8 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
// FIXME: move me to a better place
Gen.FinishCache(Progress);
}
+ if (Debug == true)
+ std::clog << "Caches are ready for shipping" << std::endl;
if (_error->PendingError() == true)
return false;
diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc
index 81fdb0431..f9901bc9a 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, "pref", true, 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 6b7a299d6..a860c7eac 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;
@@ -331,41 +324,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++)