diff options
Diffstat (limited to 'apt-pkg/deb')
-rw-r--r-- | apt-pkg/deb/debindexfile.cc | 2 | ||||
-rw-r--r-- | apt-pkg/deb/debindexfile.h | 68 | ||||
-rw-r--r-- | apt-pkg/deb/deblistparser.cc | 29 | ||||
-rw-r--r-- | apt-pkg/deb/deblistparser.h | 25 | ||||
-rw-r--r-- | apt-pkg/deb/debmetaindex.cc | 12 | ||||
-rw-r--r-- | apt-pkg/deb/debmetaindex.h | 43 | ||||
-rw-r--r-- | apt-pkg/deb/debrecords.cc | 10 | ||||
-rw-r--r-- | apt-pkg/deb/debrecords.h | 30 | ||||
-rw-r--r-- | apt-pkg/deb/debsrcrecords.cc | 49 | ||||
-rw-r--r-- | apt-pkg/deb/debsrcrecords.h | 23 | ||||
-rw-r--r-- | apt-pkg/deb/debsystem.cc | 9 | ||||
-rw-r--r-- | apt-pkg/deb/debsystem.h | 4 | ||||
-rw-r--r-- | apt-pkg/deb/debversion.cc | 31 | ||||
-rw-r--r-- | apt-pkg/deb/debversion.h | 30 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 177 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.h | 21 |
16 files changed, 294 insertions, 269 deletions
diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index e3d4063dc..27c1f7f32 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -9,6 +9,8 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include <config.h> + #include <apt-pkg/debindexfile.h> #include <apt-pkg/debsrcrecords.h> #include <apt-pkg/deblistparser.h> diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index 678c22473..9e64d4476 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -26,14 +26,14 @@ class debStatusIndex : public pkgIndexFile void *d; protected: - string File; + std::string File; public: virtual const Type *GetType() const; // Interface for acquire - virtual string Describe(bool Short) const {return File;}; + virtual std::string Describe(bool Short) const {return File;}; // Interface for the Cache Generator virtual bool Exists() const; @@ -43,7 +43,7 @@ class debStatusIndex : public pkgIndexFile bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog, unsigned long const Flag) const; virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; - debStatusIndex(string File); + debStatusIndex(std::string File); virtual ~debStatusIndex() {}; }; @@ -52,25 +52,25 @@ class debPackagesIndex : public pkgIndexFile /** \brief dpointer placeholder (for later in case we need it) */ void *d; - string URI; - string Dist; - string Section; - string Architecture; + std::string URI; + std::string Dist; + std::string Section; + std::string Architecture; - string Info(const char *Type) const; - string IndexFile(const char *Type) const; - string IndexURI(const char *Type) const; + std::string Info(const char *Type) const; + std::string IndexFile(const char *Type) const; + std::string IndexURI(const char *Type) const; public: virtual const Type *GetType() const; // Stuff for accessing files on remote items - virtual string ArchiveInfo(pkgCache::VerIterator Ver) const; - virtual string ArchiveURI(string File) const {return URI + File;}; + virtual std::string ArchiveInfo(pkgCache::VerIterator Ver) const; + virtual std::string ArchiveURI(std::string File) const {return URI + File;}; // Interface for acquire - virtual string Describe(bool Short) const; + virtual std::string Describe(bool Short) const; // Interface for the Cache Generator virtual bool Exists() const; @@ -79,8 +79,8 @@ class debPackagesIndex : public pkgIndexFile virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; - debPackagesIndex(string const &URI, string const &Dist, string const &Section, - bool const &Trusted, string const &Arch = "native"); + debPackagesIndex(std::string const &URI, std::string const &Dist, std::string const &Section, + bool const &Trusted, std::string const &Arch = "native"); virtual ~debPackagesIndex() {}; }; @@ -89,23 +89,23 @@ class debTranslationsIndex : public pkgIndexFile /** \brief dpointer placeholder (for later in case we need it) */ void *d; - string URI; - string Dist; - string Section; + std::string URI; + std::string Dist; + std::string Section; const char * const Language; - string Info(const char *Type) const; - string IndexFile(const char *Type) const; - string IndexURI(const char *Type) const; + std::string Info(const char *Type) const; + std::string IndexFile(const char *Type) const; + std::string IndexURI(const char *Type) const; - inline string TranslationFile() const {return string("Translation-").append(Language);}; + inline std::string TranslationFile() const {return std::string("Translation-").append(Language);}; public: virtual const Type *GetType() const; // Interface for acquire - virtual string Describe(bool Short) const; + virtual std::string Describe(bool Short) const; virtual bool GetIndexes(pkgAcquire *Owner) const; // Interface for the Cache Generator @@ -115,7 +115,7 @@ class debTranslationsIndex : public pkgIndexFile virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; - debTranslationsIndex(string URI,string Dist,string Section, char const * const Language); + debTranslationsIndex(std::string URI,std::string Dist,std::string Section, char const * const Language); virtual ~debTranslationsIndex() {}; }; @@ -124,25 +124,25 @@ class debSourcesIndex : public pkgIndexFile /** \brief dpointer placeholder (for later in case we need it) */ void *d; - string URI; - string Dist; - string Section; + std::string URI; + std::string Dist; + std::string Section; - string Info(const char *Type) const; - string IndexFile(const char *Type) const; - string IndexURI(const char *Type) const; + std::string Info(const char *Type) const; + std::string IndexFile(const char *Type) const; + std::string IndexURI(const char *Type) const; public: virtual const Type *GetType() const; // Stuff for accessing files on remote items - virtual string SourceInfo(pkgSrcRecords::Parser const &Record, + virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record, pkgSrcRecords::File const &File) const; - virtual string ArchiveURI(string File) const {return URI + File;}; + virtual std::string ArchiveURI(std::string File) const {return URI + File;}; // Interface for acquire - virtual string Describe(bool Short) const; + virtual std::string Describe(bool Short) const; // Interface for the record parsers virtual pkgSrcRecords::Parser *CreateSrcParser() const; @@ -152,7 +152,7 @@ class debSourcesIndex : public pkgIndexFile virtual bool HasPackages() const {return false;}; virtual unsigned long Size() const; - debSourcesIndex(string URI,string Dist,string Section,bool Trusted); + debSourcesIndex(std::string URI,std::string Dist,std::string Section,bool Trusted); virtual ~debSourcesIndex() {}; }; diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 89999fb44..28568d5e3 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -10,11 +10,14 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include <config.h> + #include <apt-pkg/deblistparser.h> #include <apt-pkg/error.h> #include <apt-pkg/configuration.h> #include <apt-pkg/aptconfiguration.h> #include <apt-pkg/strutl.h> +#include <apt-pkg/fileutl.h> #include <apt-pkg/crc-16.h> #include <apt-pkg/md5.h> #include <apt-pkg/macros.h> @@ -23,6 +26,8 @@ #include <ctype.h> /*}}}*/ +using std::string; + static debListParser::WordList PrioList[] = {{"important",pkgCache::State::Important}, {"required",pkgCache::State::Required}, {"standard",pkgCache::State::Standard}, @@ -517,9 +522,9 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop, // Skip whitespace for (;I != Stop && isspace(*I) != 0; I++); Start = I; - for (;I != Stop && *I != ')'; I++); - if (I == Stop || Start == I) - return 0; + I = (const char*) memchr(I, ')', Stop - I); + if (I == NULL || Start == I) + return 0; // Skip trailing whitespace const char *End = I; @@ -670,6 +675,9 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver) return _error->Error("Problem parsing Provides line"); if (Op != pkgCache::Dep::NoOp) { _error->Warning("Ignoring Provides line with DepCompareOp for package %s", Package.c_str()); + } else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign) { + if (NewProvidesAllArch(Ver, Package, Version) == false) + return false; } else { if (NewProvides(Ver, Package, Arch, Version) == false) return false; @@ -792,21 +800,16 @@ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI, } // seperate the tag from the data - for (; buffer[len] != ':' && buffer[len] != '\0'; ++len) - /* nothing */ - ; - if (buffer[len] == '\0') + const char* dataStart = strchr(buffer + len, ':'); + if (dataStart == NULL) continue; - char* dataStart = buffer + len; + len = dataStart - buffer; for (++dataStart; *dataStart == ' '; ++dataStart) /* nothing */ ; - char* dataEnd = dataStart; - for (++dataEnd; *dataEnd != '\0'; ++dataEnd) - /* nothing */ - ; + const char* dataEnd = (const char*)rawmemchr(dataStart, '\0'); // The last char should be a newline, but we can never be sure: #633350 - char* lineEnd = dataEnd; + const char* lineEnd = dataEnd; for (--lineEnd; *lineEnd == '\r' || *lineEnd == '\n'; --lineEnd) /* nothing */ ; diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index 41d712fbf..9519d9711 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -12,7 +12,6 @@ #define PKGLIB_DEBLISTPARSER_H #include <apt-pkg/pkgcachegen.h> -#include <apt-pkg/indexfile.h> #include <apt-pkg/tagfile.h> class debListParser : public pkgCacheGenerator::ListParser @@ -34,7 +33,7 @@ class debListParser : public pkgCacheGenerator::ListParser pkgTagFile Tags; pkgTagSection Section; unsigned long iOffset; - string Arch; + std::string Arch; std::vector<std::string> Architectures; bool MultiArchEnabled; @@ -43,21 +42,21 @@ class debListParser : public pkgCacheGenerator::ListParser bool ParseDepends(pkgCache::VerIterator &Ver,const char *Tag, unsigned int Type); bool ParseProvides(pkgCache::VerIterator &Ver); - bool NewProvidesAllArch(pkgCache::VerIterator &Ver, string const &Package, string const &Version); - static bool GrabWord(string Word,WordList *List,unsigned char &Out); + bool NewProvidesAllArch(pkgCache::VerIterator &Ver, std::string const &Package, std::string const &Version); + static bool GrabWord(std::string Word,WordList *List,unsigned char &Out); public: - static unsigned char GetPrio(string Str); + static unsigned char GetPrio(std::string Str); // These all operate against the current section - virtual string Package(); - virtual string Architecture(); + virtual std::string Package(); + virtual std::string Architecture(); virtual bool ArchitectureAll(); - virtual string Version(); + virtual std::string Version(); virtual bool NewVersion(pkgCache::VerIterator &Ver); - virtual string Description(); - virtual string DescriptionLanguage(); + virtual std::string Description(); + virtual std::string DescriptionLanguage(); virtual MD5SumValue Description_md5(); virtual unsigned short VersionHash(); virtual bool UsePackage(pkgCache::PkgIterator &Pkg, @@ -68,15 +67,15 @@ class debListParser : public pkgCacheGenerator::ListParser virtual bool Step(); bool LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,FileFd &File, - string section); + std::string section); static const char *ParseDepends(const char *Start,const char *Stop, - string &Package,string &Ver,unsigned int &Op, + std::string &Package,std::string &Ver,unsigned int &Op, bool const &ParseArchFlags = false, bool const &StripMultiArch = true); static const char *ConvertRelation(const char *I,unsigned int &Op); - debListParser(FileFd *File, string const &Arch = ""); + debListParser(FileFd *File, std::string const &Arch = ""); virtual ~debListParser() {}; }; diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 11aa2635d..5d3a80aa5 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -1,14 +1,19 @@ // ijones, walters +#include <config.h> #include <apt-pkg/debmetaindex.h> #include <apt-pkg/debindexfile.h> #include <apt-pkg/strutl.h> +#include <apt-pkg/fileutl.h> #include <apt-pkg/acquire-item.h> #include <apt-pkg/configuration.h> #include <apt-pkg/aptconfiguration.h> +#include <apt-pkg/indexrecords.h> +#include <apt-pkg/sourcelist.h> #include <apt-pkg/error.h> #include <set> +#include <algorithm> using namespace std; @@ -197,7 +202,11 @@ vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const { } } - std::vector<std::string> const lang = APT::Configuration::getLanguages(true); + std::vector<std::string> lang = APT::Configuration::getLanguages(true); + std::vector<std::string>::iterator lend = std::remove(lang.begin(), lang.end(), "none"); + if (lend != lang.end()) + lang.erase(lend); + if (lang.empty() == true) return IndexTargets; @@ -209,7 +218,6 @@ vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const { s != sections.end(); ++s) { for (std::vector<std::string>::const_iterator l = lang.begin(); l != lang.end(); ++l) { - if (*l == "none") continue; IndexTarget * Target = new OptionalIndexTarget(); Target->ShortDesc = "Translation-" + *l; Target->MetaKey = TranslationIndexURISuffix(l->c_str(), *s); diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index 695cfa7cc..0cba2d8a8 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -3,9 +3,10 @@ #define PKGLIB_DEBMETAINDEX_H #include <apt-pkg/metaindex.h> -#include <apt-pkg/sourcelist.h> #include <map> +#include <string> +#include <vector> class debReleaseIndex : public metaIndex { public: @@ -13,43 +14,43 @@ class debReleaseIndex : public metaIndex { class debSectionEntry { public: - debSectionEntry (string const &Section, bool const &IsSrc); - string const Section; + debSectionEntry (std::string const &Section, bool const &IsSrc); + std::string const Section; bool const IsSrc; }; private: /** \brief dpointer placeholder (for later in case we need it) */ void *d; - std::map<string, vector<debSectionEntry const*> > ArchEntries; + std::map<std::string, std::vector<debSectionEntry const*> > ArchEntries; enum { ALWAYS_TRUSTED, NEVER_TRUSTED, CHECK_TRUST } Trusted; public: - debReleaseIndex(string const &URI, string const &Dist); - debReleaseIndex(string const &URI, string const &Dist, bool const Trusted); + debReleaseIndex(std::string const &URI, std::string const &Dist); + debReleaseIndex(std::string const &URI, std::string const &Dist, bool const Trusted); virtual ~debReleaseIndex(); - virtual string ArchiveURI(string const &File) const {return URI + File;}; + virtual std::string ArchiveURI(std::string const &File) const {return URI + File;}; virtual bool GetIndexes(pkgAcquire *Owner, bool const &GetAll=false) const; - vector <struct IndexTarget *>* ComputeIndexTargets() const; - string Info(const char *Type, string const &Section, string const &Arch="") const; - string MetaIndexInfo(const char *Type) const; - string MetaIndexFile(const char *Types) const; - string MetaIndexURI(const char *Type) const; - string IndexURI(const char *Type, string const &Section, string const &Arch="native") const; - string IndexURISuffix(const char *Type, string const &Section, string const &Arch="native") const; - string SourceIndexURI(const char *Type, const string &Section) const; - string SourceIndexURISuffix(const char *Type, const string &Section) const; - string TranslationIndexURI(const char *Type, const string &Section) const; - string TranslationIndexURISuffix(const char *Type, const string &Section) const; - virtual vector <pkgIndexFile *> *GetIndexFiles(); + std::vector <struct IndexTarget *>* ComputeIndexTargets() const; + std::string Info(const char *Type, std::string const &Section, std::string const &Arch="") const; + std::string MetaIndexInfo(const char *Type) const; + std::string MetaIndexFile(const char *Types) const; + std::string MetaIndexURI(const char *Type) const; + std::string IndexURI(const char *Type, std::string const &Section, std::string const &Arch="native") const; + std::string IndexURISuffix(const char *Type, std::string const &Section, std::string const &Arch="native") const; + std::string SourceIndexURI(const char *Type, const std::string &Section) const; + std::string SourceIndexURISuffix(const char *Type, const std::string &Section) const; + std::string TranslationIndexURI(const char *Type, const std::string &Section) const; + std::string TranslationIndexURISuffix(const char *Type, const std::string &Section) const; + virtual std::vector <pkgIndexFile *> *GetIndexFiles(); void SetTrusted(bool const Trusted); virtual bool IsTrusted() const; - void PushSectionEntry(vector<string> const &Archs, const debSectionEntry *Entry); - void PushSectionEntry(string const &Arch, const debSectionEntry *Entry); + void PushSectionEntry(std::vector<std::string> const &Archs, const debSectionEntry *Entry); + void PushSectionEntry(std::string const &Arch, const debSectionEntry *Entry); void PushSectionEntry(const debSectionEntry *Entry); }; diff --git a/apt-pkg/deb/debrecords.cc b/apt-pkg/deb/debrecords.cc index 2571aae52..1afa7b74d 100644 --- a/apt-pkg/deb/debrecords.cc +++ b/apt-pkg/deb/debrecords.cc @@ -8,13 +8,19 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include <config.h> + #include <apt-pkg/debrecords.h> #include <apt-pkg/strutl.h> #include <apt-pkg/error.h> #include <apt-pkg/aptconfiguration.h> +#include <apt-pkg/fileutl.h> + #include <langinfo.h> /*}}}*/ +using std::string; + // RecordParser::debRecordParser - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -133,8 +139,8 @@ string debRecordParser::LongDesc() orig = Section.FindS("Description").c_str(); else { - vector<string> const lang = APT::Configuration::getLanguages(); - for (vector<string>::const_iterator l = lang.begin(); + std::vector<string> const lang = APT::Configuration::getLanguages(); + for (std::vector<string>::const_iterator l = lang.begin(); orig.empty() && l != lang.end(); ++l) orig = Section.FindS(string("Description-").append(*l).c_str()); } diff --git a/apt-pkg/deb/debrecords.h b/apt-pkg/deb/debrecords.h index 7868bfa3d..9c7ea6b48 100644 --- a/apt-pkg/deb/debrecords.h +++ b/apt-pkg/deb/debrecords.h @@ -15,8 +15,8 @@ #define PKGLIB_DEBRECORDS_H #include <apt-pkg/pkgrecords.h> -#include <apt-pkg/indexfile.h> #include <apt-pkg/tagfile.h> +#include <apt-pkg/fileutl.h> class debRecordParser : public pkgRecords::Parser { @@ -35,27 +35,27 @@ class debRecordParser : public pkgRecords::Parser public: // These refer to the archive file for the Version - virtual string FileName(); - virtual string MD5Hash(); - virtual string SHA1Hash(); - virtual string SHA256Hash(); - virtual string SHA512Hash(); - virtual string SourcePkg(); - virtual string SourceVer(); + virtual std::string FileName(); + virtual std::string MD5Hash(); + virtual std::string SHA1Hash(); + virtual std::string SHA256Hash(); + virtual std::string SHA512Hash(); + virtual std::string SourcePkg(); + virtual std::string SourceVer(); // These are some general stats about the package - virtual string Maintainer(); - virtual string ShortDesc(); - virtual string LongDesc(); - virtual string Name(); - virtual string Homepage(); + virtual std::string Maintainer(); + virtual std::string ShortDesc(); + virtual std::string LongDesc(); + virtual std::string Name(); + virtual std::string Homepage(); // An arbitrary custom field - virtual string RecordField(const char *fieldName); + virtual std::string RecordField(const char *fieldName); virtual void GetRec(const char *&Start,const char *&Stop); - debRecordParser(string FileName,pkgCache &Cache); + debRecordParser(std::string FileName,pkgCache &Cache); virtual ~debRecordParser() {}; }; diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc index 749305005..ce55ccd1f 100644 --- a/apt-pkg/deb/debsrcrecords.cc +++ b/apt-pkg/deb/debsrcrecords.cc @@ -9,6 +9,8 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include <config.h> + #include <apt-pkg/deblistparser.h> #include <apt-pkg/debsrcrecords.h> #include <apt-pkg/error.h> @@ -19,6 +21,8 @@ using std::max; /*}}}*/ +using std::string; + // SrcRecordParser::Binaries - Return the binaries field /*{{{*/ // --------------------------------------------------------------------- /* This member parses the binaries field into a pair of class arrays and @@ -28,25 +32,32 @@ using std::max; used during scanning to find the right package */ const char **debSrcRecordParser::Binaries() { - // This should use Start/Stop too, it is supposed to be efficient after all. - string Bins = Sect.FindS("Binary"); - if (Bins.empty() == true || Bins.length() >= 102400) - return 0; - - if (Bins.length() >= BufSize) - { - delete [] Buffer; - // allocate new size based on buffer (but never smaller than 4000) - BufSize = max((unsigned int)4000, max((unsigned int)Bins.length()+1,2*BufSize)); - Buffer = new char[BufSize]; - } + const char *Start, *End; + if (Sect.Find("Binary", Start, End) == false) + return NULL; + for (; isspace(*Start) != 0; ++Start); + if (Start >= End) + return NULL; + + StaticBinList.clear(); + free(Buffer); + Buffer = strndup(Start, End - Start); - strcpy(Buffer,Bins.c_str()); - if (TokSplitString(',',Buffer,StaticBinList, - sizeof(StaticBinList)/sizeof(StaticBinList[0])) == false) - return 0; + char* bin = Buffer; + do { + char* binStartNext = strchrnul(bin, ','); + char* binEnd = binStartNext - 1; + for (; isspace(*binEnd) != 0; --binEnd) + binEnd = '\0'; + StaticBinList.push_back(bin); + if (*binStartNext != ',') + break; + *binStartNext = '\0'; + for (bin = binStartNext + 1; isspace(*bin) != 0; ++bin); + } while (*bin != '\0'); + StaticBinList.push_back(NULL); - return (const char **)StaticBinList; + return (const char **) &StaticBinList[0]; } /*}}}*/ // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/ @@ -55,7 +66,7 @@ const char **debSrcRecordParser::Binaries() package/version records representing the build dependency. The returned array need not be freed and will be reused by the next call to this function */ -bool debSrcRecordParser::BuildDepends(vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps, +bool debSrcRecordParser::BuildDepends(std::vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch) { unsigned int I; @@ -100,7 +111,7 @@ bool debSrcRecordParser::BuildDepends(vector<pkgSrcRecords::Parser::BuildDepRec> // --------------------------------------------------------------------- /* This parses the list of files and returns it, each file is required to have a complete source package */ -bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List) +bool debSrcRecordParser::Files(std::vector<pkgSrcRecords::File> &List) { List.erase(List.begin(),List.end()); diff --git a/apt-pkg/deb/debsrcrecords.h b/apt-pkg/deb/debsrcrecords.h index aa859b0e6..4c8d03224 100644 --- a/apt-pkg/deb/debsrcrecords.h +++ b/apt-pkg/deb/debsrcrecords.h @@ -24,10 +24,9 @@ class debSrcRecordParser : public pkgSrcRecords::Parser FileFd Fd; pkgTagFile Tags; pkgTagSection Sect; - char *StaticBinList[400]; + std::vector<const char*> StaticBinList; unsigned long iOffset; char *Buffer; - unsigned int BufSize; public: @@ -35,24 +34,24 @@ class debSrcRecordParser : public pkgSrcRecords::Parser virtual bool Step() {iOffset = Tags.Offset(); return Tags.Step(Sect);}; virtual bool Jump(unsigned long const &Off) {iOffset = Off; return Tags.Jump(Sect,Off);}; - virtual string Package() const {return Sect.FindS("Package");}; - virtual string Version() const {return Sect.FindS("Version");}; - virtual string Maintainer() const {return Sect.FindS("Maintainer");}; - virtual string Section() const {return Sect.FindS("Section");}; + virtual std::string Package() const {return Sect.FindS("Package");}; + virtual std::string Version() const {return Sect.FindS("Version");}; + virtual std::string Maintainer() const {return Sect.FindS("Maintainer");}; + virtual std::string Section() const {return Sect.FindS("Section");}; virtual const char **Binaries(); - virtual bool BuildDepends(vector<BuildDepRec> &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch = true); + virtual bool BuildDepends(std::vector<BuildDepRec> &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch = true); virtual unsigned long Offset() {return iOffset;}; - virtual string AsStr() + virtual std::string AsStr() { const char *Start=0,*Stop=0; Sect.GetSection(Start,Stop); - return string(Start,Stop); + return std::string(Start,Stop); }; - virtual bool Files(vector<pkgSrcRecords::File> &F); + virtual bool Files(std::vector<pkgSrcRecords::File> &F); - debSrcRecordParser(string const &File,pkgIndexFile const *Index) + debSrcRecordParser(std::string const &File,pkgIndexFile const *Index) : Parser(Index), Fd(File,FileFd::ReadOnlyGzip), Tags(&Fd,102400), - Buffer(0), BufSize(0) {} + Buffer(NULL) {} virtual ~debSrcRecordParser(); }; diff --git a/apt-pkg/deb/debsystem.cc b/apt-pkg/deb/debsystem.cc index 7644bc66b..7ed6936c3 100644 --- a/apt-pkg/deb/debsystem.cc +++ b/apt-pkg/deb/debsystem.cc @@ -10,6 +10,8 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include <config.h> + #include <apt-pkg/debsystem.h> #include <apt-pkg/debversion.h> #include <apt-pkg/debindexfile.h> @@ -17,13 +19,16 @@ #include <apt-pkg/configuration.h> #include <apt-pkg/error.h> #include <apt-pkg/fileutl.h> -#include <apti18n.h> #include <sys/types.h> #include <unistd.h> #include <dirent.h> #include <errno.h> + +#include <apti18n.h> /*}}}*/ +using std::string; + debSystem debSys; class debSystemPrivate { @@ -216,7 +221,7 @@ signed debSystem::Score(Configuration const &Cnf) // System::AddStatusFiles - Register the status files /*{{{*/ // --------------------------------------------------------------------- /* */ -bool debSystem::AddStatusFiles(vector<pkgIndexFile *> &List) +bool debSystem::AddStatusFiles(std::vector<pkgIndexFile *> &List) { if (d->StatusFile == 0) d->StatusFile = new debStatusIndex(_config->FindFile("Dir::State::status")); diff --git a/apt-pkg/deb/debsystem.h b/apt-pkg/deb/debsystem.h index 232155256..855123516 100644 --- a/apt-pkg/deb/debsystem.h +++ b/apt-pkg/deb/debsystem.h @@ -11,10 +11,12 @@ #define PKGLIB_DEBSYSTEM_H #include <apt-pkg/pkgsystem.h> +#include <apt-pkg/pkgcache.h> class debSystemPrivate; - class debStatusIndex; +class pkgDepCache; + class debSystem : public pkgSystem { // private d-pointer diff --git a/apt-pkg/deb/debversion.cc b/apt-pkg/deb/debversion.cc index 755ffbe96..a02699a44 100644 --- a/apt-pkg/deb/debversion.cc +++ b/apt-pkg/deb/debversion.cc @@ -10,7 +10,7 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#define APT_COMPATIBILITY 986 +#include <config.h> #include <apt-pkg/debversion.h> #include <apt-pkg/pkgcache.h> @@ -127,14 +127,12 @@ int debVersioningSystem::CmpFragment(const char *A,const char *AEnd, int debVersioningSystem::DoCmpVersion(const char *A,const char *AEnd, const char *B,const char *BEnd) { - // Strip off the epoch and compare it - const char *lhs = A; - const char *rhs = B; - for (;lhs != AEnd && *lhs != ':'; lhs++); - for (;rhs != BEnd && *rhs != ':'; rhs++); - if (lhs == AEnd) + // Strip off the epoch and compare it + const char *lhs = (const char*) memchr(A, ':', AEnd - A); + const char *rhs = (const char*) memchr(B, ':', BEnd - B); + if (lhs == NULL) lhs = A; - if (rhs == BEnd) + if (rhs == NULL) rhs = B; // Special case: a zero epoch is the same as no epoch, @@ -169,15 +167,12 @@ int debVersioningSystem::DoCmpVersion(const char *A,const char *AEnd, if (rhs != B) rhs++; - // Find the last - - const char *dlhs = AEnd-1; - const char *drhs = BEnd-1; - for (;dlhs > lhs && *dlhs != '-'; dlhs--); - for (;drhs > rhs && *drhs != '-'; drhs--); - - if (dlhs == lhs) + // Find the last - + const char *dlhs = (const char*) memrchr(lhs, '-', AEnd - lhs); + const char *drhs = (const char*) memrchr(rhs, '-', BEnd - rhs); + if (dlhs == NULL) dlhs = AEnd; - if (drhs == rhs) + if (drhs == NULL) drhs = BEnd; // Compare the main version @@ -262,7 +257,7 @@ bool debVersioningSystem::CheckDep(const char *PkgVer, // debVS::UpstreamVersion - Return the upstream version string /*{{{*/ // --------------------------------------------------------------------- /* This strips all the debian specific information from the version number */ -string debVersioningSystem::UpstreamVersion(const char *Ver) +std::string debVersioningSystem::UpstreamVersion(const char *Ver) { // Strip off the bit before the first colon const char *I = Ver; @@ -277,6 +272,6 @@ string debVersioningSystem::UpstreamVersion(const char *Ver) if (*I == '-') Last = I - Ver; - return string(Ver,Last); + return std::string(Ver,Last); } /*}}}*/ diff --git a/apt-pkg/deb/debversion.h b/apt-pkg/deb/debversion.h index 56fb67887..f1d6f3cc5 100644 --- a/apt-pkg/deb/debversion.h +++ b/apt-pkg/deb/debversion.h @@ -32,39 +32,11 @@ class debVersioningSystem : public pkgVersioningSystem { return DoCmpVersion(A,Aend,B,Bend); } - virtual string UpstreamVersion(const char *A); + virtual std::string UpstreamVersion(const char *A); debVersioningSystem(); }; extern debVersioningSystem debVS; -#ifdef APT_COMPATIBILITY -#if APT_COMPATIBILITY != 986 -#warning "Using APT_COMPATIBILITY" -#endif - -inline int pkgVersionCompare(const char *A, const char *B) -{ - return debVS.CmpVersion(A,B); -} -inline int pkgVersionCompare(const char *A, const char *AEnd, - const char *B, const char *BEnd) -{ - return debVS.DoCmpVersion(A,AEnd,B,BEnd); -} -inline int pkgVersionCompare(string A,string B) -{ - return debVS.CmpVersion(A,B); -} -inline bool pkgCheckDep(const char *DepVer,const char *PkgVer,int Op) -{ - return debVS.CheckDep(PkgVer,Op,DepVer); -} -inline string pkgBaseVersion(const char *Ver) -{ - return debVS.UpstreamVersion(Ver); -} -#endif - #endif diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 61927ff68..4a1bf42d5 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -8,6 +8,8 @@ ##################################################################### */ /*}}}*/ // Includes /*{{{*/ +#include <config.h> + #include <apt-pkg/dpkgpm.h> #include <apt-pkg/error.h> #include <apt-pkg/configuration.h> @@ -16,6 +18,7 @@ #include <apt-pkg/strutl.h> #include <apt-pkg/fileutl.h> #include <apt-pkg/cachefile.h> +#include <apt-pkg/packagemanager.h> #include <unistd.h> #include <stdlib.h> @@ -39,7 +42,6 @@ #include <sys/ioctl.h> #include <pty.h> -#include <config.h> #include <apti18n.h> /*}}}*/ @@ -902,6 +904,28 @@ bool pkgDPkgPM::Go(int OutStatusFd) // create log OpenLog(); + // Generate the base argument list for dpkg + std::vector<const char *> Args; + unsigned long StartSize = 0; + string const Tmp = _config->Find("Dir::Bin::dpkg","dpkg"); + Args.push_back(Tmp.c_str()); + StartSize += Tmp.length(); + + // Stick in any custom dpkg options + Configuration::Item const *Opts = _config->Tree("DPkg::Options"); + if (Opts != 0) + { + Opts = Opts->Child; + for (; Opts != 0; Opts = Opts->Next) + { + if (Opts->Value.empty() == true) + continue; + Args.push_back(Opts->Value.c_str()); + StartSize += Opts->Value.length(); + } + } + size_t const BaseArgs = Args.size(); + // this loop is runs once per operation for (vector<Item>::const_iterator I = List.begin(); I != List.end();) { @@ -923,11 +947,12 @@ bool pkgDPkgPM::Go(int OutStatusFd) for (; J != List.end() && J->Op == I->Op; ++J) /* nothing */; - // Generate the argument list - const char *Args[MaxArgs + 50]; // keep track of allocated strings for multiarch package names - char *Packages[MaxArgs + 50]; - unsigned int pkgcount = 0; + std::vector<char *> Packages; + + // start with the baseset of arguments + unsigned long Size = StartSize; + Args.erase(Args.begin() + BaseArgs, Args.end()); // Now check if we are within the MaxArgs limit // @@ -935,93 +960,70 @@ bool pkgDPkgPM::Go(int OutStatusFd) // the argument list is split in a way that A depends on B // and they are in the same "--configure A B" run // - with the split they may now be configured in different - // runs + // runs, using Immediate-Configure-All can help prevent this. if (J - I > (signed)MaxArgs) + { J = I + MaxArgs; - - unsigned int n = 0; - unsigned long Size = 0; - string const Tmp = _config->Find("Dir::Bin::dpkg","dpkg"); - Args[n++] = Tmp.c_str(); - Size += strlen(Args[n-1]); - - // Stick in any custom dpkg options - Configuration::Item const *Opts = _config->Tree("DPkg::Options"); - if (Opts != 0) + Args.reserve(MaxArgs + 10); + } + else { - Opts = Opts->Child; - for (; Opts != 0; Opts = Opts->Next) - { - if (Opts->Value.empty() == true) - continue; - Args[n++] = Opts->Value.c_str(); - Size += Opts->Value.length(); - } + Args.reserve((J - I) + 10); } + - char status_fd_buf[20]; int fd[2]; pipe(fd); - - Args[n++] = "--status-fd"; - Size += strlen(Args[n-1]); + +#define ADDARG(X) Args.push_back(X); Size += strlen(X) +#define ADDARGC(X) Args.push_back(X); Size += sizeof(X) - 1 + + ADDARGC("--status-fd"); + char status_fd_buf[20]; snprintf(status_fd_buf,sizeof(status_fd_buf),"%i", fd[1]); - Args[n++] = status_fd_buf; - Size += strlen(Args[n-1]); + ADDARG(status_fd_buf); + unsigned long const Op = I->Op; switch (I->Op) { case Item::Remove: - Args[n++] = "--force-depends"; - Size += strlen(Args[n-1]); - Args[n++] = "--force-remove-essential"; - Size += strlen(Args[n-1]); - Args[n++] = "--remove"; - Size += strlen(Args[n-1]); + ADDARGC("--force-depends"); + ADDARGC("--force-remove-essential"); + ADDARGC("--remove"); break; case Item::Purge: - Args[n++] = "--force-depends"; - Size += strlen(Args[n-1]); - Args[n++] = "--force-remove-essential"; - Size += strlen(Args[n-1]); - Args[n++] = "--purge"; - Size += strlen(Args[n-1]); + ADDARGC("--force-depends"); + ADDARGC("--force-remove-essential"); + ADDARGC("--purge"); break; case Item::Configure: - Args[n++] = "--configure"; - Size += strlen(Args[n-1]); + ADDARGC("--configure"); break; case Item::ConfigurePending: - Args[n++] = "--configure"; - Size += strlen(Args[n-1]); - Args[n++] = "--pending"; - Size += strlen(Args[n-1]); + ADDARGC("--configure"); + ADDARGC("--pending"); break; case Item::TriggersPending: - Args[n++] = "--triggers-only"; - Size += strlen(Args[n-1]); - Args[n++] = "--pending"; - Size += strlen(Args[n-1]); + ADDARGC("--triggers-only"); + ADDARGC("--pending"); break; case Item::Install: - Args[n++] = "--unpack"; - Size += strlen(Args[n-1]); - Args[n++] = "--auto-deconfigure"; - Size += strlen(Args[n-1]); + ADDARGC("--unpack"); + ADDARGC("--auto-deconfigure"); break; } if (NoTriggers == true && I->Op != Item::TriggersPending && I->Op != Item::ConfigurePending) { - Args[n++] = "--no-triggers"; - Size += strlen(Args[n-1]); + ADDARGC("--no-triggers"); } +#undef ADDARGC // Write in the file or package names if (I->Op == Item::Install) @@ -1030,10 +1032,10 @@ bool pkgDPkgPM::Go(int OutStatusFd) { if (I->File[0] != '/') return _error->Error("Internal Error, Pathname to install is not absolute '%s'",I->File.c_str()); - Args[n++] = I->File.c_str(); - Size += strlen(Args[n-1]); + Args.push_back(I->File.c_str()); + Size += I->File.length(); } - } + } else { string const nativeArch = _config->Find("APT::Architecture"); @@ -1045,29 +1047,35 @@ bool pkgDPkgPM::Go(int OutStatusFd) if (I->Op == Item::Configure && disappearedPkgs.find(I->Pkg.Name()) != disappearedPkgs.end()) continue; if (I->Pkg.Arch() == nativeArch || !strcmp(I->Pkg.Arch(), "all")) - Args[n++] = I->Pkg.Name(); + { + char const * const name = I->Pkg.Name(); + ADDARG(name); + } else { - Packages[pkgcount] = strdup(I->Pkg.FullName(false).c_str()); - Args[n++] = Packages[pkgcount++]; + char * const fullname = strdup(I->Pkg.FullName(false).c_str()); + Packages.push_back(fullname); + ADDARG(fullname); } - Size += strlen(Args[n-1]); } // skip configure action if all sheduled packages disappeared if (oldSize == Size) continue; } - Args[n] = 0; +#undef ADDARG + J = I; if (_config->FindB("Debug::pkgDPkgPM",false) == true) { - for (unsigned int k = 0; k != n; k++) - clog << Args[k] << ' '; + for (std::vector<const char *>::const_iterator a = Args.begin(); + a != Args.end(); ++a) + clog << *a << ' '; clog << endl; continue; } - + Args.push_back(NULL); + cout << flush; clog << flush; cerr << flush; @@ -1077,8 +1085,13 @@ bool pkgDPkgPM::Go(int OutStatusFd) it to all processes in the group. Since dpkg ignores the signal it doesn't die but we do! So we must also ignore it */ sighandler_t old_SIGQUIT = signal(SIGQUIT,SIG_IGN); - sighandler_t old_SIGINT = signal(SIGINT,SIG_IGN); - + sighandler_t old_SIGINT = signal(SIGINT,SigINT); + + // Check here for any SIGINT + if (pkgPackageManager::SigINTStop && (Op == Item::Remove || Op == Item::Purge || Op == Item::Install)) + break; + + // ignore SIGHUP as well (debian #463030) sighandler_t old_SIGHUP = signal(SIGHUP,SIG_IGN); @@ -1116,7 +1129,6 @@ bool pkgDPkgPM::Go(int OutStatusFd) sigprocmask(SIG_SETMASK, &original_sigmask, 0); } } - // Fork dpkg pid_t Child; _config->Set("APT::Keep-Fds::",fd[1]); @@ -1177,7 +1189,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) /* No Job Control Stop Env is a magic dpkg var that prevents it from using sigstop */ putenv((char *)"DPKG_NO_TSTP=yes"); - execvp(Args[0],(char **)Args); + execvp(Args[0], (char**) &Args[0]); cerr << "Could not exec dpkg!" << endl; _exit(100); } @@ -1203,10 +1215,11 @@ bool pkgDPkgPM::Go(int OutStatusFd) sigemptyset(&sigmask); sigprocmask(SIG_BLOCK,&sigmask,&original_sigmask); - /* clean up the temporary allocation for multiarch package names in - the parent, so we don't leak memory when we return. */ - for (unsigned int i = 0; i < pkgcount; i++) - free(Packages[i]); + /* free vectors (and therefore memory) as we don't need the included data anymore */ + for (std::vector<char *>::const_iterator p = Packages.begin(); + p != Packages.end(); ++p) + free(*p); + Packages.clear(); // the result of the waitpid call int res; @@ -1222,6 +1235,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) // Restore sig int/quit signal(SIGQUIT,old_SIGQUIT); signal(SIGINT,old_SIGINT); + signal(SIGHUP,old_SIGHUP); return _error->Errno("waitpid","Couldn't wait for subprocess"); } @@ -1262,6 +1276,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) // Restore sig int/quit signal(SIGQUIT,old_SIGQUIT); signal(SIGINT,old_SIGINT); + signal(SIGHUP,old_SIGHUP); if(master >= 0) @@ -1299,6 +1314,9 @@ bool pkgDPkgPM::Go(int OutStatusFd) } } CloseLog(); + + if (pkgPackageManager::SigINTStop) + _error->Warning(_("Operation was interrupted before it could finish")); if (RunScripts("DPkg::Post-Invoke") == false) return false; @@ -1323,6 +1341,11 @@ bool pkgDPkgPM::Go(int OutStatusFd) Cache.writeStateFile(NULL); return true; } + +void SigINT(int sig) { + if (_config->FindB("APT::Immediate-Configure-All",false)) + pkgPackageManager::SigINTStop = true; +} /*}}}*/ // pkgDpkgPM::Reset - Dump the contents of the command list /*{{{*/ // --------------------------------------------------------------------- diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h index ddf9485c7..6b62360b7 100644 --- a/apt-pkg/deb/dpkgpm.h +++ b/apt-pkg/deb/dpkgpm.h @@ -15,9 +15,6 @@ #include <map> #include <stdio.h> -using std::vector; -using std::map; - class pkgDPkgPMPrivate; class pkgDPkgPM : public pkgPackageManager @@ -38,7 +35,7 @@ class pkgDPkgPM : public pkgPackageManager needs to declare a Replaces on the disappeared package. \param pkgname Name of the package that disappeared */ - void handleDisappearAction(string const &pkgname); + void handleDisappearAction(std::string const &pkgname); protected: int pkgFailures; @@ -53,11 +50,11 @@ class pkgDPkgPM : public pkgPackageManager // the dpkg states that the pkg will run through, the string is // the package, the vector contains the dpkg states that the package // will go through - map<string,vector<struct DpkgState> > PackageOps; + std::map<std::string,std::vector<struct DpkgState> > PackageOps; // the dpkg states that are already done; the string is the package // the int is the state that is already done (e.g. a package that is // going to be install is already in state "half-installed") - map<string,unsigned int> PackageOpsDone; + std::map<std::string,unsigned int> PackageOpsDone; // progress reporting unsigned int PackagesDone; @@ -66,19 +63,19 @@ class pkgDPkgPM : public pkgPackageManager struct Item { enum Ops {Install, Configure, Remove, Purge, ConfigurePending, TriggersPending} Op; - string File; + std::string File; PkgIterator Pkg; - Item(Ops Op,PkgIterator Pkg,string File = "") : Op(Op), + Item(Ops Op,PkgIterator Pkg,std::string File = "") : Op(Op), File(File), Pkg(Pkg) {}; Item() {}; }; - vector<Item> List; + std::vector<Item> List; // Helpers bool RunScriptsWithPkgs(const char *Cnf); bool SendV2Pkgs(FILE *F); - void WriteHistoryTag(string const &tag, string value); + void WriteHistoryTag(std::string const &tag, std::string value); // apport integration void WriteApportReport(const char *pkgpath, const char *errormsg); @@ -94,7 +91,7 @@ class pkgDPkgPM : public pkgPackageManager void ProcessDpkgStatusLine(int OutStatusFd, char *line); // The Actuall installation implementation - virtual bool Install(PkgIterator Pkg,string File); + virtual bool Install(PkgIterator Pkg,std::string File); virtual bool Configure(PkgIterator Pkg); virtual bool Remove(PkgIterator Pkg,bool Purge = false); virtual bool Go(int StatusFd=-1); @@ -106,4 +103,6 @@ class pkgDPkgPM : public pkgPackageManager virtual ~pkgDPkgPM(); }; +void SigINT(int sig); + #endif |