summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2011-12-19 14:07:51 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2011-12-19 14:07:51 +0100
commit27da8141d21cfbfc29675510737ee05bdfd4a2b1 (patch)
tree008e311e4c24dbfce3f47643d962cfa67a333a68 /apt-pkg
parent386566e36bedb453eb6f914e8e14fd555a2bf111 (diff)
parent6fd947bd48449652edf783cfb1362391e63f9be1 (diff)
merged from lp:~donkult/apt/experimental
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/acquire-item.h8
-rw-r--r--apt-pkg/acquire-method.h5
-rw-r--r--apt-pkg/acquire.h5
-rw-r--r--apt-pkg/algorithms.h5
-rw-r--r--apt-pkg/cachefile.h6
-rw-r--r--apt-pkg/cacheset.h4
-rw-r--r--apt-pkg/cdrom.cc158
-rw-r--r--apt-pkg/cdrom.h5
-rw-r--r--apt-pkg/contrib/cdromutl.h4
-rw-r--r--apt-pkg/contrib/cmndline.h4
-rw-r--r--apt-pkg/contrib/configuration.h4
-rw-r--r--apt-pkg/contrib/fileutl.cc506
-rw-r--r--apt-pkg/contrib/fileutl.h71
-rw-r--r--apt-pkg/contrib/hashes.h6
-rw-r--r--apt-pkg/contrib/hashsum_template.h5
-rw-r--r--apt-pkg/contrib/md5.h5
-rw-r--r--apt-pkg/contrib/mmap.cc22
-rw-r--r--apt-pkg/contrib/mmap.h5
-rw-r--r--apt-pkg/contrib/netrc.h4
-rw-r--r--apt-pkg/contrib/progress.h4
-rw-r--r--apt-pkg/contrib/sha1.h5
-rw-r--r--apt-pkg/contrib/strutl.h6
-rw-r--r--apt-pkg/deb/debindexfile.cc32
-rw-r--r--apt-pkg/deb/deblistparser.cc1
-rw-r--r--apt-pkg/deb/deblistparser.h4
-rw-r--r--apt-pkg/deb/debmetaindex.h4
-rw-r--r--apt-pkg/deb/debrecords.cc2
-rw-r--r--apt-pkg/deb/debrecords.h4
-rw-r--r--apt-pkg/deb/debsrcrecords.h2
-rw-r--r--apt-pkg/deb/dpkgpm.h5
-rw-r--r--apt-pkg/depcache.h5
-rw-r--r--apt-pkg/edsp.h5
-rw-r--r--apt-pkg/edsp/edspindexfile.cc11
-rw-r--r--apt-pkg/edsp/edspindexfile.h4
-rw-r--r--apt-pkg/edsp/edsplistparser.h6
-rw-r--r--apt-pkg/indexcopy.cc175
-rw-r--r--apt-pkg/indexcopy.h5
-rw-r--r--apt-pkg/indexfile.h4
-rw-r--r--apt-pkg/indexrecords.h4
-rw-r--r--apt-pkg/init.h5
-rw-r--r--apt-pkg/metaindex.h7
-rw-r--r--apt-pkg/packagemanager.h5
-rw-r--r--apt-pkg/pkgcache.h5
-rw-r--r--apt-pkg/pkgcachegen.cc16
-rw-r--r--apt-pkg/pkgsystem.h4
-rw-r--r--apt-pkg/policy.h4
-rw-r--r--apt-pkg/sourcelist.h28
-rw-r--r--apt-pkg/srcrecords.cc8
-rw-r--r--apt-pkg/srcrecords.h5
-rw-r--r--apt-pkg/tagfile.h4
-rw-r--r--apt-pkg/vendor.h4
-rw-r--r--apt-pkg/vendorlist.h7
-rw-r--r--apt-pkg/version.h4
-rw-r--r--apt-pkg/versionmatch.h4
54 files changed, 901 insertions, 329 deletions
diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h
index 27b8e887b..51d539450 100644
--- a/apt-pkg/acquire-item.h
+++ b/apt-pkg/acquire-item.h
@@ -25,6 +25,14 @@
#include <apt-pkg/weakptr.h>
#include <apt-pkg/pkgcache.h>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/indexfile.h>
+#include <apt-pkg/vendor.h>
+#include <apt-pkg/sourcelist.h>
+#include <apt-pkg/pkgrecords.h>
+#include <apt-pkg/indexrecords.h>
+#endif
+
/** \addtogroup acquire
* @{
*
diff --git a/apt-pkg/acquire-method.h b/apt-pkg/acquire-method.h
index c3f042ee0..2dd9ad685 100644
--- a/apt-pkg/acquire-method.h
+++ b/apt-pkg/acquire-method.h
@@ -25,6 +25,11 @@
#include <string>
#include <vector>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/strutl.h>
+#endif
+
class Hashes;
class pkgAcqMethod
{
diff --git a/apt-pkg/acquire.h b/apt-pkg/acquire.h
index 93772403d..3d5d7a4b7 100644
--- a/apt-pkg/acquire.h
+++ b/apt-pkg/acquire.h
@@ -75,6 +75,11 @@
#include <sys/time.h>
#include <unistd.h>
+#ifndef APT_8_CLEANER_HEADERS
+using std::vector;
+using std::string;
+#endif
+
class pkgAcquireStatus;
/** \brief The core download scheduler. {{{
diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h
index 948fe1103..185d11e96 100644
--- a/apt-pkg/algorithms.h
+++ b/apt-pkg/algorithms.h
@@ -36,6 +36,11 @@
#include <iostream>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/acquire.h>
+using std::ostream;
+#endif
+
class pkgAcquireStatus;
class pkgSimulate : public pkgPackageManager /*{{{*/
diff --git a/apt-pkg/cachefile.h b/apt-pkg/cachefile.h
index b56e42855..802b12b61 100644
--- a/apt-pkg/cachefile.h
+++ b/apt-pkg/cachefile.h
@@ -20,6 +20,12 @@
#include <apt-pkg/depcache.h>
#include <apt-pkg/macros.h>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/acquire.h>
+#include <apt-pkg/policy.h>
+#include <apt-pkg/sourcelist.h>
+#endif
+
class pkgPolicy;
class pkgSourceList;
class OpProgress;
diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h
index d1e396e0f..91d7eec1c 100644
--- a/apt-pkg/cacheset.h
+++ b/apt-pkg/cacheset.h
@@ -20,6 +20,10 @@
#include <apt-pkg/error.h>
#include <apt-pkg/pkgcache.h>
+
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/cachefile.h>
+#endif
/*}}}*/
class pkgCacheFile;
diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc
index 07983e44f..4462d4e24 100644
--- a/apt-pkg/cdrom.cc
+++ b/apt-pkg/cdrom.cc
@@ -58,23 +58,21 @@ bool pkgCdrom::FindPackages(string CD,
return _error->Errno("chdir","Unable to change to %s",CD.c_str());
// Look for a .disk subdirectory
- struct stat Buf;
- if (stat(".disk",&Buf) == 0)
+ if (DirectoryExists(".disk") == true)
{
if (InfoDir.empty() == true)
InfoDir = CD + ".disk/";
}
// Don't look into directories that have been marked to ingore.
- if (stat(".aptignr",&Buf) == 0)
+ if (RealFileExists(".aptignr") == true)
return true;
-
/* Check _first_ for a signature file as apt-cdrom assumes that all files
under a Packages/Source file are in control of that file and stops
the scanning
*/
- if (stat("Release.gpg",&Buf) == 0)
+ if (RealFileExists("Release.gpg") == true || RealFileExists("InRelease") == true)
{
SigList.push_back(CD);
}
@@ -82,66 +80,69 @@ bool pkgCdrom::FindPackages(string CD,
/* Aha! We found some package files. We assume that everything under
this dir is controlled by those package files so we don't look down
anymore */
- std::vector<std::string> types = APT::Configuration::getCompressionTypes();
- types.push_back("");
- for (std::vector<std::string>::const_iterator t = types.begin();
- t != types.end(); ++t)
- {
- std::string filename = std::string("Packages");
- if ((*t).size() > 0)
- filename.append("."+*t);
- if (stat(filename.c_str(), &Buf) == 0)
- {
- List.push_back(CD);
-
- // Continue down if thorough is given
- if (_config->FindB("APT::CDROM::Thorough",false) == false)
- return true;
- break;
- }
- }
- for (std::vector<std::string>::const_iterator t = types.begin();
- t != types.end(); ++t)
- {
- std::string filename = std::string("Sources");
- if ((*t).size() > 0)
- filename.append("."+*t);
- {
- SList.push_back(CD);
-
- // Continue down if thorough is given
- if (_config->FindB("APT::CDROM::Thorough",false) == false)
- return true;
- break;
- }
- }
+ std::vector<APT::Configuration::Compressor> const compressor = APT::Configuration::getCompressors();
+ for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
+ c != compressor.end(); ++c)
+ {
+ if (RealFileExists(std::string("Packages").append(c->Extension).c_str()) == false)
+ continue;
+
+ if (_config->FindB("Debug::aptcdrom",false) == true)
+ std::clog << "Found Packages in " << CD << std::endl;
+ List.push_back(CD);
- // see if we find translatin indexes
- if (stat("i18n",&Buf) == 0)
+ // Continue down if thorough is given
+ if (_config->FindB("APT::CDROM::Thorough",false) == false)
+ return true;
+ break;
+ }
+ for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
+ c != compressor.end(); ++c)
+ {
+ if (RealFileExists(std::string("Sources").append(c->Extension).c_str()) == false)
+ continue;
+
+ if (_config->FindB("Debug::aptcdrom",false) == true)
+ std::clog << "Found Sources in " << CD << std::endl;
+ SList.push_back(CD);
+
+ // Continue down if thorough is given
+ if (_config->FindB("APT::CDROM::Thorough",false) == false)
+ return true;
+ break;
+ }
+
+ // see if we find translation indices
+ if (DirectoryExists("i18n") == true)
{
D = opendir("i18n");
for (struct dirent *Dir = readdir(D); Dir != 0; Dir = readdir(D))
{
- if(strstr(Dir->d_name,"Translation") != NULL)
+ if(strncmp(Dir->d_name, "Translation-", strlen("Translation-")) != 0)
+ continue;
+ string file = Dir->d_name;
+ for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
+ c != compressor.end(); ++c)
{
- if (_config->FindB("Debug::aptcdrom",false) == true)
- std::clog << "found translations: " << Dir->d_name << "\n";
- string file = Dir->d_name;
- for (std::vector<std::string>::const_iterator t = types.begin();
- t != types.end(); ++t)
- {
- std::string needle = "." + *t;
- if(file.substr(file.size()-needle.size()) == needle)
- file = file.substr(0, file.size()-needle.size());
- TransList.push_back(CD+"i18n/"+ file);
- break;
- }
+ string fileext = flExtension(file);
+ if (file == fileext)
+ fileext.clear();
+ else if (fileext.empty() == false)
+ fileext = "." + fileext;
+
+ if (c->Extension == fileext)
+ {
+ if (_config->FindB("Debug::aptcdrom",false) == true)
+ std::clog << "Found translation " << Dir->d_name << " in " << CD << "i18n/" << std::endl;
+ file.erase(file.size() - fileext.size());
+ TransList.push_back(CD + "i18n/" + file);
+ break;
+ }
}
}
closedir(D);
}
-
D = opendir(".");
if (D == 0)
return _error->Errno("opendir","Unable to read %s",CD.c_str());
@@ -276,38 +277,43 @@ bool pkgCdrom::DropBinaryArch(vector<string> &List)
/* Here we go and stat every file that we found and strip dup inodes. */
bool pkgCdrom::DropRepeats(vector<string> &List,const char *Name)
{
+ bool couldFindAllFiles = true;
// Get a list of all the inodes
ino_t *Inodes = new ino_t[List.size()];
- for (unsigned int I = 0; I != List.size(); I++)
+ for (unsigned int I = 0; I != List.size(); ++I)
{
struct stat Buf;
- std::vector<std::string> types = APT::Configuration::getCompressionTypes();
- types.push_back("");
- for (std::vector<std::string>::const_iterator t = types.begin();
- t != types.end(); ++t)
+ bool found = false;
+
+ std::vector<APT::Configuration::Compressor> const compressor = APT::Configuration::getCompressors();
+ for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
+ c != compressor.end(); ++c)
{
- std::string filename = List[I] + Name;
- if ((*t).size() > 0)
- filename.append("." + *t);
+ std::string filename = std::string(List[I]).append(Name).append(c->Extension);
if (stat(filename.c_str(), &Buf) != 0)
- _error->Errno("stat","Failed to stat %s%s",List[I].c_str(),
- Name);
- Inodes[I] = Buf.st_ino;
+ continue;
+ Inodes[I] = Buf.st_ino;
+ found = true;
+ break;
+ }
+
+ if (found == false)
+ {
+ _error->Errno("stat","Failed to stat %s%s",List[I].c_str(), Name);
+ couldFindAllFiles = false;
+ Inodes[I] = 0;
}
}
-
- if (_error->PendingError() == true) {
- delete[] Inodes;
- return false;
- }
-
+
// Look for dups
for (unsigned int I = 0; I != List.size(); I++)
{
+ if (Inodes[I] == 0)
+ continue;
for (unsigned int J = I+1; J < List.size(); J++)
{
// No match
- if (Inodes[J] != Inodes[I])
+ if (Inodes[J] == 0 || Inodes[J] != Inodes[I])
continue;
// We score the two paths.. and erase one
@@ -333,7 +339,7 @@ bool pkgCdrom::DropRepeats(vector<string> &List,const char *Name)
List.erase(List.begin()+I);
}
- return true;
+ return couldFindAllFiles;
}
/*}}}*/
// ReduceSourceList - Takes the path list and reduces it /*{{{*/
@@ -712,7 +718,13 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/
DropBinaryArch(List);
DropRepeats(List,"Packages");
DropRepeats(SourceList,"Sources");
+ // FIXME: We ignore stat() errors here as we usually have only one of those in use
+ // This has little potencial to drop 'valid' stat() errors as we know that one of these
+ // files need to exist, but it would be better if we would check it here
+ _error->PushToStack();
DropRepeats(SigList,"Release.gpg");
+ DropRepeats(SigList,"InRelease");
+ _error->RevertToStack();
DropRepeats(TransList,"");
if(log != NULL) {
msg.str("");
diff --git a/apt-pkg/cdrom.h b/apt-pkg/cdrom.h
index 319254fd0..cedfccff7 100644
--- a/apt-pkg/cdrom.h
+++ b/apt-pkg/cdrom.h
@@ -4,6 +4,11 @@
#include<string>
#include<vector>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/init.h>
+using namespace std;
+#endif
+
class Configuration;
class OpProgress;
diff --git a/apt-pkg/contrib/cdromutl.h b/apt-pkg/contrib/cdromutl.h
index 2c6afac0f..e94045b5c 100644
--- a/apt-pkg/contrib/cdromutl.h
+++ b/apt-pkg/contrib/cdromutl.h
@@ -12,6 +12,10 @@
#include <string>
+#ifndef APT_8_CLEANER_HEADERS
+using std::string;
+#endif
+
// mount cdrom, DeviceName (e.g. /dev/sr0) is optional
bool MountCdrom(std::string Path, std::string DeviceName="");
bool UnmountCdrom(std::string Path);
diff --git a/apt-pkg/contrib/cmndline.h b/apt-pkg/contrib/cmndline.h
index b201d9855..9f505fd41 100644
--- a/apt-pkg/contrib/cmndline.h
+++ b/apt-pkg/contrib/cmndline.h
@@ -44,6 +44,10 @@
#ifndef PKGLIB_CMNDLINE_H
#define PKGLIB_CMNDLINE_H
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/configuration.h>
+#endif
+
class Configuration;
class CommandLine
diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h
index f6f2a3c1d..4c2e75041 100644
--- a/apt-pkg/contrib/configuration.h
+++ b/apt-pkg/contrib/configuration.h
@@ -34,6 +34,10 @@
#include <vector>
#include <iostream>
+#ifndef APT_8_CLEANER_HEADERS
+using std::string;
+#endif
+
class Configuration
{
public:
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 95058cbde..a98c2cb85 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -24,6 +24,7 @@
#include <apt-pkg/strutl.h>
#include <apt-pkg/error.h>
#include <apt-pkg/sptr.h>
+#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/configuration.h>
#include <cstdlib>
@@ -43,6 +44,16 @@
#include <set>
#include <algorithm>
+// FIXME: Compressor Fds have some speed disadvantages and are a bit buggy currently,
+// so while the current implementation satisfies the testcases it is not a real option
+// to disable it for now
+#define APT_USE_ZLIB 1
+#if APT_USE_ZLIB
+#include <zlib.h>
+#else
+#pragma message "Usage of zlib is DISABLED!"
+#endif
+
#ifdef WORDS_BIGENDIAN
#include <inttypes.h>
#endif
@@ -52,6 +63,21 @@
using namespace std;
+class FileFdPrivate {
+ public:
+#if APT_USE_ZLIB
+ gzFile gz;
+#else
+ void* gz;
+#endif
+ int compressed_fd;
+ pid_t compressor_pid;
+ bool pipe;
+ APT::Configuration::Compressor compressor;
+ unsigned int openmode;
+ FileFdPrivate() : gz(NULL), compressed_fd(-1), compressor_pid(-1), pipe(false) {};
+};
+
// RunScripts - Run a set of scripts from a configuration subtree /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -718,85 +744,288 @@ bool ExecWait(pid_t Pid,const char *Name,bool Reap)
// FileFd::Open - Open a file /*{{{*/
// ---------------------------------------------------------------------
/* The most commonly used open mode combinations are given with Mode */
-bool FileFd::Open(string FileName,OpenMode Mode, unsigned long Perms)
+bool FileFd::Open(string FileName,unsigned int const Mode,CompressMode Compress, unsigned long const Perms)
{
- Close();
- Flags = AutoClose;
- switch (Mode)
+ if (Mode == ReadOnlyGzip)
+ return Open(FileName, ReadOnly, Gzip, Perms);
+
+ if (Compress == Auto && (Mode & WriteOnly) == WriteOnly)
+ return _error->Error("Autodetection on %s only works in ReadOnly openmode!", FileName.c_str());
+
+ // FIXME: Denote inbuilt compressors somehow - as we don't need to have the binaries for them
+ std::vector<APT::Configuration::Compressor> const compressors = APT::Configuration::getCompressors();
+ std::vector<APT::Configuration::Compressor>::const_iterator compressor = compressors.begin();
+ if (Compress == Auto)
{
- case ReadOnly:
- iFd = open(FileName.c_str(),O_RDONLY);
- break;
-
- case ReadOnlyGzip:
- iFd = open(FileName.c_str(),O_RDONLY);
- if (iFd > 0) {
- gz = gzdopen (iFd, "r");
- if (gz == NULL) {
- close (iFd);
- iFd = -1;
- }
- }
- break;
-
- case WriteAtomic:
+ for (; compressor != compressors.end(); ++compressor)
{
- Flags |= Replace;
- char *name = strdup((FileName + ".XXXXXX").c_str());
- TemporaryFileName = string(mktemp(name));
- iFd = open(TemporaryFileName.c_str(),O_RDWR | O_CREAT | O_EXCL,Perms);
- free(name);
+ std::string file = std::string(FileName).append(compressor->Extension);
+ if (FileExists(file) == false)
+ continue;
+ FileName = file;
break;
}
-
- case WriteEmpty:
+ }
+ else if (Compress == Extension)
+ {
+ std::string::size_type const found = FileName.find_last_of('.');
+ std::string ext;
+ if (found != std::string::npos)
{
- struct stat Buf;
- if (lstat(FileName.c_str(),&Buf) == 0 && S_ISLNK(Buf.st_mode))
- unlink(FileName.c_str());
- iFd = open(FileName.c_str(),O_RDWR | O_CREAT | O_TRUNC,Perms);
- break;
+ ext = FileName.substr(found);
+ if (ext == ".new" || ext == ".bak")
+ {
+ std::string::size_type const found2 = FileName.find_last_of('.', found - 1);
+ if (found2 != std::string::npos)
+ ext = FileName.substr(found2, found - found2);
+ else
+ ext.clear();
+ }
}
-
- case WriteExists:
- iFd = open(FileName.c_str(),O_RDWR);
- break;
+ for (; compressor != compressors.end(); ++compressor)
+ if (ext == compressor->Extension)
+ break;
+ // no matching extension - assume uncompressed (imagine files like 'example.org_Packages')
+ if (compressor == compressors.end())
+ for (compressor = compressors.begin(); compressor != compressors.end(); ++compressor)
+ if (compressor->Name == ".")
+ break;
+ }
+ else
+ {
+ std::string name;
+ switch (Compress)
+ {
+ case None: name = "."; break;
+ case Gzip: name = "gzip"; break;
+ case Bzip2: name = "bzip2"; break;
+ case Lzma: name = "lzma"; break;
+ case Xz: name = "xz"; break;
+ case Auto:
+ case Extension:
+ // Unreachable
+ return _error->Error("Opening File %s in None, Auto or Extension should be already handled?!?", FileName.c_str());
+ }
+ for (; compressor != compressors.end(); ++compressor)
+ if (compressor->Name == name)
+ break;
+ if (compressor == compressors.end())
+ return _error->Error("Can't find a configured compressor %s for file %s", name.c_str(), FileName.c_str());
+ }
- case WriteAny:
- iFd = open(FileName.c_str(),O_RDWR | O_CREAT,Perms);
- break;
+ if (compressor == compressors.end())
+ return _error->Error("Can't find a match for specified compressor mode for file %s", FileName.c_str());
+ return Open(FileName, Mode, *compressor, Perms);
+}
+bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Compressor const &compressor, unsigned long const Perms)
+{
+ Close();
+ d = new FileFdPrivate;
+ d->openmode = Mode;
+ Flags = AutoClose;
+
+ if ((Mode & WriteOnly) != WriteOnly && (Mode & (Atomic | Create | Empty | Exclusive)) != 0)
+ return _error->Error("ReadOnly mode for %s doesn't accept additional flags!", FileName.c_str());
+ if ((Mode & ReadWrite) == 0)
+ return _error->Error("No openmode provided in FileFd::Open for %s", FileName.c_str());
- case WriteTemp:
+ if ((Mode & Atomic) == Atomic)
+ {
+ Flags |= Replace;
+ char *name = strdup((FileName + ".XXXXXX").c_str());
+ TemporaryFileName = string(mktemp(name));
+ free(name);
+ }
+ else if ((Mode & (Exclusive | Create)) == (Exclusive | Create))
+ {
+ // for atomic, this will be done by rename in Close()
unlink(FileName.c_str());
- iFd = open(FileName.c_str(),O_RDWR | O_CREAT | O_EXCL,Perms);
- break;
- }
+ }
+ if ((Mode & Empty) == Empty)
+ {
+ struct stat Buf;
+ if (lstat(FileName.c_str(),&Buf) == 0 && S_ISLNK(Buf.st_mode))
+ unlink(FileName.c_str());
+ }
+
+ int fileflags = 0;
+ #define if_FLAGGED_SET(FLAG, MODE) if ((Mode & FLAG) == FLAG) fileflags |= MODE
+ if_FLAGGED_SET(ReadWrite, O_RDWR);
+ else if_FLAGGED_SET(ReadOnly, O_RDONLY);
+ else if_FLAGGED_SET(WriteOnly, O_WRONLY);
+
+ if_FLAGGED_SET(Create, O_CREAT);
+ if_FLAGGED_SET(Empty, O_TRUNC);
+ if_FLAGGED_SET(Exclusive, O_EXCL);
+ else if_FLAGGED_SET(Atomic, O_EXCL);
+ #undef if_FLAGGED_SET
+
+ if (TemporaryFileName.empty() == false)
+ iFd = open(TemporaryFileName.c_str(), fileflags, Perms);
+ else
+ iFd = open(FileName.c_str(), fileflags, Perms);
+
+ if (iFd == -1 || OpenInternDescriptor(Mode, compressor) == false)
+ {
+ if (iFd != -1)
+ {
+ close (iFd);
+ iFd = -1;
+ }
+ return _error->Errno("open",_("Could not open file %s"), FileName.c_str());
+ }
- if (iFd < 0)
- return _error->Errno("open",_("Could not open file %s"),FileName.c_str());
-
this->FileName = FileName;
SetCloseExec(iFd,true);
return true;
}
+ /*}}}*/
+// FileFd::OpenDescriptor - Open a filedescriptor /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, CompressMode Compress, bool AutoClose)
+{
+ std::vector<APT::Configuration::Compressor> const compressors = APT::Configuration::getCompressors();
+ std::vector<APT::Configuration::Compressor>::const_iterator compressor = compressors.begin();
+ std::string name;
+ switch (Compress)
+ {
+ case None: name = "."; break;
+ case Gzip: name = "gzip"; break;
+ case Bzip2: name = "bzip2"; break;
+ case Lzma: name = "lzma"; break;
+ case Xz: name = "xz"; break;
+ case Auto:
+ case Extension:
+ return _error->Error("Opening Fd %d in Auto or Extension compression mode is not supported", Fd);
+ }
+ for (; compressor != compressors.end(); ++compressor)
+ if (compressor->Name == name)
+ break;
+ if (compressor == compressors.end())
+ return _error->Error("Can't find a configured compressor %s for file %s", name.c_str(), FileName.c_str());
-bool FileFd::OpenDescriptor(int Fd, OpenMode Mode, bool AutoClose)
+ return OpenDescriptor(Fd, Mode, *compressor, AutoClose);
+}
+bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration::Compressor const &compressor, bool AutoClose)
{
Close();
+ d = new FileFdPrivate;
+ d->openmode = Mode;
Flags = (AutoClose) ? FileFd::AutoClose : 0;
iFd = Fd;
- if (Mode == ReadOnlyGzip) {
- gz = gzdopen (iFd, "r");
- if (gz == NULL) {
- if (AutoClose)
- close (iFd);
- return _error->Errno("gzdopen",_("Could not open file descriptor %d"),
- Fd);
- }
+ if (OpenInternDescriptor(Mode, compressor) == false)
+ {
+ if (AutoClose)
+ close (iFd);
+ return _error->Errno("gzdopen",_("Could not open file descriptor %d"), Fd);
}
this->FileName = "";
return true;
}
+bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor)
+{
+ d->compressor = compressor;
+ if (compressor.Name == "." || compressor.Binary.empty() == true)
+ return true;
+#if APT_USE_ZLIB
+ else if (compressor.Name == "gzip")
+ {
+ if ((Mode & ReadWrite) == ReadWrite)
+ d->gz = gzdopen(iFd, "r+");
+ else if ((Mode & WriteOnly) == WriteOnly)
+ d->gz = gzdopen(iFd, "w");
+ else
+ d->gz = gzdopen (iFd, "r");
+ if (d->gz == NULL)
+ return false;
+ Flags |= Compressed;
+ return true;
+ }
+#endif
+
+ if ((Mode & ReadWrite) == ReadWrite)
+ return _error->Error("ReadWrite mode is not supported for file %s", FileName.c_str());
+
+ bool const Comp = (Mode & WriteOnly) == WriteOnly;
+ // Handle 'decompression' of empty files
+ if (Comp == false)
+ {
+ struct stat Buf;
+ fstat(iFd, &Buf);
+ if (Buf.st_size == 0 && S_ISFIFO(Buf.st_mode) == false)
+ return true;
+
+ // We don't need the file open - instead let the compressor open it
+ // as he properly knows better how to efficiently read from 'his' file
+ if (FileName.empty() == false)
+ close(iFd);
+ }
+
+ // Create a data pipe
+ int Pipe[2] = {-1,-1};
+ if (pipe(Pipe) != 0)
+ return _error->Errno("pipe",_("Failed to create subprocess IPC"));
+ for (int J = 0; J != 2; J++)
+ SetCloseExec(Pipe[J],true);
+
+ d->compressed_fd = iFd;
+ d->pipe = true;
+
+ if (Comp == true)
+ iFd = Pipe[1];
+ else
+ iFd = Pipe[0];
+
+ // The child..
+ d->compressor_pid = ExecFork();
+ if (d->compressor_pid == 0)
+ {
+ if (Comp == true)
+ {
+ dup2(d->compressed_fd,STDOUT_FILENO);
+ dup2(Pipe[0],STDIN_FILENO);
+ }
+ else
+ {
+ if (FileName.empty() == true)
+ dup2(d->compressed_fd,STDIN_FILENO);
+ dup2(Pipe[1],STDOUT_FILENO);
+ }
+
+ SetCloseExec(STDOUT_FILENO,false);
+ SetCloseExec(STDIN_FILENO,false);
+
+ std::vector<char const*> Args;
+ Args.push_back(compressor.Binary.c_str());
+ std::vector<std::string> const * const addArgs =
+ (Comp == true) ? &(compressor.CompressArgs) : &(compressor.UncompressArgs);
+ for (std::vector<std::string>::const_iterator a = addArgs->begin();
+ a != addArgs->end(); ++a)
+ Args.push_back(a->c_str());
+ if (Comp == false && FileName.empty() == false)
+ {
+ Args.push_back("--stdout");
+ if (TemporaryFileName.empty() == false)
+ Args.push_back(TemporaryFileName.c_str());
+ else
+ Args.push_back(FileName.c_str());
+ }
+ Args.push_back(NULL);
+
+ execvp(Args[0],(char **)&Args[0]);
+ cerr << _("Failed to exec compressor ") << Args[0] << endl;
+ _exit(100);
+ }
+ if (Comp == true)
+ close(Pipe[0]);
+ else
+ close(Pipe[1]);
+ if (Comp == true || FileName.empty() == true)
+ close(d->compressed_fd);
+
+ return true;
+}
/*}}}*/
// FileFd::~File - Closes the file /*{{{*/
// ---------------------------------------------------------------------
@@ -817,12 +1046,14 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual)
errno = 0;
if (Actual != 0)
*Actual = 0;
-
+ *((char *)To) = '\0';
do
{
- if (gz != NULL)
- Res = gzread(gz,To,Size);
+#if APT_USE_ZLIB
+ if (d->gz != NULL)
+ Res = gzread(d->gz,To,Size);
else
+#endif
Res = read(iFd,To,Size);
if (Res < 0 && errno == EINTR)
continue;
@@ -853,6 +1084,31 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual)
return _error->Error(_("read, still have %llu to read but none left"), Size);
}
/*}}}*/
+// FileFd::ReadLine - Read a complete line from the file /*{{{*/
+// ---------------------------------------------------------------------
+/* Beware: This method can be quiet slow for big buffers on UNcompressed
+ files because of the naive implementation! */
+char* FileFd::ReadLine(char *To, unsigned long long const Size)
+{
+ *To = '\0';
+#if APT_USE_ZLIB
+ if (d->gz != NULL)
+ return gzgets(d->gz, To, Size);
+#endif
+
+ unsigned long long read = 0;
+ if (Read(To, Size, &read) == false)
+ return NULL;
+ char* c = To;
+ for (; *c != '\n' && *c != '\0' && read != 0; --read, ++c)
+ ; // find the end of the line
+ if (*c != '\0')
+ *c = '\0';
+ if (read != 0)
+ Seek(Tell() - read);
+ return To;
+}
+ /*}}}*/
// FileFd::Write - Write to the file /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -862,9 +1118,11 @@ bool FileFd::Write(const void *From,unsigned long long Size)
errno = 0;
do
{
- if (gz != NULL)
- Res = gzwrite(gz,From,Size);
+#if APT_USE_ZLIB
+ if (d->gz != NULL)
+ Res = gzwrite(d->gz,From,Size);
else
+#endif
Res = write(iFd,From,Size);
if (Res < 0 && errno == EINTR)
continue;
@@ -891,10 +1149,38 @@ bool FileFd::Write(const void *From,unsigned long long Size)
/* */
bool FileFd::Seek(unsigned long long To)
{
+ if (d->pipe == true)
+ {
+ if ((d->openmode & ReadOnly) != ReadOnly)
+ return _error->Error("Reopen is only implemented for read-only files!");
+ close(iFd);
+ iFd = 0;
+ if (TemporaryFileName.empty() == false)
+ iFd = open(TemporaryFileName.c_str(), O_RDONLY);
+ else if (FileName.empty() == false)
+ iFd = open(FileName.c_str(), O_RDONLY);
+ else
+ {
+ if (d->compressed_fd > 0)
+ if (lseek(d->compressed_fd, 0, SEEK_SET) != 0)
+ iFd = d->compressed_fd;
+ if (iFd <= 0)
+ return _error->Error("Reopen is not implemented for pipes opened with FileFd::OpenDescriptor()!");
+ }
+
+ if (OpenInternDescriptor(d->openmode, d->compressor) == false)
+ return _error->Error("Seek on file %s because it couldn't be reopened", FileName.c_str());
+
+ if (To != 0)
+ return Skip(To);
+ return true;
+ }
int res;
- if (gz)
- res = gzseek(gz,To,SEEK_SET);
+#if APT_USE_ZLIB
+ if (d->gz)
+ res = gzseek(d->gz,To,SEEK_SET);
else
+#endif
res = lseek(iFd,To,SEEK_SET);
if (res != (signed)To)
{
@@ -911,9 +1197,11 @@ bool FileFd::Seek(unsigned long long To)
bool FileFd::Skip(unsigned long long Over)
{
int res;
- if (gz)
- res = gzseek(gz,Over,SEEK_CUR);
+#if APT_USE_ZLIB
+ if (d->gz != NULL)
+ res = gzseek(d->gz,Over,SEEK_CUR);
else
+#endif
res = lseek(iFd,Over,SEEK_CUR);
if (res < 0)
{
@@ -929,7 +1217,7 @@ bool FileFd::Skip(unsigned long long Over)
/* */
bool FileFd::Truncate(unsigned long long To)
{
- if (gz)
+ if (d->gz != NULL)
{
Flags |= Fail;
return _error->Error("Truncating gzipped files is not implemented (%s)", FileName.c_str());
@@ -949,9 +1237,11 @@ bool FileFd::Truncate(unsigned long long To)
unsigned long long FileFd::Tell()
{
off_t Res;
- if (gz)
- Res = gztell(gz);
+#if APT_USE_ZLIB
+ if (d->gz != NULL)
+ Res = gztell(d->gz);
else
+#endif
Res = lseek(iFd,0,SEEK_CUR);
if (Res == (off_t)-1)
_error->Errno("lseek","Failed to determine the current file position");
@@ -964,9 +1254,19 @@ unsigned long long FileFd::Tell()
unsigned long long FileFd::FileSize()
{
struct stat Buf;
-
- if (fstat(iFd,&Buf) != 0)
+ if (d->pipe == false && fstat(iFd,&Buf) != 0)
return _error->Errno("fstat","Unable to determine the file size");
+
+ // for compressor pipes st_size is undefined and at 'best' zero
+ if (d->pipe == true || S_ISFIFO(Buf.st_mode))
+ {
+ // we set it here, too, as we get the info here for free
+ // in theory the Open-methods should take care of it already
+ d->pipe = true;
+ if (stat(FileName.c_str(), &Buf) != 0)
+ return _error->Errno("stat","Unable to determine the file size");
+ }
+
return Buf.st_size;
}
/*}}}*/
@@ -977,10 +1277,25 @@ unsigned long long FileFd::Size()
{
unsigned long long size = FileSize();
+ // for compressor pipes st_size is undefined and at 'best' zero,
+ // so we 'read' the content and 'seek' back - see there
+ if (d->pipe == true)
+ {
+ // FIXME: If we have read first and then FileSize() the report is wrong
+ size = 0;
+ char ignore[1000];
+ unsigned long long read = 0;
+ do {
+ Read(ignore, sizeof(ignore), &read);
+ size += read;
+ } while(read != 0);
+ Seek(0);
+ }
+#if APT_USE_ZLIB
// only check gzsize if we are actually a gzip file, just checking for
- // "gz" is not sufficient as uncompressed files will be opened with
+ // "gz" is not sufficient as uncompressed files could be opened with
// gzopen in "direct" mode as well
- if (gz && !gzdirect(gz) && size > 0)
+ else if (d->gz && !gzdirect(d->gz) && size > 0)
{
/* unfortunately zlib.h doesn't provide a gzsize(), so we have to do
* this ourselves; the original (uncompressed) file size is the last 32
@@ -1004,24 +1319,58 @@ unsigned long long FileFd::Size()
return _error->Errno("lseek","Unable to seek in gzipped file");
return size;
}
+#endif
return size;
}
/*}}}*/
+// FileFd::ModificationTime - Return the time of last touch /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+time_t FileFd::ModificationTime()
+{
+ struct stat Buf;
+ if (d->pipe == false && fstat(iFd,&Buf) != 0)
+ {
+ _error->Errno("fstat","Unable to determine the modification time of file %s", FileName.c_str());
+ return 0;
+ }
+
+ // for compressor pipes st_size is undefined and at 'best' zero
+ if (d->pipe == true || S_ISFIFO(Buf.st_mode))
+ {
+ // we set it here, too, as we get the info here for free
+ // in theory the Open-methods should take care of it already
+ d->pipe = true;
+ if (stat(FileName.c_str(), &Buf) != 0)
+ {
+ _error->Errno("fstat","Unable to determine the modification time of file %s", FileName.c_str());
+ return 0;
+ }
+ }
+
+ return Buf.st_mtime;
+}
+ /*}}}*/
// FileFd::Close - Close the file if the close flag is set /*{{{*/
// ---------------------------------------------------------------------
/* */
bool FileFd::Close()
{
+ if (iFd == -1)
+ return true;
+
bool Res = true;
if ((Flags & AutoClose) == AutoClose)
{
- if (gz != NULL) {
- int const e = gzclose(gz);
+#if APT_USE_ZLIB
+ if (d != NULL && d->gz != NULL) {
+ int const e = gzclose(d->gz);
// gzdopen() on empty files always fails with "buffer error" here, ignore that
if (e != 0 && e != Z_BUF_ERROR)
Res &= _error->Errno("close",_("Problem closing the gzip file %s"), FileName.c_str());
} else
+#endif
if (iFd > 0 && close(iFd) != 0)
Res &= _error->Errno("close",_("Problem closing the file %s"), FileName.c_str());
}
@@ -1031,16 +1380,23 @@ bool FileFd::Close()
Res &= _error->Errno("rename",_("Problem renaming the file %s to %s"), TemporaryFileName.c_str(), FileName.c_str());
FileName = TemporaryFileName; // for the unlink() below.
+ TemporaryFileName.clear();
}
iFd = -1;
- gz = NULL;
if ((Flags & Fail) == Fail && (Flags & DelOnFail) == DelOnFail &&
FileName.empty() == false)
if (unlink(FileName.c_str()) != 0)
Res &= _error->WarningE("unlnk",_("Problem unlinking the file %s"), FileName.c_str());
+ if (d != NULL)
+ {
+ if (d->compressor_pid > 0)
+ ExecWait(d->compressor_pid, "FileFdCompressor", true);
+ delete d;
+ d = NULL;
+ }
return Res;
}
@@ -1057,3 +1413,5 @@ bool FileFd::Sync()
return true;
}
/*}}}*/
+
+gzFile FileFd::gzFd() { return (gzFile) d->gz; }
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index 0d0451a46..147535df1 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -22,30 +22,51 @@
#define PKGLIB_FILEUTL_H
#include <apt-pkg/macros.h>
+#include <apt-pkg/aptconfiguration.h>
#include <string>
#include <vector>
#include <zlib.h>
+#ifndef APT_8_CLEANER_HEADERS
+using std::string;
+#endif
+
/* Define this for python-apt */
#define APT_HAS_GZIP 1
+class FileFdPrivate;
class FileFd
{
protected:
int iFd;
enum LocalFlags {AutoClose = (1<<0),Fail = (1<<1),DelOnFail = (1<<2),
- HitEof = (1<<3), Replace = (1<<4) };
+ HitEof = (1<<3), Replace = (1<<4), Compressed = (1<<5) };
unsigned long Flags;
std::string FileName;
std::string TemporaryFileName;
- gzFile gz;
public:
- enum OpenMode {ReadOnly,WriteEmpty,WriteExists,WriteAny,WriteTemp,ReadOnlyGzip,
- WriteAtomic};
+ enum OpenMode {
+ ReadOnly = (1 << 0),
+ WriteOnly = (1 << 1),
+ ReadWrite = ReadOnly | WriteOnly,
+
+ Create = (1 << 2),
+ Exclusive = (1 << 3),
+ Atomic = Exclusive | (1 << 4),
+ Empty = (1 << 5),
+
+ WriteEmpty = ReadWrite | Create | Empty,
+ WriteExists = ReadWrite,
+ WriteAny = ReadWrite | Create,
+ WriteTemp = ReadWrite | Create | Exclusive,
+ ReadOnlyGzip,
+ WriteAtomic = ReadWrite | Create | Atomic
+ };
+ enum CompressMode { Auto = 'A', None = 'N', Extension = 'E', Gzip = 'G', Bzip2 = 'B', Lzma = 'L', Xz = 'X' };
inline bool Read(void *To,unsigned long long Size,bool AllowEof)
{
@@ -55,6 +76,7 @@ class FileFd
return Read(To,Size);
}
bool Read(void *To,unsigned long long Size,unsigned long long *Actual = 0);
+ char* ReadLine(char *To, unsigned long long const Size);
bool Write(const void *From,unsigned long long Size);
bool Seek(unsigned long long To);
bool Skip(unsigned long long To);
@@ -62,6 +84,7 @@ class FileFd
unsigned long long Tell();
unsigned long long Size();
unsigned long long FileSize();
+ time_t ModificationTime();
/* You want to use 'unsigned long long' if you are talking about a file
to be able to support large files (>2 or >4 GB) properly.
@@ -77,30 +100,54 @@ class FileFd
return T;
}
- bool Open(std::string FileName,OpenMode Mode,unsigned long Perms = 0666);
- bool OpenDescriptor(int Fd, OpenMode Mode, bool AutoClose=false);
+ bool Open(std::string FileName,unsigned int const Mode,CompressMode Compress,unsigned long const Perms = 0666);
+ bool Open(std::string FileName,unsigned int const Mode,APT::Configuration::Compressor const &compressor,unsigned long const Perms = 0666);
+ inline bool Open(std::string const &FileName,unsigned int const Mode, unsigned long const Perms = 0666) {
+ return Open(FileName, Mode, None, Perms);
+ };
+ bool OpenDescriptor(int Fd, unsigned int const Mode, CompressMode Compress, bool AutoClose=false);
+ bool OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration::Compressor const &compressor, bool AutoClose=false);
+ inline bool OpenDescriptor(int Fd, unsigned int const Mode, bool AutoClose=false) {
+ return OpenDescriptor(Fd, Mode, None, AutoClose);
+ };
bool Close();
bool Sync();
// Simple manipulators
inline int Fd() {return iFd;};
inline void Fd(int fd) {iFd = fd;};
- inline gzFile gzFd() {return gz;};
+ __deprecated gzFile gzFd();
+
inline bool IsOpen() {return iFd >= 0;};
inline bool Failed() {return (Flags & Fail) == Fail;};
inline void EraseOnFailure() {Flags |= DelOnFail;};
inline void OpFail() {Flags |= Fail;};
inline bool Eof() {return (Flags & HitEof) == HitEof;};
+ inline bool IsCompressed() {return (Flags & Compressed) == Compressed;};
inline std::string &Name() {return FileName;};
- FileFd(std::string FileName,OpenMode Mode,unsigned long Perms = 0666) : iFd(-1),
- Flags(0), gz(NULL)
+ FileFd(std::string FileName,unsigned int const Mode,unsigned long Perms = 0666) : iFd(-1), Flags(0), d(NULL)
{
- Open(FileName,Mode,Perms);
+ Open(FileName,Mode, None, Perms);
+ };
+ FileFd(std::string FileName,unsigned int const Mode, CompressMode Compress, unsigned long Perms = 0666) : iFd(-1), Flags(0), d(NULL)
+ {
+ Open(FileName,Mode, Compress, Perms);
+ };
+ FileFd() : iFd(-1), Flags(AutoClose), d(NULL) {};
+ FileFd(int const Fd, unsigned int const Mode = ReadWrite, CompressMode Compress = None) : iFd(-1), Flags(0), d(NULL)
+ {
+ OpenDescriptor(Fd, Mode, Compress);
+ };
+ FileFd(int const Fd, bool const AutoClose) : iFd(-1), Flags(0), d(NULL)
+ {
+ OpenDescriptor(Fd, ReadWrite, None, AutoClose);
};
- FileFd(int Fd = -1) : iFd(Fd), Flags(AutoClose), gz(NULL) {};
- FileFd(int Fd,bool) : iFd(Fd), Flags(0), gz(NULL) {};
virtual ~FileFd();
+
+ private:
+ FileFdPrivate* d;
+ bool OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor);
};
bool RunScripts(const char *Cnf);
diff --git a/apt-pkg/contrib/hashes.h b/apt-pkg/contrib/hashes.h
index 81851dede..b206eccb8 100644
--- a/apt-pkg/contrib/hashes.h
+++ b/apt-pkg/contrib/hashes.h
@@ -22,6 +22,12 @@
#include <vector>
#include <cstring>
+
+#ifndef APT_8_CLEANER_HEADERS
+using std::min;
+using std::vector;
+#endif
+
// helper class that contains hash function name
// and hash
class HashString
diff --git a/apt-pkg/contrib/hashsum_template.h b/apt-pkg/contrib/hashsum_template.h
index 27d192b82..6301ac9d0 100644
--- a/apt-pkg/contrib/hashsum_template.h
+++ b/apt-pkg/contrib/hashsum_template.h
@@ -15,6 +15,11 @@
#include <algorithm>
#include <stdint.h>
+#ifndef APT_8_CLEANER_HEADERS
+using std::string;
+using std::min;
+#endif
+
template<int N>
class HashSumValue
{
diff --git a/apt-pkg/contrib/md5.h b/apt-pkg/contrib/md5.h
index a207da4e4..25631b166 100644
--- a/apt-pkg/contrib/md5.h
+++ b/apt-pkg/contrib/md5.h
@@ -31,6 +31,11 @@
#include "hashsum_template.h"
+#ifndef APT_8_CLEANER_HEADERS
+using std::string;
+using std::min;
+#endif
+
typedef HashSumValue<128> MD5SumValue;
class MD5Summation : public SummationImplementation
diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc
index f76169a92..a67ab3698 100644
--- a/apt-pkg/contrib/mmap.cc
+++ b/apt-pkg/contrib/mmap.cc
@@ -66,7 +66,7 @@ MMap::~MMap()
bool MMap::Map(FileFd &Fd)
{
iSize = Fd.Size();
-
+
// Set the permissions.
int Prot = PROT_READ;
int Map = MAP_SHARED;
@@ -77,7 +77,18 @@ bool MMap::Map(FileFd &Fd)
if (iSize == 0)
return _error->Error(_("Can't mmap an empty file"));
-
+
+ // We can't mmap compressed fd's directly, so we need to read it completely
+ if (Fd.IsCompressed() == true)
+ {
+ if ((Flags & ReadOnly) != ReadOnly)
+ return _error->Error("Compressed file %s can only be mapped readonly", Fd.Name().c_str());
+ Base = new unsigned char[iSize];
+ if (Fd.Seek(0L) == false || Fd.Read(Base, iSize) == false)
+ return false;
+ return true;
+ }
+
// Map it.
Base = mmap(0,iSize,Prot,Map,Fd.Fd(),0);
if (Base == (void *)-1)
@@ -86,6 +97,13 @@ bool MMap::Map(FileFd &Fd)
{
// The filesystem doesn't support this particular kind of mmap.
// So we allocate a buffer and read the whole file into it.
+ if ((Flags & ReadOnly) == ReadOnly)
+ {
+ // for readonly, we don't need sync, so make it simple
+ Base = new unsigned char[iSize];
+ return Fd.Read(Base, iSize);
+ }
+ // FIXME: Writing to compressed fd's ?
int const dupped_fd = dup(Fd.Fd());
if (dupped_fd == -1)
return _error->Errno("mmap", _("Couldn't duplicate file descriptor %i"), Fd.Fd());
diff --git a/apt-pkg/contrib/mmap.h b/apt-pkg/contrib/mmap.h
index 2ed4a95f8..6bd4a2d86 100644
--- a/apt-pkg/contrib/mmap.h
+++ b/apt-pkg/contrib/mmap.h
@@ -28,6 +28,11 @@
#include <string>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/fileutl.h>
+using std::string;
+#endif
+
class FileFd;
/* This should be a 32 bit type, larger tyes use too much ram and smaller
diff --git a/apt-pkg/contrib/netrc.h b/apt-pkg/contrib/netrc.h
index 7b94eba88..5931d4a42 100644
--- a/apt-pkg/contrib/netrc.h
+++ b/apt-pkg/contrib/netrc.h
@@ -16,6 +16,10 @@
#include <string>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/strutl.h>
+#endif
+
#define DOT_CHAR "."
#define DIR_CHAR "/"
diff --git a/apt-pkg/contrib/progress.h b/apt-pkg/contrib/progress.h
index 7635719bc..3a6943aee 100644
--- a/apt-pkg/contrib/progress.h
+++ b/apt-pkg/contrib/progress.h
@@ -25,6 +25,10 @@
#include <string>
#include <sys/time.h>
+#ifndef APT_8_CLEANER_HEADERS
+using std::string;
+#endif
+
class Configuration;
class OpProgress
{
diff --git a/apt-pkg/contrib/sha1.h b/apt-pkg/contrib/sha1.h
index b4b139a22..a8d55eb13 100644
--- a/apt-pkg/contrib/sha1.h
+++ b/apt-pkg/contrib/sha1.h
@@ -20,6 +20,11 @@
#include "hashsum_template.h"
+#ifndef APT_8_CLEANER_HEADERS
+using std::string;
+using std::min;
+#endif
+
typedef HashSumValue<160> SHA1SumValue;
class SHA1Summation : public SummationImplementation
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index 93f4bef4f..337139d5d 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -27,6 +27,12 @@
#include "macros.h"
+#ifndef APT_8_CLEANER_HEADERS
+using std::string;
+using std::vector;
+using std::ostream;
+#endif
+
bool UTF8ToCodeset(const char *codeset, const std::string &orig, std::string *dest);
char *_strstrip(char *String);
char *_strtabexpand(char *String,size_t Len);
diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc
index 27c1f7f32..84791a70a 100644
--- a/apt-pkg/deb/debindexfile.cc
+++ b/apt-pkg/deb/debindexfile.cc
@@ -26,6 +26,8 @@
#include <sys/stat.h>
/*}}}*/
+using std::string;
+
// SourcesIndex::debSourcesIndex - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -159,7 +161,7 @@ unsigned long debSourcesIndex::Size() const
/* we need to ignore errors here; if the lists are absent, just return 0 */
_error->PushToStack();
- FileFd f = FileFd (IndexFile("Sources"), FileFd::ReadOnlyGzip);
+ FileFd f = FileFd (IndexFile("Sources"), FileFd::ReadOnly, FileFd::Extension);
if (!f.Failed())
size = f.Size();
@@ -288,7 +290,7 @@ unsigned long debPackagesIndex::Size() const
/* we need to ignore errors here; if the lists are absent, just return 0 */
_error->PushToStack();
- FileFd f = FileFd (IndexFile("Packages"), FileFd::ReadOnlyGzip);
+ FileFd f = FileFd (IndexFile("Packages"), FileFd::ReadOnly, FileFd::Extension);
if (!f.Failed())
size = f.Size();
@@ -305,7 +307,7 @@ unsigned long debPackagesIndex::Size() const
bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
{
string PackageFile = IndexFile("Packages");
- FileFd Pkg(PackageFile,FileFd::ReadOnlyGzip);
+ FileFd Pkg(PackageFile,FileFd::ReadOnly, FileFd::Extension);
debListParser Parser(&Pkg, Architecture);
if (_error->PendingError() == true)
@@ -319,11 +321,8 @@ bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
// Store the IMS information
pkgCache::PkgFileIterator File = Gen.GetCurFile();
pkgCacheGenerator::Dynamic<pkgCache::PkgFileIterator> DynFile(File);
- struct stat St;
- if (fstat(Pkg.Fd(),&St) != 0)
- return _error->Errno("fstat","Failed to stat");
- File->Size = St.st_size;
- File->mtime = St.st_mtime;
+ File->Size = Pkg.FileSize();
+ File->mtime = Pkg.ModificationTime();
if (Gen.MergeList(Parser) == false)
return _error->Error("Problem with MergeList %s",PackageFile.c_str());
@@ -489,7 +488,7 @@ unsigned long debTranslationsIndex::Size() const
/* we need to ignore errors here; if the lists are absent, just return 0 */
_error->PushToStack();
- FileFd f = FileFd (IndexFile(Language), FileFd::ReadOnlyGzip);
+ FileFd f = FileFd (IndexFile(Language), FileFd::ReadOnly, FileFd::Extension);
if (!f.Failed())
size = f.Size();
@@ -509,7 +508,7 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
string TranslationFile = IndexFile(Language);
if (FileExists(TranslationFile))
{
- FileFd Trans(TranslationFile,FileFd::ReadOnlyGzip);
+ FileFd Trans(TranslationFile,FileFd::ReadOnly, FileFd::Extension);
debListParser TransParser(&Trans);
if (_error->PendingError() == true)
return false;
@@ -521,11 +520,8 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
// Store the IMS information
pkgCache::PkgFileIterator TransFile = Gen.GetCurFile();
- struct stat TransSt;
- if (fstat(Trans.Fd(),&TransSt) != 0)
- return _error->Errno("fstat","Failed to stat");
- TransFile->Size = TransSt.st_size;
- TransFile->mtime = TransSt.st_mtime;
+ TransFile->Size = Trans.FileSize();
+ TransFile->mtime = Trans.ModificationTime();
if (Gen.MergeList(TransParser) == false)
return _error->Error("Problem with MergeList %s",TranslationFile.c_str());
@@ -590,7 +586,7 @@ unsigned long debStatusIndex::Size() const
/* */
bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
{
- FileFd Pkg(File,FileFd::ReadOnlyGzip);
+ FileFd Pkg(File,FileFd::ReadOnly, FileFd::Extension);
if (_error->PendingError() == true)
return false;
debListParser Parser(&Pkg);
@@ -607,8 +603,8 @@ bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
struct stat St;
if (fstat(Pkg.Fd(),&St) != 0)
return _error->Errno("fstat","Failed to stat");
- CFile->Size = St.st_size;
- CFile->mtime = St.st_mtime;
+ CFile->Size = Pkg.FileSize();
+ CFile->mtime = Pkg.ModificationTime();
CFile->Archive = Gen.WriteUniqString("now");
if (Gen.MergeList(Parser) == false)
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index 28568d5e3..bdb50f6bf 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -773,6 +773,7 @@ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,
// file. to provide Component pinning we use the section name now
FileI->Component = WriteUniqString(component);
+ // FIXME: Code depends on the fact that Release files aren't compressed
FILE* release = fdopen(dup(File.Fd()), "r");
if (release == NULL)
return false;
diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h
index 9519d9711..386d291a2 100644
--- a/apt-pkg/deb/deblistparser.h
+++ b/apt-pkg/deb/deblistparser.h
@@ -14,6 +14,10 @@
#include <apt-pkg/pkgcachegen.h>
#include <apt-pkg/tagfile.h>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/indexfile.h>
+#endif
+
class debListParser : public pkgCacheGenerator::ListParser
{
public:
diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h
index 0cba2d8a8..b9ecab97c 100644
--- a/apt-pkg/deb/debmetaindex.h
+++ b/apt-pkg/deb/debmetaindex.h
@@ -8,6 +8,10 @@
#include <string>
#include <vector>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/sourcelist.h>
+#endif
+
class debReleaseIndex : public metaIndex {
public:
diff --git a/apt-pkg/deb/debrecords.cc b/apt-pkg/deb/debrecords.cc
index 1afa7b74d..184c07c33 100644
--- a/apt-pkg/deb/debrecords.cc
+++ b/apt-pkg/deb/debrecords.cc
@@ -25,7 +25,7 @@ using std::string;
// ---------------------------------------------------------------------
/* */
debRecordParser::debRecordParser(string FileName,pkgCache &Cache) :
- File(FileName,FileFd::ReadOnlyGzip),
+ File(FileName,FileFd::ReadOnly, FileFd::Extension),
Tags(&File, std::max(Cache.Head().MaxVerFileSize,
Cache.Head().MaxDescFileSize) + 200)
{
diff --git a/apt-pkg/deb/debrecords.h b/apt-pkg/deb/debrecords.h
index 9c7ea6b48..b5e3bbdba 100644
--- a/apt-pkg/deb/debrecords.h
+++ b/apt-pkg/deb/debrecords.h
@@ -18,6 +18,10 @@
#include <apt-pkg/tagfile.h>
#include <apt-pkg/fileutl.h>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/indexfile.h>
+#endif
+
class debRecordParser : public pkgRecords::Parser
{
/** \brief dpointer placeholder (for later in case we need it) */
diff --git a/apt-pkg/deb/debsrcrecords.h b/apt-pkg/deb/debsrcrecords.h
index 4c8d03224..5d2a67f4f 100644
--- a/apt-pkg/deb/debsrcrecords.h
+++ b/apt-pkg/deb/debsrcrecords.h
@@ -50,7 +50,7 @@ class debSrcRecordParser : public pkgSrcRecords::Parser
virtual bool Files(std::vector<pkgSrcRecords::File> &F);
debSrcRecordParser(std::string const &File,pkgIndexFile const *Index)
- : Parser(Index), Fd(File,FileFd::ReadOnlyGzip), Tags(&Fd,102400),
+ : Parser(Index), Fd(File,FileFd::ReadOnly, FileFd::Extension), Tags(&Fd,102400),
Buffer(NULL) {}
virtual ~debSrcRecordParser();
};
diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h
index 6b62360b7..aab39f633 100644
--- a/apt-pkg/deb/dpkgpm.h
+++ b/apt-pkg/deb/dpkgpm.h
@@ -15,6 +15,11 @@
#include <map>
#include <stdio.h>
+#ifndef APT_8_CLEANER_HEADERS
+using std::vector;
+using std::map;
+#endif
+
class pkgDPkgPMPrivate;
class pkgDPkgPM : public pkgPackageManager
diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h
index f6e6c0afc..7358048ed 100644
--- a/apt-pkg/depcache.h
+++ b/apt-pkg/depcache.h
@@ -46,6 +46,11 @@
#include <set>
#include <list>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/progress.h>
+#include <apt-pkg/error.h>
+#endif
+
class OpProgress;
class pkgDepCache : protected pkgCache::Namespace
diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h
index 07bbbdd03..12b06d143 100644
--- a/apt-pkg/edsp.h
+++ b/apt-pkg/edsp.h
@@ -15,6 +15,11 @@
#include <list>
#include <string>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/depcache.h>
+#include <apt-pkg/progress.h>
+#endif
+
class pkgDepCache;
class OpProgress;
diff --git a/apt-pkg/edsp/edspindexfile.cc b/apt-pkg/edsp/edspindexfile.cc
index 058cef636..482581979 100644
--- a/apt-pkg/edsp/edspindexfile.cc
+++ b/apt-pkg/edsp/edspindexfile.cc
@@ -24,7 +24,7 @@
// edspIndex::edspIndex - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-edspIndex::edspIndex(string File) : debStatusIndex(File)
+edspIndex::edspIndex(std::string File) : debStatusIndex(File)
{
}
/*}}}*/
@@ -44,16 +44,13 @@ bool edspIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
if (Prog != NULL)
Prog->SubProgress(0,File);
- if (Gen.SelectFile(File,string(),*this) == false)
+ if (Gen.SelectFile(File,std::string(),*this) == false)
return _error->Error("Problem with SelectFile %s",File.c_str());
// Store the IMS information
pkgCache::PkgFileIterator CFile = Gen.GetCurFile();
- struct stat St;
- if (fstat(Pkg.Fd(),&St) != 0)
- return _error->Errno("fstat","Failed to stat");
- CFile->Size = St.st_size;
- CFile->mtime = St.st_mtime;
+ CFile->Size = Pkg.FileSize();
+ CFile->mtime = Pkg.ModificationTime();
CFile->Archive = Gen.WriteUniqString("edsp::scenario");
if (Gen.MergeList(Parser) == false)
diff --git a/apt-pkg/edsp/edspindexfile.h b/apt-pkg/edsp/edspindexfile.h
index 9670c4837..de10f2d2f 100644
--- a/apt-pkg/edsp/edspindexfile.h
+++ b/apt-pkg/edsp/edspindexfile.h
@@ -10,6 +10,10 @@
#include <apt-pkg/debindexfile.h>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/indexfile.h>
+#endif
+
class edspIndex : public debStatusIndex
{
/** \brief dpointer placeholder (for later in case we need it) */
diff --git a/apt-pkg/edsp/edsplistparser.h b/apt-pkg/edsp/edsplistparser.h
index 5d82716c7..a7bf9de95 100644
--- a/apt-pkg/edsp/edsplistparser.h
+++ b/apt-pkg/edsp/edsplistparser.h
@@ -13,6 +13,12 @@
#include <apt-pkg/deblistparser.h>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/pkgcachegen.h>
+#include <apt-pkg/indexfile.h>
+#include <apt-pkg/tagfile.h>
+#endif
+
class FileFd;
class edspListParser : public debListParser
diff --git a/apt-pkg/indexcopy.cc b/apt-pkg/indexcopy.cc
index 4df018ef4..3747e3570 100644
--- a/apt-pkg/indexcopy.cc
+++ b/apt-pkg/indexcopy.cc
@@ -16,6 +16,7 @@
#include <apt-pkg/progress.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/fileutl.h>
+#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/tagfile.h>
#include <apt-pkg/indexrecords.h>
@@ -37,8 +38,6 @@
using namespace std;
-
-
// IndexCopy::CopyPackages - Copy the package files from the CD /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -57,15 +56,25 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
// Prepare the progress indicator
off_t TotalSize = 0;
+ std::vector<APT::Configuration::Compressor> const compressor = APT::Configuration::getCompressors();
for (vector<string>::iterator I = List.begin(); I != List.end(); ++I)
{
struct stat Buf;
- if (stat(string(*I + GetFileName()).c_str(),&Buf) != 0 &&
- stat(string(*I + GetFileName() + ".gz").c_str(),&Buf) != 0)
- return _error->Errno("stat","Stat failed for %s",
- string(*I + GetFileName()).c_str());
+ bool found = false;
+ std::string file = std::string(*I).append(GetFileName());
+ for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
+ c != compressor.end(); ++c)
+ {
+ if (stat(std::string(file + c->Extension).c_str(), &Buf) != 0)
+ continue;
+ found = true;
+ break;
+ }
+
+ if (found == false)
+ return _error->Errno("stat", "Stat failed for %s", file.c_str());
TotalSize += Buf.st_size;
- }
+ }
off_t CurrentSize = 0;
unsigned int NotFound = 0;
@@ -74,57 +83,11 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector<string> &List,
for (vector<string>::iterator I = List.begin(); I != List.end(); ++I)
{
string OrigPath = string(*I,CDROM.length());
- off_t FileSize = 0;
// Open the package file
- FileFd Pkg;
- if (RealFileExists(*I + GetFileName()) == true)
- {
- Pkg.Open(*I + GetFileName(),FileFd::ReadOnly);
- FileSize = Pkg.Size();
- }
- else
- {
- FileFd From(*I + GetFileName() + ".gz",FileFd::ReadOnly);
- if (_error->PendingError() == true)
- return false;
- FileSize = From.Size();
-
- // Get a temp file
- FILE *tmp = tmpfile();
- if (tmp == 0)
- return _error->Errno("tmpfile","Unable to create a tmp file");
- Pkg.Fd(dup(fileno(tmp)));
- fclose(tmp);
-
- // Fork gzip
- pid_t Process = fork();
- if (Process < 0)
- return _error->Errno("fork","Couldn't fork gzip");
-
- // The child
- if (Process == 0)
- {
- dup2(From.Fd(),STDIN_FILENO);
- dup2(Pkg.Fd(),STDOUT_FILENO);
- SetCloseExec(STDIN_FILENO,false);
- SetCloseExec(STDOUT_FILENO,false);
-
- const char *Args[3];
- string Tmp = _config->Find("Dir::bin::gzip","gzip");
- Args[0] = Tmp.c_str();
- Args[1] = "-d";
- Args[2] = 0;
- execvp(Args[0],(char **)Args);
- exit(100);
- }
-
- // Wait for gzip to finish
- if (ExecWait(Process,_config->Find("Dir::bin::gzip","gzip").c_str(),false) == false)
- return _error->Error("gzip failed, perhaps the disk is full.");
-
- Pkg.Seek(0);
- }
+ FileFd Pkg(*I + GetFileName(), FileFd::ReadOnly, FileFd::Extension);
+ off_t const FileSize = Pkg.Size();
+
pkgTagFile Parser(&Pkg);
if (_error->PendingError() == true)
return false;
@@ -602,13 +565,19 @@ bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList,
string const releasegpg = *I+"Release.gpg";
string const release = *I+"Release";
+ string const inrelease = *I+"InRelease";
+ bool useInRelease = true;
// a Release.gpg without a Release should never happen
- if(RealFileExists(release) == false)
+ if (RealFileExists(inrelease) == true)
+ ;
+ else if(RealFileExists(release) == false || RealFileExists(releasegpg) == false)
{
delete MetaIndex;
continue;
}
+ else
+ useInRelease = false;
pid_t pid = ExecFork();
if(pid < 0) {
@@ -616,11 +585,16 @@ bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList,
return false;
}
if(pid == 0)
- RunGPGV(release, releasegpg);
+ {
+ if (useInRelease == true)
+ RunGPGV(inrelease, inrelease);
+ else
+ RunGPGV(release, releasegpg);
+ }
if(!ExecWait(pid, "gpgv")) {
_error->Warning("Signature verification failed for: %s",
- releasegpg.c_str());
+ (useInRelease ? inrelease.c_str() : releasegpg.c_str()));
// something went wrong, don't copy the Release.gpg
// FIXME: delete any existing gpg file?
continue;
@@ -650,8 +624,13 @@ bool SigVerify::CopyAndVerify(string CDROM,string Name,vector<string> &SigList,
delete MetaIndex;
// everything was fine, copy the Release and Release.gpg file
- CopyMetaIndex(CDROM, Name, prefix, "Release");
- CopyMetaIndex(CDROM, Name, prefix, "Release.gpg");
+ if (useInRelease == true)
+ CopyMetaIndex(CDROM, Name, prefix, "InRelease");
+ else
+ {
+ CopyMetaIndex(CDROM, Name, prefix, "Release");
+ CopyMetaIndex(CDROM, Name, prefix, "Release.gpg");
+ }
}
return true;
@@ -789,15 +768,25 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name, /*{{{*/
// Prepare the progress indicator
off_t TotalSize = 0;
+ std::vector<APT::Configuration::Compressor> const compressor = APT::Configuration::getCompressors();
for (vector<string>::iterator I = List.begin(); I != List.end(); ++I)
{
struct stat Buf;
- if (stat(string(*I).c_str(),&Buf) != 0 &&
- stat(string(*I + ".gz").c_str(),&Buf) != 0)
- return _error->Errno("stat","Stat failed for %s",
- string(*I).c_str());
+ bool found = false;
+ std::string file = *I;
+ for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
+ c != compressor.end(); ++c)
+ {
+ if (stat(std::string(file + c->Extension).c_str(), &Buf) != 0)
+ continue;
+ found = true;
+ break;
+ }
+
+ if (found == false)
+ return _error->Errno("stat", "Stat failed for %s", file.c_str());
TotalSize += Buf.st_size;
- }
+ }
off_t CurrentSize = 0;
unsigned int NotFound = 0;
@@ -806,57 +795,11 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name, /*{{{*/
for (vector<string>::iterator I = List.begin(); I != List.end(); ++I)
{
string OrigPath = string(*I,CDROM.length());
- off_t FileSize = 0;
-
+
// Open the package file
- FileFd Pkg;
- if (RealFileExists(*I) == true)
- {
- Pkg.Open(*I,FileFd::ReadOnly);
- FileSize = Pkg.Size();
- }
- else
- {
- FileFd From(*I + ".gz",FileFd::ReadOnly);
- if (_error->PendingError() == true)
- return false;
- FileSize = From.Size();
-
- // Get a temp file
- FILE *tmp = tmpfile();
- if (tmp == 0)
- return _error->Errno("tmpfile","Unable to create a tmp file");
- Pkg.Fd(dup(fileno(tmp)));
- fclose(tmp);
-
- // Fork gzip
- pid_t Process = fork();
- if (Process < 0)
- return _error->Errno("fork","Couldn't fork gzip");
-
- // The child
- if (Process == 0)
- {
- dup2(From.Fd(),STDIN_FILENO);
- dup2(Pkg.Fd(),STDOUT_FILENO);
- SetCloseExec(STDIN_FILENO,false);
- SetCloseExec(STDOUT_FILENO,false);
-
- const char *Args[3];
- string Tmp = _config->Find("Dir::bin::gzip","gzip");
- Args[0] = Tmp.c_str();
- Args[1] = "-d";
- Args[2] = 0;
- execvp(Args[0],(char **)Args);
- exit(100);
- }
-
- // Wait for gzip to finish
- if (ExecWait(Process,_config->Find("Dir::bin::gzip","gzip").c_str(),false) == false)
- return _error->Error("gzip failed, perhaps the disk is full.");
-
- Pkg.Seek(0);
- }
+ FileFd Pkg(*I, FileFd::ReadOnly, FileFd::Extension);
+ off_t const FileSize = Pkg.Size();
+
pkgTagFile Parser(&Pkg);
if (_error->PendingError() == true)
return false;
diff --git a/apt-pkg/indexcopy.h b/apt-pkg/indexcopy.h
index 21294ae7e..e3de1afd9 100644
--- a/apt-pkg/indexcopy.h
+++ b/apt-pkg/indexcopy.h
@@ -14,6 +14,11 @@
#include <string>
#include <stdio.h>
+#ifndef APT_8_CLEANER_HEADERS
+using std::string;
+using std::vector;
+#endif
+
class pkgTagSection;
class FileFd;
class indexRecords;
diff --git a/apt-pkg/indexfile.h b/apt-pkg/indexfile.h
index 5e162a846..1d34dc773 100644
--- a/apt-pkg/indexfile.h
+++ b/apt-pkg/indexfile.h
@@ -29,6 +29,10 @@
#include <apt-pkg/pkgrecords.h>
#include <apt-pkg/macros.h>
+#ifndef APT_8_CLEANER_HEADERS
+using std::string;
+#endif
+
class pkgAcquire;
class pkgCacheGenerator;
class OpProgress;
diff --git a/apt-pkg/indexrecords.h b/apt-pkg/indexrecords.h
index fa60a0847..a98b939bc 100644
--- a/apt-pkg/indexrecords.h
+++ b/apt-pkg/indexrecords.h
@@ -13,6 +13,10 @@
#include <vector>
#include <ctime>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/fileutl.h>
+#endif
+
class indexRecords
{
bool parseSumData(const char *&Start, const char *End, std::string &Name,
diff --git a/apt-pkg/init.h b/apt-pkg/init.h
index 0c1c7ae5a..b6f3df753 100644
--- a/apt-pkg/init.h
+++ b/apt-pkg/init.h
@@ -13,6 +13,11 @@
#ifndef PKGLIB_INIT_H
#define PKGLIB_INIT_H
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/pkgsystem.h>
+#endif
+
class pkgSystem;
class Configuration;
diff --git a/apt-pkg/metaindex.h b/apt-pkg/metaindex.h
index 9cc79a7a6..5783735ff 100644
--- a/apt-pkg/metaindex.h
+++ b/apt-pkg/metaindex.h
@@ -6,6 +6,13 @@
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/indexfile.h>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/srcrecords.h>
+#include <apt-pkg/pkgrecords.h>
+#include <apt-pkg/vendor.h>
+using std::string;
+#endif
+
class pkgAcquire;
class pkgCacheGenerator;
class OpProgress;
diff --git a/apt-pkg/packagemanager.h b/apt-pkg/packagemanager.h
index d4989a6e0..1a6a9f01c 100644
--- a/apt-pkg/packagemanager.h
+++ b/apt-pkg/packagemanager.h
@@ -29,6 +29,11 @@
#include <iostream>
#include <set>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/depcache.h>
+using std::string;
+#endif
+
class pkgAcquire;
class pkgDepCache;
class pkgSourceList;
diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h
index fd1a02149..1a7013551 100644
--- a/apt-pkg/pkgcache.h
+++ b/apt-pkg/pkgcache.h
@@ -74,11 +74,14 @@
#ifndef PKGLIB_PKGCACHE_H
#define PKGLIB_PKGCACHE_H
-
#include <string>
#include <time.h>
#include <apt-pkg/mmap.h>
+#ifndef APT_8_CLEANER_HEADERS
+using std::string;
+#endif
+
class pkgVersioningSystem;
class pkgCache /*{{{*/
{
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index 9f999c41b..ec072fddd 100644
--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -35,12 +35,14 @@
#include <apti18n.h>
/*}}}*/
-typedef vector<pkgIndexFile *>::iterator FileIterator;
+typedef std::vector<pkgIndexFile *>::iterator FileIterator;
template <typename Iter> std::vector<Iter*> pkgCacheGenerator::Dynamic<Iter>::toReMap;
bool IsDuplicateDescription(pkgCache::DescIterator Desc,
MD5SumValue const &CurMd5, std::string const &CurLang);
+using std::string;
+
// CacheGenerator::pkgCacheGenerator - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* We set the dirty flag and make sure that is written to the disk */
@@ -1221,14 +1223,14 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
MMap **OutMap,bool AllowMem)
{
bool const Debug = _config->FindB("Debug::pkgCacheGen", false);
-
- vector<pkgIndexFile *> Files;
- for (vector<metaIndex *>::const_iterator i = List.begin();
+
+ std::vector<pkgIndexFile *> Files;
+ for (std::vector<metaIndex *>::const_iterator i = List.begin();
i != List.end();
++i)
{
- vector <pkgIndexFile *> *Indexes = (*i)->GetIndexFiles();
- for (vector<pkgIndexFile *>::const_iterator j = Indexes->begin();
+ std::vector <pkgIndexFile *> *Indexes = (*i)->GetIndexFiles();
+ for (std::vector<pkgIndexFile *>::const_iterator j = Indexes->begin();
j != Indexes->end();
++j)
Files.push_back (*j);
@@ -1418,7 +1420,7 @@ __deprecated bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutM
{ return pkgCacheGenerator::MakeOnlyStatusCache(&Progress, OutMap); }
bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap)
{
- vector<pkgIndexFile *> Files;
+ std::vector<pkgIndexFile *> Files;
unsigned long EndOfSource = Files.size();
if (_system->AddStatusFiles(Files) == false)
return false;
diff --git a/apt-pkg/pkgsystem.h b/apt-pkg/pkgsystem.h
index 211fd0d56..75f7b9fcc 100644
--- a/apt-pkg/pkgsystem.h
+++ b/apt-pkg/pkgsystem.h
@@ -41,6 +41,10 @@
#include <vector>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/depcache.h>
+#endif
+
class pkgDepCache;
class pkgPackageManager;
class pkgVersioningSystem;
diff --git a/apt-pkg/policy.h b/apt-pkg/policy.h
index 3c8246e3b..5172a3c3b 100644
--- a/apt-pkg/policy.h
+++ b/apt-pkg/policy.h
@@ -38,6 +38,10 @@
#include <apt-pkg/versionmatch.h>
#include <vector>
+#ifndef APT_8_CLEANER_HEADERS
+using std::vector;
+#endif
+
class pkgPolicy : public pkgDepCache::Policy
{
protected:
diff --git a/apt-pkg/sourcelist.h b/apt-pkg/sourcelist.h
index 4509e54b9..02e27101a 100644
--- a/apt-pkg/sourcelist.h
+++ b/apt-pkg/sourcelist.h
@@ -32,9 +32,11 @@
#include <map>
#include <apt-pkg/pkgcache.h>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/metaindex.h>
using std::string;
using std::vector;
-
+#endif
class pkgAcquire;
class pkgIndexFile;
@@ -57,32 +59,32 @@ class pkgSourceList
const char *Name;
const char *Label;
- bool FixupURI(string &URI) const;
- virtual bool ParseLine(vector<metaIndex *> &List,
+ bool FixupURI(std::string &URI) const;
+ virtual bool ParseLine(std::vector<metaIndex *> &List,
const char *Buffer,
- unsigned long const &CurLine,string const &File) const;
- virtual bool CreateItem(vector<metaIndex *> &List,string const &URI,
- string const &Dist,string const &Section,
- std::map<string, string> const &Options) const = 0;
+ unsigned long const &CurLine,std::string const &File) const;
+ virtual bool CreateItem(std::vector<metaIndex *> &List,std::string const &URI,
+ std::string const &Dist,std::string const &Section,
+ std::map<std::string, std::string> const &Options) const = 0;
Type();
virtual ~Type() {};
};
- typedef vector<metaIndex *>::const_iterator const_iterator;
+ typedef std::vector<metaIndex *>::const_iterator const_iterator;
protected:
- vector<metaIndex *> SrcList;
+ std::vector<metaIndex *> SrcList;
public:
bool ReadMainList();
- bool Read(string File);
+ bool Read(std::string File);
// CNC:2003-03-03
void Reset();
- bool ReadAppend(string File);
- bool ReadSourceDir(string Dir);
+ bool ReadAppend(std::string File);
+ bool ReadSourceDir(std::string Dir);
// List accessors
inline const_iterator begin() const {return SrcList.begin();};
@@ -98,7 +100,7 @@ class pkgSourceList
time_t GetLastModifiedTime();
pkgSourceList();
- pkgSourceList(string File);
+ pkgSourceList(std::string File);
~pkgSourceList();
};
diff --git a/apt-pkg/srcrecords.cc b/apt-pkg/srcrecords.cc
index f6d2d5158..48b643eac 100644
--- a/apt-pkg/srcrecords.cc
+++ b/apt-pkg/srcrecords.cc
@@ -29,8 +29,8 @@ pkgSrcRecords::pkgSrcRecords(pkgSourceList &List) : Files(0), Current(0)
{
for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); ++I)
{
- vector<pkgIndexFile *> *Indexes = (*I)->GetIndexFiles();
- for (vector<pkgIndexFile *>::const_iterator J = Indexes->begin();
+ std::vector<pkgIndexFile *> *Indexes = (*I)->GetIndexFiles();
+ for (std::vector<pkgIndexFile *>::const_iterator J = Indexes->begin();
J != Indexes->end(); ++J)
{
Parser* P = (*J)->CreateSrcParser();
@@ -58,7 +58,7 @@ pkgSrcRecords::pkgSrcRecords(pkgSourceList &List) : Files(0), Current(0)
pkgSrcRecords::~pkgSrcRecords()
{
// Blow away all the parser objects
- for(vector<Parser*>::iterator I = Files.begin(); I != Files.end(); ++I)
+ for(std::vector<Parser*>::iterator I = Files.begin(); I != Files.end(); ++I)
delete *I;
}
/*}}}*/
@@ -68,7 +68,7 @@ pkgSrcRecords::~pkgSrcRecords()
bool pkgSrcRecords::Restart()
{
Current = Files.begin();
- for (vector<Parser*>::iterator I = Files.begin();
+ for (std::vector<Parser*>::iterator I = Files.begin();
I != Files.end(); ++I)
(*I)->Restart();
diff --git a/apt-pkg/srcrecords.h b/apt-pkg/srcrecords.h
index a55bc74fa..06f0dce6c 100644
--- a/apt-pkg/srcrecords.h
+++ b/apt-pkg/srcrecords.h
@@ -17,6 +17,11 @@
#include <string>
#include <vector>
+#ifndef APT_8_CLEANER_HEADERS
+using std::string;
+using std::vector;
+#endif
+
class pkgSourceList;
class pkgIndexFile;
class pkgSrcRecords
diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h
index a5bf5ac90..fd24471c1 100644
--- a/apt-pkg/tagfile.h
+++ b/apt-pkg/tagfile.h
@@ -24,6 +24,10 @@
#include <string>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/fileutl.h>
+#endif
+
class FileFd;
class pkgTagSection
diff --git a/apt-pkg/vendor.h b/apt-pkg/vendor.h
index 9b157378c..6484adf9b 100644
--- a/apt-pkg/vendor.h
+++ b/apt-pkg/vendor.h
@@ -6,6 +6,10 @@
#include <apt-pkg/macros.h>
+#ifndef APT_8_CLEANER_HEADERS
+using std::string;
+#endif
+
// A class representing a particular software provider.
class __deprecated Vendor
{
diff --git a/apt-pkg/vendorlist.h b/apt-pkg/vendorlist.h
index 733d23a32..a86ccde7c 100644
--- a/apt-pkg/vendorlist.h
+++ b/apt-pkg/vendorlist.h
@@ -17,6 +17,13 @@
#include <vector>
#include <apt-pkg/macros.h>
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/vendor.h>
+#include <apt-pkg/configuration.h>
+using std::string;
+using std::vector;
+#endif
+
class Vendor;
class Configuration;
diff --git a/apt-pkg/version.h b/apt-pkg/version.h
index 92dbc2576..e0e0e6c14 100644
--- a/apt-pkg/version.h
+++ b/apt-pkg/version.h
@@ -23,6 +23,10 @@
#include <apt-pkg/strutl.h>
#include <string>
+#ifndef APT_8_CLEANER_HEADERS
+using std::string;
+#endif
+
class pkgVersioningSystem
{
public:
diff --git a/apt-pkg/versionmatch.h b/apt-pkg/versionmatch.h
index da103fc5b..433396fc9 100644
--- a/apt-pkg/versionmatch.h
+++ b/apt-pkg/versionmatch.h
@@ -39,6 +39,10 @@
#include <string>
#include <apt-pkg/pkgcache.h>
+#ifndef APT_8_CLEANER_HEADERS
+using std::string;
+#endif
+
class pkgVersionMatch
{
// Version Matching