From 671b7116373153c6498bffafc7d0312b67ffb069 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 27 Mar 2012 15:14:38 +0200 Subject: * apt-pkg/deb/dpkgpm.cc: - do not crash if (*I).Pkg is NULL (LP: #939867) --- apt-pkg/deb/dpkgpm.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index c46a81209..be11870fd 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1595,7 +1595,10 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg) const char *ops_str[] = {"Install", "Configure","Remove","Purge"}; fprintf(report, "AptOrdering:\n"); for (vector::iterator I = List.begin(); I != List.end(); ++I) - fprintf(report, " %s: %s\n", (*I).Pkg.Name(), ops_str[(*I).Op]); + if ((*I).Pkg != NULL) + fprintf(report, " %s: %s\n", (*I).Pkg.Name(), ops_str[(*I).Op]); + else + fprintf(report, " %s: %s\n", "NULL", ops_str[(*I).Op]); // attach dmesg log (to learn about segfaults) if (FileExists("/bin/dmesg")) -- cgit v1.2.3 From 5ab7b53b09c508eb551eaf698bd2035cd3bc8777 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 16 Apr 2012 23:55:39 +0200 Subject: =?UTF-8?q?*=20apt-pkg/packagemanager.cc:=20=20=20-=20init=20count?= =?UTF-8?q?er=20in=20SmartConfigure=20so=20that=20the=20loop-breaker=20isn?= =?UTF-8?q?'t=20=20=20=20=20triggered=20at=20random=E2=80=A6=20(Closes:=20?= =?UTF-8?q?#669060)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apt-pkg/packagemanager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index c62c4d187..093999bc2 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -602,7 +602,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c or by the ConfigureAll call at the end of the for loop in OrderInstall. */ bool Changed = false; const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 500); - unsigned int i; + unsigned int i = 0; do { Changed = false; -- cgit v1.2.3 From bce0e0ff327341da3ad54d7ea2bb6d82b3f96879 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 17 Apr 2012 23:47:35 +0200 Subject: newer gcc versions seems to have no problem with that, but while working with g++-4.1 it complains about this so lets be extra clear --- apt-pkg/cacheset.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index 6f0a0e358..5b9900603 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -186,7 +186,7 @@ public: /*{{{*/ pkgCache::PkgIterator getPkg(void) const { return *_iter; } inline pkgCache::PkgIterator operator*(void) const { return *_iter; }; operator typename Container::iterator(void) const { return _iter; } - operator typename PackageContainer::const_iterator() { return PackageContainer::const_iterator(_iter); } + operator typename PackageContainer::const_iterator() { return typename PackageContainer::const_iterator(_iter); } inline iterator& operator++() { ++_iter; return *this; } inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; } inline bool operator!=(iterator const &i) const { return _iter != i._iter; }; @@ -506,7 +506,7 @@ public: /*{{{*/ pkgCache::VerIterator getVer(void) const { return *_iter; } inline pkgCache::VerIterator operator*(void) const { return *_iter; }; operator typename Container::iterator(void) const { return _iter; } - operator typename VersionContainer::const_iterator() { return VersionContainer::const_iterator(_iter); } + operator typename VersionContainer::const_iterator() { return typename VersionContainer::const_iterator(_iter); } inline iterator& operator++() { ++_iter; return *this; } inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; } inline bool operator!=(iterator const &i) const { return _iter != i._iter; }; -- cgit v1.2.3 From a552f37ebad5718bba7767e606f3cca13690fbd8 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 18 Apr 2012 18:13:30 +0200 Subject: * apt-pkg/deb/deblistparser.cc: - only treat the native apt as essential by default --- apt-pkg/deb/deblistparser.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 84e6c38c5..00e2bd900 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -249,8 +249,14 @@ bool debListParser::UsePackage(pkgCache::PkgIterator &Pkg, return false; if (strcmp(Pkg.Name(),"apt") == 0) - Pkg->Flags |= pkgCache::Flag::Essential | pkgCache::Flag::Important; - + { + if ((essential == "native" && Pkg->Arch != 0 && myArch == Pkg.Arch()) || + essential == "all") + Pkg->Flags |= pkgCache::Flag::Essential | pkgCache::Flag::Important; + else + Pkg->Flags |= pkgCache::Flag::Important; + } + if (ParseStatus(Pkg,Ver) == false) return false; return true; -- cgit v1.2.3 From 0b4895d3d223c97c6ba1ece9f7b88479debb7fb7 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 19 Apr 2012 11:05:41 +0200 Subject: * apt-pkg/contrib/fileutl.cc: - redirect stderr from compressors to /dev/null --- apt-pkg/contrib/fileutl.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 9e3611b26..e9d1ba1ce 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1098,6 +1098,12 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C dup2(d->compressed_fd,STDIN_FILENO); dup2(Pipe[1],STDOUT_FILENO); } + int const nullfd = open("/dev/null", O_WRONLY); + if (nullfd != -1) + { + dup2(nullfd,STDERR_FILENO); + close(nullfd); + } SetCloseExec(STDOUT_FILENO,false); SetCloseExec(STDIN_FILENO,false); -- cgit v1.2.3 From d8e25d34e89d66b4c38d6b19b4bb2af08f5bd019 Mon Sep 17 00:00:00 2001 From: Malcolm Scott Date: Thu, 19 Apr 2012 22:38:30 +0200 Subject: * apt-pkg/packagemanager.cc: - iterate over all pre-depends or-group member instead of looping endlessly over the first member in SmartUnpack (LP: #985852) --- apt-pkg/packagemanager.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 093999bc2..b56619ef5 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -621,7 +621,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c // Look for easy targets: packages that are already okay for (DepIterator Cur = Start; Bad == true; ++Cur) { - SPtrArray VList = Start.AllTargets(); + SPtrArray VList = Cur.AllTargets(); for (Version **I = VList; *I != 0; ++I) { VerIterator Ver(Cache,*I); @@ -644,7 +644,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c // Look for something that could be configured. for (DepIterator Cur = Start; Bad == true; ++Cur) { - SPtrArray VList = Start.AllTargets(); + SPtrArray VList = Cur.AllTargets(); for (Version **I = VList; *I != 0; ++I) { VerIterator Ver(Cache,*I); -- cgit v1.2.3 From d4621f8277a76f3e5c87b06f7abd93df04446efc Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 20 Apr 2012 09:12:56 +0200 Subject: cherry pick r1975 from lp:~ubuntu-core-dev/apt/ubuntu --- apt-pkg/deb/dpkgpm.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index be11870fd..14376f649 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -738,6 +738,7 @@ bool pkgDPkgPM::OpenLog() d->history_out = fopen(history_name.c_str(),"a"); if (d->history_out == NULL) return _error->WarningE("OpenLog", _("Could not open file '%s'"), history_name.c_str()); + SetCloseExec(fileno(d->history_out), true); chmod(history_name.c_str(), 0644); fprintf(d->history_out, "\nStart-Date: %s\n", timestr); string remove, purge, install, reinstall, upgrade, downgrade; -- cgit v1.2.3 From 858fd39f6adea6353e9367759cf48ae2b439ffcc Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 20 Apr 2012 09:52:17 +0200 Subject: * apt-pkg/aptconfiguration.cc: - if the compressor is not installed, but we link against it's library accept it as a CompressionType (Closes: #669328) --- apt-pkg/aptconfiguration.cc | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index d72b0c5ae..f0cd8ebc0 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -47,6 +47,7 @@ const Configuration::getCompressionTypes(bool const &Cached) { _config->CndSet("Acquire::CompressionTypes::gz","gzip"); setDefaultConfigurationForCompressors(); + std::vector const compressors = getCompressors(); // accept non-list order as override setting for config settings on commandline std::string const overrideOrder = _config->Find("Acquire::CompressionTypes::Order",""); @@ -63,12 +64,12 @@ const Configuration::getCompressionTypes(bool const &Cached) { if (_config->Exists(std::string("Acquire::CompressionTypes::").append(*o)) == false) continue; // ignore types we have no app ready to use - std::string const appsetting = std::string("Dir::Bin::").append(*o); - if (_config->Exists(appsetting) == true) { - std::string const app = _config->FindFile(appsetting.c_str(), ""); - if (app.empty() == false && FileExists(app) == false) - continue; - } + std::vector::const_iterator c = compressors.begin(); + for (; c != compressors.end(); ++c) + if (c->Name == *o) + break; + if (c == compressors.end()) + continue; types.push_back(*o); } @@ -84,12 +85,12 @@ const Configuration::getCompressionTypes(bool const &Cached) { if (std::find(types.begin(),types.end(),Types->Tag) != types.end()) continue; // ignore types we have no app ready to use - std::string const appsetting = std::string("Dir::Bin::").append(Types->Value); - if (appsetting.empty() == false && _config->Exists(appsetting) == true) { - std::string const app = _config->FindFile(appsetting.c_str(), ""); - if (app.empty() == false && FileExists(app) == false) - continue; - } + std::vector::const_iterator c = compressors.begin(); + for (; c != compressors.end(); ++c) + if (c->Name == Types->Value) + break; + if (c == compressors.end()) + continue; types.push_back(Types->Tag); } -- cgit v1.2.3 From 5149632eb5af0831a8728e8bb5d5c483d6e3f147 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 20 Apr 2012 09:53:24 +0200 Subject: * apt-pkg/contrib/sha2_internal.cc: - do not use the input data directly but memcpy it instead as it could be unaligned as in the http-transport which causes a sigbus error on sparc (Closes: #669061) --- apt-pkg/contrib/sha2_internal.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/sha2_internal.cc b/apt-pkg/contrib/sha2_internal.cc index 6d27e8f2b..83b5a98d3 100644 --- a/apt-pkg/contrib/sha2_internal.cc +++ b/apt-pkg/contrib/sha2_internal.cc @@ -552,7 +552,9 @@ void SHA256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) { } while (len >= SHA256_BLOCK_LENGTH) { /* Process as many complete blocks as we can */ - SHA256_Transform(context, (sha2_word32*)data); + sha2_byte buffer[SHA256_BLOCK_LENGTH]; + MEMCPY_BCOPY(buffer, data, SHA256_BLOCK_LENGTH); + SHA256_Transform(context, (sha2_word32*)buffer); context->bitcount += SHA256_BLOCK_LENGTH << 3; len -= SHA256_BLOCK_LENGTH; data += SHA256_BLOCK_LENGTH; @@ -879,7 +881,9 @@ void SHA512_Update(SHA512_CTX* context, const sha2_byte *data, size_t len) { } while (len >= SHA512_BLOCK_LENGTH) { /* Process as many complete blocks as we can */ - SHA512_Transform(context, (sha2_word64*)data); + sha2_byte buffer[SHA512_BLOCK_LENGTH]; + MEMCPY_BCOPY(buffer, data, SHA512_BLOCK_LENGTH); + SHA512_Transform(context, (sha2_word64*)buffer); ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3); len -= SHA512_BLOCK_LENGTH; data += SHA512_BLOCK_LENGTH; -- cgit v1.2.3 From e6a12579e9e5d5735eda450cf2bb3986d828ab65 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 20 Apr 2012 10:13:17 +0200 Subject: * apt-pkg/cacheset.cc: - actually return to the fallback modifier if we have detected we should for packagenames which look like modifiers (Closes: #669591) --- apt-pkg/cacheset.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc index b892ab4bf..e2dbe0e57 100644 --- a/apt-pkg/cacheset.cc +++ b/apt-pkg/cacheset.cc @@ -217,6 +217,7 @@ bool PackageContainerInterface::FromModifierCommandLine(unsigned short &modID, P pkgCacheFile &Cache, const char * cmdline, std::list const &mods, CacheSetHelper &helper) { std::string str = cmdline; + unsigned short fallback = modID; bool modifierPresent = false; for (std::list::const_iterator mod = mods.begin(); mod != mods.end(); ++mod) { @@ -243,6 +244,7 @@ bool PackageContainerInterface::FromModifierCommandLine(unsigned short &modID, P helper.showErrors(errors); if (Pkg.end() == false) { pci->insert(Pkg); + modID = fallback; return true; } } @@ -281,13 +283,14 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID, modifierPresent = true; break; } - if (modifierPresent == true) { bool const errors = helper.showErrors(false); bool const found = VersionContainerInterface::FromString(vci, Cache, cmdline, select, helper, true); helper.showErrors(errors); - if (found == true) + if (found == true) { + modID = fallback; return true; + } } return FromString(vci, Cache, str, select, helper); } -- cgit v1.2.3 From 79b207bc0a3a7d9cef91f96e6061ea35451c563a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 20 Apr 2012 11:05:35 +0200 Subject: fix a bug uncovered by the previous commit which checks if a Compressor preference given by the Order setting is really available before adding it as possible CompressionType. --- apt-pkg/aptconfiguration.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index f0cd8ebc0..e1225b3e6 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -61,12 +61,14 @@ const Configuration::getCompressionTypes(bool const &Cached) { if ((*o).empty() == true) continue; // ignore types we have no method ready to use - if (_config->Exists(std::string("Acquire::CompressionTypes::").append(*o)) == false) + std::string const method = std::string("Acquire::CompressionTypes::").append(*o); + if (_config->Exists(method) == false) continue; // ignore types we have no app ready to use + std::string const app = _config->Find(method); std::vector::const_iterator c = compressors.begin(); for (; c != compressors.end(); ++c) - if (c->Name == *o) + if (c->Name == app) break; if (c == compressors.end()) continue; -- cgit v1.2.3 From 5076b3c220bb6e9e99d79d390e919da132b67215 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 21 Apr 2012 18:26:49 +0200 Subject: * apt-pkg/contrib/strutl.cc: - remove the message size limit from ioprintf and strprintf --- apt-pkg/contrib/strutl.cc | 57 ++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 20 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 99efa8d98..ca096d736 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -1168,34 +1169,50 @@ unsigned long RegexChoice(RxChoiceList *Rxs,const char **ListBegin, return Hits; } /*}}}*/ -// ioprintf - C format string outputter to C++ iostreams /*{{{*/ +// {str,io}printf - C format string outputter to C++ strings/iostreams /*{{{*/ // --------------------------------------------------------------------- /* This is used to make the internationalization strings easier to translate and to allow reordering of parameters */ -void ioprintf(ostream &out,const char *format,...) +static bool iovprintf(ostream &out, const char *format, + va_list &args, ssize_t &size) { + char *S = (char*)malloc(size); + ssize_t const n = vsnprintf(S, size, format, args); + if (n > -1 && n < size) { + out << S; + free(S); + return true; + } else { + if (n > -1) + size = n + 1; + else + size *= 2; + } + free(S); + return false; +} +void ioprintf(ostream &out,const char *format,...) { va_list args; - va_start(args,format); - - // sprintf the description - char S[4096]; - vsnprintf(S,sizeof(S),format,args); - out << S; + ssize_t size = 400; + while (true) { + va_start(args,format); + if (iovprintf(out, format, args, size) == true) + return; + va_end(args); + } } - /*}}}*/ -// strprintf - C format string outputter to C++ strings /*{{{*/ -// --------------------------------------------------------------------- -/* This is used to make the internationalization strings easier to translate - and to allow reordering of parameters */ -void strprintf(string &out,const char *format,...) +void strprintf(string &out,const char *format,...) { va_list args; - va_start(args,format); - - // sprintf the description - char S[4096]; - vsnprintf(S,sizeof(S),format,args); - out = string(S); + ssize_t size = 400; + std::ostringstream outstr; + while (true) { + va_start(args,format); + if (iovprintf(outstr, format, args, size) == true) + break; + va_end(args); + } + out = outstr.str(); } /*}}}*/ // safe_snprintf - Safer snprintf /*{{{*/ -- cgit v1.2.3 From 2f4162708d9db7c71590370cc998d46e8386c757 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 22 Apr 2012 12:28:10 +0200 Subject: * apt-pkg/contrib/configuration.cc: - add a more versatile Dump() method --- apt-pkg/contrib/configuration.cc | 72 +++++++++++++++++++++++++++++++++++----- apt-pkg/contrib/configuration.h | 2 ++ 2 files changed, 66 insertions(+), 8 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index 36866a35a..ff80dfaf8 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -482,24 +482,80 @@ bool Configuration::ExistsAny(const char *Name) const /* Dump the entire configuration space */ void Configuration::Dump(ostream& str) { - /* Write out all of the configuration directives by walking the + Dump(str, NULL, "%f \"%v\";\n", true); +} +void Configuration::Dump(ostream& str, char const * const root, + char const * const formatstr, bool const emptyValue) +{ + const Configuration::Item* Top = Tree(root); + if (Top == 0) + return; + const Configuration::Item* const Root = (root == NULL) ? NULL : Top; + std::vector const format = VectorizeString(formatstr, '%'); + + /* Write out all of the configuration directives by walking the configuration tree */ - const Configuration::Item *Top = Tree(0); - for (; Top != 0;) - { - str << Top->FullTag() << " \"" << Top->Value << "\";" << endl; - + do { + if (emptyValue == true || Top->Value.empty() == emptyValue) + { + std::vector::const_iterator f = format.begin(); + str << *f; + for (++f; f != format.end(); ++f) + { + if (f->empty() == true) + { + ++f; + str << '%' << *f; + continue; + } + char const type = (*f)[0]; + if (type == 'f') + str << Top->FullTag(); + else if (type == 't') + str << Top->Tag; + else if (type == 'v') + str << Top->Value; + else if (type == 'F') + str << QuoteString(Top->FullTag(), "=\"\n"); + else if (type == 'T') + str << QuoteString(Top->Tag, "=\"\n"); + else if (type == 'V') + str << QuoteString(Top->Value, "=\"\n"); + else if (type == 'n') + str << "\n"; + else if (type == 'N') + str << "\t"; + else + str << '%' << type; + str << f->c_str() + 1; + } + } + if (Top->Child != 0) { Top = Top->Child; continue; } - + while (Top != 0 && Top->Next == 0) Top = Top->Parent; if (Top != 0) Top = Top->Next; - } + + if (Root != NULL) + { + const Configuration::Item* I = Top; + while(I != 0) + { + if (I == Root) + break; + else + I = I->Parent; + } + if (I == 0) + break; + } + } while (Top != 0); } /*}}}*/ diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h index 4c2e75041..ea94c2fe6 100644 --- a/apt-pkg/contrib/configuration.h +++ b/apt-pkg/contrib/configuration.h @@ -103,6 +103,8 @@ class Configuration inline void Dump() { Dump(std::clog); }; void Dump(std::ostream& str); + void Dump(std::ostream& str, char const * const root, + char const * const format, bool const emptyValue); Configuration(const Item *Root); Configuration(); -- cgit v1.2.3 From d280d03ac50f2b49f7c08f825dccdebf61b62c57 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 22 Apr 2012 12:28:54 +0200 Subject: * apt-pkg/acquire-worker.cc: - use Dump() to generate the configuration message for sending --- apt-pkg/acquire-worker.cc | 39 +++++++++------------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc index 77e2fc311..8bc043c58 100644 --- a/apt-pkg/acquire-worker.cc +++ b/apt-pkg/acquire-worker.cc @@ -467,40 +467,19 @@ bool pkgAcquire::Worker::SendConfiguration() if (OutFd == -1) return false; - - string Message = "601 Configuration\n"; - Message.reserve(2000); - /* Write out all of the configuration directives by walking the + /* Write out all of the configuration directives by walking the configuration tree */ - const Configuration::Item *Top = _config->Tree(0); - for (; Top != 0;) - { - if (Top->Value.empty() == false) - { - string Line = "Config-Item: " + QuoteString(Top->FullTag(),"=\"\n") + "="; - Line += QuoteString(Top->Value,"\n") + '\n'; - Message += Line; - } - - if (Top->Child != 0) - { - Top = Top->Child; - continue; - } - - while (Top != 0 && Top->Next == 0) - Top = Top->Parent; - if (Top != 0) - Top = Top->Next; - } - Message += '\n'; + std::ostringstream Message; + Message << "601 Configuration\n"; + _config->Dump(Message, NULL, "Config-Item: %F=%V\n", false); + Message << '\n'; if (Debug == true) - clog << " -> " << Access << ':' << QuoteString(Message,"\n") << endl; - OutQueue += Message; - OutReady = true; - + clog << " -> " << Access << ':' << QuoteString(Message.str(),"\n") << endl; + OutQueue += Message.str(); + OutReady = true; + return true; } /*}}}*/ -- cgit v1.2.3 From 849e64ac558c5c72a65b6ee0098fdfc538eca5e6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 22 Apr 2012 13:01:37 +0200 Subject: * apt-pkg/cdrom.cc: - use Dump() to generate the configuration output --- apt-pkg/cdrom.cc | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index 50c204371..c10ca6bd1 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -409,27 +409,10 @@ bool pkgCdrom::WriteDatabase(Configuration &Cnf) /* Write out all of the configuration directives by walking the configuration tree */ - const Configuration::Item *Top = Cnf.Tree(0); - for (; Top != 0;) - { - // Print the config entry - if (Top->Value.empty() == false) - Out << Top->FullTag() + " \"" << Top->Value << "\";" << endl; - - if (Top->Child != 0) - { - Top = Top->Child; - continue; - } - - while (Top != 0 && Top->Next == 0) - Top = Top->Parent; - if (Top != 0) - Top = Top->Next; - } + _config->Dump(Out, NULL, "%f \"%v\";\n", false); Out.close(); - + if (FileExists(DFile) == true && link(DFile.c_str(),string(DFile + '~').c_str()) != 0) return _error->Errno("link", "Failed to link %s to %s~", DFile.c_str(), DFile.c_str()); if (rename(NewFile.c_str(),DFile.c_str()) != 0) -- cgit v1.2.3 From 074da0970c68879d548b6b4f64d0da7f38151248 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 23 Apr 2012 17:46:11 +0200 Subject: * apt-pkg/depcache.cc: - clearly separate 'positive' and 'negative' dependencies and their upgrade-resolution tries in MarkInstall and especially don't treat Conflicts differently compared to Breaks here --- apt-pkg/depcache.cc | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 1eea55560..daf7c8c4d 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -1152,9 +1152,8 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, } /* This bit is for processing the possibilty of an install/upgrade - fixing the problem */ - if (Start->Type != Dep::DpkgBreaks && - (DepState[Start->ID] & DepCVer) == DepCVer) + fixing the problem for "positive" dependencies */ + if (Start.IsNegative() == false && (DepState[Start->ID] & DepCVer) == DepCVer) { APT::VersionList verlist; pkgCache::VerIterator Cand = PkgState[Start.TargetPkg()->ID].CandidateVerIter(*this); @@ -1198,13 +1197,13 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, } continue; } - - /* For conflicts we just de-install the package and mark as auto, - Conflicts may not have or groups. For dpkg's Breaks we try to - upgrade the package. */ - if (Start.IsNegative() == true) + /* Negative dependencies have no or-group + If the dependency isn't versioned, we try if an upgrade might solve the problem. + Otherwise we remove the offender if needed */ + else if (Start.IsNegative() == true && Start->Type != pkgCache::Dep::Obsoletes) { SPtrArray List = Start.AllTargets(); + pkgCache::PkgIterator TrgPkg = Start.TargetPkg(); for (Version **I = List; *I != 0; I++) { VerIterator Ver(*this,*I); @@ -1215,15 +1214,17 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, if (PkgState[Pkg->ID].InstallVer == 0) continue; - if (PkgState[Pkg->ID].CandidateVer != *I && - Start->Type == Dep::DpkgBreaks && + if ((Start->Version != 0 || TrgPkg != Pkg) && + PkgState[Pkg->ID].CandidateVer != PkgState[Pkg->ID].InstallVer && + PkgState[Pkg->ID].CandidateVer != *I && MarkInstall(Pkg,true,Depth + 1, false, ForceImportantDeps) == true) continue; - else if (MarkDelete(Pkg,false,Depth + 1, false) == false) + else if ((Start->Type == pkgCache::Dep::Conflicts || Start->Type == pkgCache::Dep::DpkgBreaks) && + MarkDelete(Pkg,false,Depth + 1, false) == false) break; } continue; - } + } } return Dep.end() == true; -- cgit v1.2.3 From ecdc4e74bc5ba7eadeff3276bc3707c127d9989c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 23 Apr 2012 18:24:19 +0200 Subject: * edsp/edspsystem.cc: - check with RealFileExists for scenario file as otherwise a directory like one provided with RootDir triggers the usage of EDSP --- apt-pkg/edsp/edspsystem.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/edsp/edspsystem.cc b/apt-pkg/edsp/edspsystem.cc index 6b9207451..aae969d9d 100644 --- a/apt-pkg/edsp/edspsystem.cc +++ b/apt-pkg/edsp/edspsystem.cc @@ -91,7 +91,7 @@ signed edspSystem::Score(Configuration const &Cnf) { if (Cnf.Find("edsp::scenario", "") == "stdin") return 1000; - if (FileExists(Cnf.FindFile("edsp::scenario","")) == true) + if (RealFileExists(Cnf.FindFile("edsp::scenario","")) == true) return 1000; return -1000; } -- cgit v1.2.3 From ec76891fa17c77f8fd28b9b6e11ef2d7547afe7e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 23 Apr 2012 19:11:11 +0200 Subject: normalize a bit by replacing // and /./ with / in FindFile --- apt-pkg/contrib/configuration.cc | 68 ++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 30 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index ff80dfaf8..ce02f1bd2 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -171,48 +171,56 @@ string Configuration::Find(const char *Name,const char *Default) const string Configuration::FindFile(const char *Name,const char *Default) const { const Item *RootItem = Lookup("RootDir"); - std::string rootDir = (RootItem == 0) ? "" : RootItem->Value; - if(rootDir.size() > 0 && rootDir[rootDir.size() - 1] != '/') - rootDir.push_back('/'); + std::string result = (RootItem == 0) ? "" : RootItem->Value; + if(result.empty() == false && result[result.size() - 1] != '/') + result.push_back('/'); const Item *Itm = Lookup(Name); if (Itm == 0 || Itm->Value.empty() == true) { - if (Default == 0) - return rootDir; - else - return rootDir + Default; + if (Default != 0) + result.append(Default); } - - string val = Itm->Value; - while (Itm->Parent != 0) + else { - if (Itm->Parent->Value.empty() == true) + string val = Itm->Value; + while (Itm->Parent != 0) { - Itm = Itm->Parent; - continue; - } + if (Itm->Parent->Value.empty() == true) + { + Itm = Itm->Parent; + continue; + } - // Absolute - if (val.length() >= 1 && val[0] == '/') - break; + // Absolute + if (val.length() >= 1 && val[0] == '/') + break; - // ~/foo or ./foo - if (val.length() >= 2 && (val[0] == '~' || val[0] == '.') && val[1] == '/') - break; - - // ../foo - if (val.length() >= 3 && val[0] == '.' && val[1] == '.' && val[2] == '/') - break; - - if (Itm->Parent->Value.end()[-1] != '/') - val.insert(0, "/"); + // ~/foo or ./foo + if (val.length() >= 2 && (val[0] == '~' || val[0] == '.') && val[1] == '/') + break; + + // ../foo + if (val.length() >= 3 && val[0] == '.' && val[1] == '.' && val[2] == '/') + break; + + if (Itm->Parent->Value.end()[-1] != '/') + val.insert(0, "/"); - val.insert(0, Itm->Parent->Value); - Itm = Itm->Parent; + val.insert(0, Itm->Parent->Value); + Itm = Itm->Parent; + } + result.append(val); } - return rootDir + val; + // do some normalisation by removing // and /./ from the path + size_t found = string::npos; + while ((found = result.find("/./")) != string::npos) + result.replace(found, 3, "/"); + while ((found = result.find("//")) != string::npos) + result.replace(found, 2, "/"); + + return result; } /*}}}*/ // Configuration::FindDir - Find a directory name /*{{{*/ -- cgit v1.2.3 From af13d1437cbcb383de89f126b316c02587e4b691 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 23 Apr 2012 19:33:32 +0200 Subject: /dev/null is a special absolute path as it has no subdirectories --- apt-pkg/contrib/configuration.cc | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index ce02f1bd2..4de17e3e1 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -194,7 +194,11 @@ string Configuration::FindFile(const char *Name,const char *Default) const // Absolute if (val.length() >= 1 && val[0] == '/') + { + if (val.compare(0, 9, "/dev/null") == 0) + val.erase(9); break; + } // ~/foo or ./foo if (val.length() >= 2 && (val[0] == '~' || val[0] == '.') && val[1] == '/') @@ -230,7 +234,12 @@ string Configuration::FindDir(const char *Name,const char *Default) const { string Res = FindFile(Name,Default); if (Res.end()[-1] != '/') + { + size_t const found = Res.rfind("/dev/null"); + if (found != string::npos && found == Res.size() - 9) + return Res; // /dev/null returning return Res + '/'; + } return Res; } /*}}}*/ -- cgit v1.2.3 From cc04f4ce9eaaf0945775d5233806de7da5d21ff6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 23 Apr 2012 22:03:23 +0200 Subject: provider is only a possible solution if the provides has the right version (or none as we have no versioned provides in debian) and not if the version of the provider matches --- apt-pkg/depcache.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index daf7c8c4d..2656e9b42 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -1164,7 +1164,7 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, pkgCache::VerIterator V = Prv.OwnerVer(); pkgCache::VerIterator Cand = PkgState[Prv.OwnerPkg()->ID].CandidateVerIter(*this); if (Cand.end() == true || V != Cand || - VS().CheckDep(Cand.VerStr(), Start->CompareOp, Start.TargetVer()) == false) + VS().CheckDep(Prv.ProvideVersion(), Start->CompareOp, Start.TargetVer()) == false) continue; verlist.insert(Cand); } -- cgit v1.2.3 From 5954d4d2020a247d414c7e064a87f9464be85fcf Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 2 May 2012 22:00:02 +0200 Subject: * apt-pkg/pkgcachegen.cc: - check if NewDescription allocation has failed and error out accordingly --- apt-pkg/pkgcachegen.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index ec072fddd..5e0726f3b 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -304,6 +304,9 @@ bool pkgCacheGenerator::MergeListPackage(ListParser &List, pkgCache::PkgIterator void const * const oldMap = Map.Data(); map_ptrloc const descindex = NewDescription(Desc, CurLang, CurMd5, *LastDesc); + if (unlikely(descindex == 0 && _error->PendingError())) + return _error->Error(_("Error occurred while processing %s (%s%d)"), + Pkg.Name(), "NewDescription", 1); if (oldMap != Map.Data()) LastDesc += (map_ptrloc*) Map.Data() - (map_ptrloc*) oldMap; *LastDesc = descindex; @@ -456,6 +459,9 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator oldMap = Map.Data(); map_ptrloc const descindex = NewDescription(Desc, CurLang, CurMd5, *LastDesc); + if (unlikely(descindex == 0 && _error->PendingError())) + return _error->Error(_("Error occurred while processing %s (%s%d)"), + Pkg.Name(), "NewDescription", 2); if (oldMap != Map.Data()) LastDesc += (map_ptrloc*) Map.Data() - (map_ptrloc*) oldMap; *LastDesc = descindex; -- cgit v1.2.3 From fc691496f22e75f5bbb127cf6baff793898220ca Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 2 May 2012 22:31:49 +0200 Subject: * apt-pkg/deb/deblistparser.cc: - check length and containing chars for a given description md5sum --- apt-pkg/deb/deblistparser.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 00e2bd900..7bef6772c 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -215,15 +215,22 @@ string debListParser::DescriptionLanguage() */ MD5SumValue debListParser::Description_md5() { - string value = Section.FindS("Description-md5"); - - if (value.empty()) + string const value = Section.FindS("Description-md5"); + if (value.empty() == true) { MD5Summation md5; md5.Add((Description() + "\n").c_str()); return md5.Result(); - } else - return MD5SumValue(value); + } + else if (likely(value.size() == 32)) + { + if (likely(value.find_first_not_of("0123456789abcdefABCDEF") == string::npos)) + return MD5SumValue(value); + _error->Error("Malformed Description-md5 line; includes invalid character '%s'", value.c_str()); + return MD5SumValue(); + } + _error->Error("Malformed Description-md5 line; doesn't have the required length (32 != %d) '%s'", (int)value.size(), value.c_str()); + return MD5SumValue(); } /*}}}*/ // ListParser::UsePackage - Update a package structure /*{{{*/ -- cgit v1.2.3 From 7f5aab82708813d86aab04029095988f40a8462e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 May 2012 02:06:49 +0200 Subject: check if we work on a valid description in IsDuplicateDescription as we end up working on dangling pointers otherwise which segfaults on s390x and ppc64 (Closes: #669427) --- apt-pkg/pkgcachegen.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 5e0726f3b..d455e4070 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -286,7 +286,7 @@ bool pkgCacheGenerator::MergeListPackage(ListParser &List, pkgCache::PkgIterator pkgCache::DescIterator Desc = Ver.DescriptionList(); // a version can only have one md5 describing it - if (MD5SumValue(Desc.md5()) != CurMd5) + if (Desc.end() == true || MD5SumValue(Desc.md5()) != CurMd5) continue; // don't add a new description if we have one for the given @@ -1459,7 +1459,7 @@ bool IsDuplicateDescription(pkgCache::DescIterator Desc, MD5SumValue const &CurMd5, std::string const &CurLang) { // Descriptions in the same link-list have all the same md5 - if (MD5SumValue(Desc.md5()) != CurMd5) + if (Desc.end() == true || MD5SumValue(Desc.md5()) != CurMd5) return false; for (; Desc.end() == false; ++Desc) if (Desc.LanguageCode() == CurLang) -- cgit v1.2.3 From a00a9b44a1e0abf944d88c36ceaac8afdd207dcb Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 May 2012 15:37:31 +0200 Subject: ensure that apti18n.h is included last as advertised (Closes: #671623) --- apt-pkg/cachefilter.cc | 4 ++-- apt-pkg/packagemanager.cc | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cachefilter.cc b/apt-pkg/cachefilter.cc index 9ec3fa699..fb444208c 100644 --- a/apt-pkg/cachefilter.cc +++ b/apt-pkg/cachefilter.cc @@ -10,11 +10,11 @@ #include #include -#include - #include #include + +#include /*}}}*/ namespace APT { namespace CacheFilter { diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index b56619ef5..06151a165 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -25,9 +25,10 @@ #include #include -#include #include #include + +#include /*}}}*/ using namespace std; -- cgit v1.2.3 From ee7af1bd58a717601fc30b5e7702d688749d2419 Mon Sep 17 00:00:00 2001 From: YOSHINO Yoshihito Date: Mon, 7 May 2012 21:16:25 +0200 Subject: * apt-pkg/acquire-worker.cc: - revert the use of FileFd::Write in OutFdReady as we don't want error reports about EAGAIN here as we retry later. Thanks to YOSHINO Yoshihito for the report. (Closes: #671721) --- apt-pkg/acquire-worker.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc index 8bc043c58..d6db8bc02 100644 --- a/apt-pkg/acquire-worker.cc +++ b/apt-pkg/acquire-worker.cc @@ -511,10 +511,17 @@ bool pkgAcquire::Worker::QueueItem(pkgAcquire::Queue::QItem *Item) /* */ bool pkgAcquire::Worker::OutFdReady() { - if (FileFd::Write(OutFd,OutQueue.c_str(),OutQueue.length()) == false) + int Res; + do + { + Res = write(OutFd,OutQueue.c_str(),OutQueue.length()); + } + while (Res < 0 && errno == EINTR); + + if (Res <= 0) return MethodFailure(); - - OutQueue.clear(); + + OutQueue.erase(0,Res); if (OutQueue.empty() == true) OutReady = false; -- cgit v1.2.3 From afb093cd9bc9d0b2abb6a87d1b98785183a6452d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 9 May 2012 19:16:39 +0200 Subject: * apt-pkg/contrib/fileutl.cc: - check that the fd which are closed are valid --- apt-pkg/contrib/fileutl.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index e9d1ba1ce..1cf225329 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1065,7 +1065,10 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C // 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); + iFd = -1; + } } // Create a data pipe @@ -1133,7 +1136,7 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C close(Pipe[0]); else close(Pipe[1]); - if (Comp == true || FileName.empty() == true) + if ((Comp == true || FileName.empty() == true) && d->compressed_fd != -1) close(d->compressed_fd); return true; @@ -1355,8 +1358,9 @@ bool FileFd::Seek(unsigned long long To) if (d->bz2 != NULL) BZ2_bzclose(d->bz2); #endif - close(iFd); - iFd = 0; + if (iFd != -1) + close(iFd); + iFd = -1; if (TemporaryFileName.empty() == false) iFd = open(TemporaryFileName.c_str(), O_RDONLY); else if (FileName.empty() == false) -- cgit v1.2.3 From e29d7e3e1c7bcff54123b9a69f9b0136d4cf1de5 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 9 May 2012 21:44:11 +0200 Subject: * apt-pkg/aptconfiguration.cc: - use NULL instead of "" for no (un)compress parameters --- apt-pkg/aptconfiguration.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index e1225b3e6..0fd470ed5 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -477,18 +477,18 @@ const Configuration::getCompressors(bool const Cached) { setDefaultConfigurationForCompressors(); - compressors.push_back(Compressor(".", "", "", "", "", 1)); + compressors.push_back(Compressor(".", "", "", NULL, NULL, 1)); if (_config->Exists("Dir::Bin::gzip") == false || FileExists(_config->FindFile("Dir::Bin::gzip")) == true) compressors.push_back(Compressor("gzip",".gz","gzip","-9n","-d",2)); #ifdef HAVE_ZLIB else - compressors.push_back(Compressor("gzip",".gz","false", "", "", 2)); + compressors.push_back(Compressor("gzip",".gz","false", NULL, NULL, 2)); #endif if (_config->Exists("Dir::Bin::bzip2") == false || FileExists(_config->FindFile("Dir::Bin::bzip2")) == true) compressors.push_back(Compressor("bzip2",".bz2","bzip2","-9","-d",3)); #ifdef HAVE_BZ2 else - compressors.push_back(Compressor("bzip2",".bz2","false", "", "", 3)); + compressors.push_back(Compressor("bzip2",".bz2","false", NULL, NULL, 3)); #endif if (_config->Exists("Dir::Bin::xz") == false || FileExists(_config->FindFile("Dir::Bin::xz")) == true) compressors.push_back(Compressor("xz",".xz","xz","-6","-d",4)); -- cgit v1.2.3 From ba667cf74b94846c0696ae7a27e53b28492554b6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 9 May 2012 22:05:18 +0200 Subject: ensure that we do init d only once and especially not with its own content as this causes some "interesting" hickups resulting in segfaults as it seems (Closes: #554387, #670979) --- apt-pkg/contrib/fileutl.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 1cf225329..14c0b561f 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -905,8 +905,6 @@ bool FileFd::Open(string FileName,unsigned int const Mode,CompressMode Compress, 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) @@ -1000,8 +998,6 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, CompressMode Compre 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; this->FileName = ""; @@ -1015,7 +1011,12 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration: } bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor) { - d->compressor = compressor; + if (d == NULL) + { + d = new FileFdPrivate(); + d->openmode = Mode; + d->compressor = compressor; + } if (compressor.Name == "." || compressor.Binary.empty() == true) return true; #ifdef HAVE_ZLIB -- cgit v1.2.3 From adbd7eb4db58ce38965bf6340b8b059a07fdb5bc Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 10 May 2012 00:14:50 +0200 Subject: collect zombie (de)compressor processes on reopen --- apt-pkg/contrib/fileutl.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 14c0b561f..4dc087983 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1022,6 +1022,11 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C #ifdef HAVE_ZLIB else if (compressor.Name == "gzip") { + if (d->gz != NULL) + { + gzclose(d->gz); + d->gz = NULL; + } if ((Mode & ReadWrite) == ReadWrite) d->gz = gzdopen(iFd, "r+"); else if ((Mode & WriteOnly) == WriteOnly) @@ -1037,6 +1042,11 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C #ifdef HAVE_BZ2 else if (compressor.Name == "bzip2") { + if (d->bz2 != NULL) + { + BZ2_bzclose(d->bz2); + d->bz2 = NULL; + } if ((Mode & ReadWrite) == ReadWrite) d->bz2 = BZ2_bzdopen(iFd, "r+"); else if ((Mode & WriteOnly) == WriteOnly) @@ -1050,14 +1060,17 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C } #endif + // collect zombies here in case we reopen + if (d->compressor_pid > 0) + ExecWait(d->compressor_pid, "FileFdCompressor", true); 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) { + // Handle 'decompression' of empty files struct stat Buf; fstat(iFd, &Buf); if (Buf.st_size == 0 && S_ISFIFO(Buf.st_mode) == false) -- cgit v1.2.3 From fbb89d946da063ec6e1c4b0034cb479c10a37375 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 10 May 2012 01:54:21 +0200 Subject: ensure that in error conditions the Fail flag is set --- apt-pkg/contrib/fileutl.cc | 49 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 4dc087983..7a24b6bb0 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1065,7 +1065,10 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C ExecWait(d->compressor_pid, "FileFdCompressor", true); if ((Mode & ReadWrite) == ReadWrite) + { + Flags |= Fail; return _error->Error("ReadWrite mode is not supported for file %s", FileName.c_str()); + } bool const Comp = (Mode & WriteOnly) == WriteOnly; if (Comp == false) @@ -1088,7 +1091,10 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C // Create a data pipe int Pipe[2] = {-1,-1}; if (pipe(Pipe) != 0) + { + Flags |= Fail; return _error->Errno("pipe",_("Failed to create subprocess IPC")); + } for (int J = 0; J != 2; J++) SetCloseExec(Pipe[J],true); @@ -1367,7 +1373,10 @@ bool FileFd::Seek(unsigned long long To) return Skip(To - seekpos); if ((d->openmode & ReadOnly) != ReadOnly) + { + Flags |= Fail; return _error->Error("Reopen is only implemented for read-only files!"); + } #ifdef HAVE_BZ2 if (d->bz2 != NULL) BZ2_bzclose(d->bz2); @@ -1385,11 +1394,17 @@ bool FileFd::Seek(unsigned long long To) if (lseek(d->compressed_fd, 0, SEEK_SET) != 0) iFd = d->compressed_fd; if (iFd <= 0) + { + Flags |= Fail; return _error->Error("Reopen is not implemented for pipes opened with FileFd::OpenDescriptor()!"); + } } if (OpenInternDescriptor(d->openmode, d->compressor) == false) + { + Flags |= Fail; return _error->Error("Seek on file %s because it couldn't be reopened", FileName.c_str()); + } if (To != 0) return Skip(To); @@ -1431,7 +1446,10 @@ bool FileFd::Skip(unsigned long long Over) { unsigned long long toread = std::min((unsigned long long) sizeof(buffer), Over); if (Read(buffer, toread) == false) + { + Flags |= Fail; return _error->Error("Unable to seek ahead %llu",Over); + } Over -= toread; } return true; @@ -1499,7 +1517,10 @@ unsigned long long FileFd::Tell() #endif Res = lseek(iFd,0,SEEK_CUR); if (Res == (off_t)-1) + { + Flags |= Fail; _error->Errno("lseek","Failed to determine the current file position"); + } d->seekpos = Res; return Res; } @@ -1511,7 +1532,10 @@ unsigned long long FileFd::FileSize() { struct stat Buf; if (d->pipe == false && fstat(iFd,&Buf) != 0) + { + Flags |= Fail; 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)) @@ -1520,7 +1544,10 @@ unsigned long long FileFd::FileSize() // in theory the Open-methods should take care of it already d->pipe = true; if (stat(FileName.c_str(), &Buf) != 0) + { + Flags |= Fail; return _error->Errno("stat","Unable to determine the file size"); + } } return Buf.st_size; @@ -1562,10 +1589,16 @@ unsigned long long FileFd::Size() * bits of the file */ // FIXME: Size for gz-files is limited by 32bit… no largefile support if (lseek(iFd, -4, SEEK_END) < 0) - return _error->Errno("lseek","Unable to seek to end of gzipped file"); + { + Flags |= Fail; + return _error->Errno("lseek","Unable to seek to end of gzipped file"); + } size = 0L; if (read(iFd, &size, 4) != 4) - return _error->Errno("read","Unable to read original size of gzipped file"); + { + Flags |= Fail; + return _error->Errno("read","Unable to read original size of gzipped file"); + } #ifdef WORDS_BIGENDIAN uint32_t tmp_size = size; @@ -1575,7 +1608,10 @@ unsigned long long FileFd::Size() #endif if (lseek(iFd, oldPos, SEEK_SET) < 0) - return _error->Errno("lseek","Unable to seek in gzipped file"); + { + Flags |= Fail; + return _error->Errno("lseek","Unable to seek in gzipped file"); + } return size; } @@ -1592,6 +1628,7 @@ time_t FileFd::ModificationTime() struct stat Buf; if (d->pipe == false && fstat(iFd,&Buf) != 0) { + Flags |= Fail; _error->Errno("fstat","Unable to determine the modification time of file %s", FileName.c_str()); return 0; } @@ -1604,6 +1641,7 @@ time_t FileFd::ModificationTime() d->pipe = true; if (stat(FileName.c_str(), &Buf) != 0) { + Flags |= Fail; _error->Errno("fstat","Unable to determine the modification time of file %s", FileName.c_str()); return 0; } @@ -1663,6 +1701,8 @@ bool FileFd::Close() d = NULL; } + if (Res == false) + Flags |= Fail; return Res; } /*}}}*/ @@ -1673,7 +1713,10 @@ bool FileFd::Sync() { #ifdef _POSIX_SYNCHRONIZED_IO if (fsync(iFd) != 0) + { + Flags |= Fail; return _error->Errno("sync",_("Problem syncing the file")); + } #endif return true; } -- cgit v1.2.3 From f0e835998f21c315c5154da4e7f5c51b18929b3a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 10 May 2012 01:54:32 +0200 Subject: fix calling style of FileFd (no functional change) --- apt-pkg/deb/debindexfile.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 5dc2a2ac2..76c740341 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -161,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::ReadOnly, FileFd::Extension); + FileFd f(IndexFile("Sources"), FileFd::ReadOnly, FileFd::Extension); if (!f.Failed()) size = f.Size(); @@ -290,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::ReadOnly, FileFd::Extension); + FileFd f(IndexFile("Packages"), FileFd::ReadOnly, FileFd::Extension); if (!f.Failed()) size = f.Size(); @@ -488,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::ReadOnly, FileFd::Extension); + FileFd f(IndexFile(Language), FileFd::ReadOnly, FileFd::Extension); if (!f.Failed()) size = f.Size(); -- cgit v1.2.3 From ff477ee133fb448622cc86f658f1a9b23577e413 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 10 May 2012 03:09:18 +0200 Subject: ensure that d is set before accessing it --- apt-pkg/contrib/fileutl.cc | 91 +++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 41 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 7a24b6bb0..c8e685a5a 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1011,16 +1011,18 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration: } bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor) { + if (compressor.Name == "." || compressor.Binary.empty() == true) + return true; + if (d == NULL) { d = new FileFdPrivate(); d->openmode = Mode; d->compressor = compressor; } - if (compressor.Name == "." || compressor.Binary.empty() == true) - return true; + #ifdef HAVE_ZLIB - else if (compressor.Name == "gzip") + if (compressor.Name == "gzip") { if (d->gz != NULL) { @@ -1040,7 +1042,7 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C } #endif #ifdef HAVE_BZ2 - else if (compressor.Name == "bzip2") + if (compressor.Name == "bzip2") { if (d->bz2 != NULL) { @@ -1185,12 +1187,12 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual) do { #ifdef HAVE_ZLIB - if (d->gz != NULL) + if (d != NULL && d->gz != NULL) Res = gzread(d->gz,To,Size); else #endif #ifdef HAVE_BZ2 - if (d->bz2 != NULL) + if (d != NULL && d->bz2 != NULL) Res = BZ2_bzread(d->bz2,To,Size); else #endif @@ -1202,7 +1204,7 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual) continue; Flags |= Fail; #ifdef HAVE_ZLIB - if (d->gz != NULL) + if (d != NULL && d->gz != NULL) { int err; char const * const errmsg = gzerror(d->gz, &err); @@ -1211,7 +1213,7 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual) } #endif #ifdef HAVE_BZ2 - if (d->bz2 != NULL) + if (d != NULL && d->bz2 != NULL) { int err; char const * const errmsg = BZ2_bzerror(d->bz2, &err); @@ -1224,7 +1226,8 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual) To = (char *)To + Res; Size -= Res; - d->seekpos += Res; + if (d != NULL) + d->seekpos += Res; if (Actual != 0) *Actual += Res; } @@ -1252,7 +1255,7 @@ char* FileFd::ReadLine(char *To, unsigned long long const Size) { *To = '\0'; #ifdef HAVE_ZLIB - if (d->gz != NULL) + if (d != NULL && d->gz != NULL) return gzgets(d->gz, To, Size); #endif @@ -1283,12 +1286,12 @@ bool FileFd::Write(const void *From,unsigned long long Size) do { #ifdef HAVE_ZLIB - if (d->gz != NULL) + if (d != NULL && d->gz != NULL) Res = gzwrite(d->gz,From,Size); else #endif #ifdef HAVE_BZ2 - if (d->bz2 != NULL) + if (d != NULL && d->bz2 != NULL) Res = BZ2_bzwrite(d->bz2,(void*)From,Size); else #endif @@ -1299,7 +1302,7 @@ bool FileFd::Write(const void *From,unsigned long long Size) { Flags |= Fail; #ifdef HAVE_ZLIB - if (d->gz != NULL) + if (d != NULL && d->gz != NULL) { int err; char const * const errmsg = gzerror(d->gz, &err); @@ -1308,7 +1311,7 @@ bool FileFd::Write(const void *From,unsigned long long Size) } #endif #ifdef HAVE_BZ2 - if (d->bz2 != NULL) + if (d != NULL && d->bz2 != NULL) { int err; char const * const errmsg = BZ2_bzerror(d->bz2, &err); @@ -1321,7 +1324,8 @@ bool FileFd::Write(const void *From,unsigned long long Size) From = (char *)From + Res; Size -= Res; - d->seekpos += Res; + if (d != NULL) + d->seekpos += Res; } while (Res > 0 && Size > 0); @@ -1359,11 +1363,11 @@ bool FileFd::Write(int Fd, const void *From, unsigned long long Size) /* */ bool FileFd::Seek(unsigned long long To) { - if (d->pipe == true + if (d != NULL && (d->pipe == true #ifdef HAVE_BZ2 - || d->bz2 != NULL + || d->bz2 != NULL #endif - ) + )) { // Our poor man seeking in pipes is costly, so try to avoid it unsigned long long seekpos = Tell(); @@ -1414,7 +1418,7 @@ bool FileFd::Seek(unsigned long long To) } int res; #ifdef HAVE_ZLIB - if (d->gz) + if (d != NULL && d->gz) res = gzseek(d->gz,To,SEEK_SET); else #endif @@ -1425,7 +1429,8 @@ bool FileFd::Seek(unsigned long long To) return _error->Error("Unable to seek to %llu", To); } - d->seekpos = To; + if (d != NULL) + d->seekpos = To; return true; } /*}}}*/ @@ -1434,11 +1439,11 @@ bool FileFd::Seek(unsigned long long To) /* */ bool FileFd::Skip(unsigned long long Over) { - if (d->pipe == true + if (d != NULL && (d->pipe == true #ifdef HAVE_BZ2 - || d->bz2 != NULL + || d->bz2 != NULL #endif - ) + )) { d->seekpos += Over; char buffer[1024]; @@ -1457,7 +1462,7 @@ bool FileFd::Skip(unsigned long long Over) int res; #ifdef HAVE_ZLIB - if (d->gz != NULL) + if (d != NULL && d->gz != NULL) res = gzseek(d->gz,Over,SEEK_CUR); else #endif @@ -1467,7 +1472,8 @@ bool FileFd::Skip(unsigned long long Over) Flags |= Fail; return _error->Error("Unable to seek ahead %llu",Over); } - d->seekpos = res; + if (d != NULL) + d->seekpos = res; return true; } @@ -1478,7 +1484,7 @@ bool FileFd::Skip(unsigned long long Over) bool FileFd::Truncate(unsigned long long To) { #if defined HAVE_ZLIB || defined HAVE_BZ2 - if (d->gz != NULL || d->bz2 != NULL) + if (d != NULL && (d->gz != NULL || d->bz2 != NULL)) { Flags |= Fail; return _error->Error("Truncating compressed files is not implemented (%s)", FileName.c_str()); @@ -1502,16 +1508,16 @@ unsigned long long FileFd::Tell() // seeking around, but not all users of FileFd use always Seek() and co // so d->seekpos isn't always true and we can just use it as a hint if // we have nothing else, but not always as an authority… - if (d->pipe == true + if (d != NULL && (d->pipe == true #ifdef HAVE_BZ2 - || d->bz2 != NULL + || d->bz2 != NULL #endif - ) + )) return d->seekpos; off_t Res; #ifdef HAVE_ZLIB - if (d->gz != NULL) + if (d != NULL && d->gz != NULL) Res = gztell(d->gz); else #endif @@ -1521,7 +1527,8 @@ unsigned long long FileFd::Tell() Flags |= Fail; _error->Errno("lseek","Failed to determine the current file position"); } - d->seekpos = Res; + if (d != NULL) + d->seekpos = Res; return Res; } /*}}}*/ @@ -1531,18 +1538,19 @@ unsigned long long FileFd::Tell() unsigned long long FileFd::FileSize() { struct stat Buf; - if (d->pipe == false && fstat(iFd,&Buf) != 0) + if ((d == NULL || d->pipe == false) && fstat(iFd,&Buf) != 0) { Flags |= Fail; 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)) + if ((d != NULL && 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 (d != NULL) + d->pipe = true; if (stat(FileName.c_str(), &Buf) != 0) { Flags |= Fail; @@ -1562,11 +1570,11 @@ unsigned long long FileFd::Size() // 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 + if (d != NULL && (d->pipe == true #ifdef HAVE_BZ2 - || (d->bz2 && size > 0) + || (d->bz2 && size > 0) #endif - ) + )) { unsigned long long const oldSeek = Tell(); char ignore[1000]; @@ -1581,7 +1589,7 @@ unsigned long long FileFd::Size() // only check gzsize if we are actually a gzip file, just checking for // "gz" is not sufficient as uncompressed files could be opened with // gzopen in "direct" mode as well - else if (d->gz && !gzdirect(d->gz) && size > 0) + else if (d != NULL && d->gz && !gzdirect(d->gz) && size > 0) { off_t const oldPos = lseek(iFd,0,SEEK_CUR); /* unfortunately zlib.h doesn't provide a gzsize(), so we have to do @@ -1626,7 +1634,7 @@ unsigned long long FileFd::Size() time_t FileFd::ModificationTime() { struct stat Buf; - if (d->pipe == false && fstat(iFd,&Buf) != 0) + if ((d == NULL || d->pipe == false) && fstat(iFd,&Buf) != 0) { Flags |= Fail; _error->Errno("fstat","Unable to determine the modification time of file %s", FileName.c_str()); @@ -1634,11 +1642,12 @@ time_t FileFd::ModificationTime() } // for compressor pipes st_size is undefined and at 'best' zero - if (d->pipe == true || S_ISFIFO(Buf.st_mode)) + if ((d != NULL && 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 (d != NULL) + d->pipe = true; if (stat(FileName.c_str(), &Buf) != 0) { Flags |= Fail; -- cgit v1.2.3 From db09a1c5dd74f422571c4130364bb7c78200e8c8 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 10 May 2012 20:40:47 +0200 Subject: * apt-pkg/algorithms.cc: - factor out of ListUpdate a AcquireUpdate to be able to provide your own pkgAcquire fetcher to the wrapper --- apt-pkg/algorithms.cc | 37 ++++++++++++++++++++++++++----------- apt-pkg/algorithms.h | 4 +++- 2 files changed, 29 insertions(+), 12 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 8beb2d51c..e7b359981 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -1453,7 +1453,7 @@ void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List) qsort(List,Count,sizeof(*List),PrioComp); } /*}}}*/ -// ListUpdate - update the cache files /*{{{*/ +// ListUpdate - construct Fetcher and update the cache files /*{{{*/ // --------------------------------------------------------------------- /* This is a simple wrapper to update the cache. it will fetch stuff * from the network (or any other sources defined in sources.list) @@ -1462,7 +1462,6 @@ bool ListUpdate(pkgAcquireStatus &Stat, pkgSourceList &List, int PulseInterval) { - pkgAcquire::RunResult res; pkgAcquire Fetcher; if (Fetcher.Setup(&Stat, _config->FindDir("Dir::State::Lists")) == false) return false; @@ -1471,11 +1470,24 @@ bool ListUpdate(pkgAcquireStatus &Stat, if (List.GetIndexes(&Fetcher) == false) return false; + return AcquireUpdate(Fetcher, PulseInterval, true); +} + /*}}}*/ +// AcquireUpdate - take Fetcher and update the cache files /*{{{*/ +// --------------------------------------------------------------------- +/* This is a simple wrapper to update the cache with a provided acquire + * If you only need control over Status and the used SourcesList use + * ListUpdate method instead. + */ +bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval, + bool const RunUpdateScripts, bool const ListCleanup) +{ // Run scripts - RunScripts("APT::Update::Pre-Invoke"); - - // check arguments - if(PulseInterval>0) + if (RunUpdateScripts == true) + RunScripts("APT::Update::Pre-Invoke"); + + pkgAcquire::RunResult res; + if(PulseInterval > 0) res = Fetcher.Run(PulseInterval); else res = Fetcher.Run(); @@ -1512,7 +1524,7 @@ bool ListUpdate(pkgAcquireStatus &Stat, // Clean out any old list files // Keep "APT::Get::List-Cleanup" name for compatibility, but // this is really a global option for the APT library now - if (!TransientNetworkFailure && !Failed && + if (!TransientNetworkFailure && !Failed && ListCleanup == true && (_config->FindB("APT::Get::List-Cleanup",true) == true && _config->FindB("APT::List-Cleanup",true) == true)) { @@ -1529,11 +1541,14 @@ bool ListUpdate(pkgAcquireStatus &Stat, // Run the success scripts if all was fine - if(!TransientNetworkFailure && !Failed) - RunScripts("APT::Update::Post-Invoke-Success"); + if (RunUpdateScripts == true) + { + if(!TransientNetworkFailure && !Failed) + RunScripts("APT::Update::Post-Invoke-Success"); - // Run the other scripts - RunScripts("APT::Update::Post-Invoke"); + // Run the other scripts + RunScripts("APT::Update::Post-Invoke"); + } return true; } /*}}}*/ diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h index 37eacf1f8..076542c20 100644 --- a/apt-pkg/algorithms.h +++ b/apt-pkg/algorithms.h @@ -147,5 +147,7 @@ bool pkgMinimizeUpgrade(pkgDepCache &Cache); void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List); bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List, int PulseInterval=0); - +bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval = 0, + bool const RunUpdateScripts = true, bool const ListCleanup = true); + #endif -- cgit v1.2.3 From 606837654922b8c58c9ac8a12b44c30f308115e3 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 12 May 2012 00:11:07 +0200 Subject: * apt-pkg/pkgcachegen.cc: - make IsDuplicatedDescription static so that it is really private as we don't need a symbol for it as it is not in a header --- apt-pkg/pkgcachegen.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index d455e4070..538d10b35 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -38,7 +38,7 @@ typedef std::vector::iterator FileIterator; template std::vector pkgCacheGenerator::Dynamic::toReMap; -bool IsDuplicateDescription(pkgCache::DescIterator Desc, +static bool IsDuplicateDescription(pkgCache::DescIterator Desc, MD5SumValue const &CurMd5, std::string const &CurLang); using std::string; @@ -1455,7 +1455,7 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O } /*}}}*/ // IsDuplicateDescription /*{{{*/ -bool IsDuplicateDescription(pkgCache::DescIterator Desc, +static bool IsDuplicateDescription(pkgCache::DescIterator Desc, MD5SumValue const &CurMd5, std::string const &CurLang) { // Descriptions in the same link-list have all the same md5 -- cgit v1.2.3 From e1284a59de37efeedcc998ef61e8466c35b82eb2 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 14 May 2012 16:53:43 +0200 Subject: * apt-pkg/acquire-methods.cc: - factor out into private Dequeue() to fix access to deleted pointer --- apt-pkg/acquire-method.cc | 23 ++++++++++------------- apt-pkg/acquire-method.h | 3 +++ 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-method.cc b/apt-pkg/acquire-method.cc index 2041fd9e9..e6e02bbc5 100644 --- a/apt-pkg/acquire-method.cc +++ b/apt-pkg/acquire-method.cc @@ -95,12 +95,7 @@ void pkgAcqMethod::Fail(string Err,bool Transient) { std::cout << "400 URI Failure\nURI: " << Queue->Uri << "\n" << "Message: " << Err << " " << IP << "\n"; - // Dequeue - FetchItem *Tmp = Queue; - Queue = Queue->Next; - delete Tmp; - if (Tmp == QueueBack) - QueueBack = Queue; + Dequeue(); } else std::cout << "400 URI Failure\nURI: \nMessage: " << Err << "\n"; @@ -211,13 +206,7 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt) } std::cout << "\n" << std::flush; - - // Dequeue - FetchItem *Tmp = Queue; - Queue = Queue->Next; - delete Tmp; - if (Tmp == QueueBack) - QueueBack = Queue; + Dequeue(); } /*}}}*/ // AcqMethod::MediaFail - Syncronous request for new media /*{{{*/ @@ -465,3 +454,11 @@ void pkgAcqMethod::FetchResult::TakeHashes(Hashes &Hash) SHA512Sum = Hash.SHA512.Result(); } /*}}}*/ +void pkgAcqMethod::Dequeue() { /*{{{*/ + FetchItem const * const Tmp = Queue; + Queue = Queue->Next; + if (Tmp == QueueBack) + QueueBack = Queue; + delete Tmp; +} + /*}}}*/ diff --git a/apt-pkg/acquire-method.h b/apt-pkg/acquire-method.h index 2dd9ad685..00f99e0a0 100644 --- a/apt-pkg/acquire-method.h +++ b/apt-pkg/acquire-method.h @@ -104,6 +104,9 @@ class pkgAcqMethod pkgAcqMethod(const char *Ver,unsigned long Flags = 0); virtual ~pkgAcqMethod() {}; + + private: + void Dequeue(); }; /** @} */ -- cgit v1.2.3 From 5674f6b3163d73260e25ce7d350aaac50071eb0e Mon Sep 17 00:00:00 2001 From: Raphael Geissert Date: Mon, 14 May 2012 18:07:01 +0200 Subject: * apt-pkg/acquire*.cc: - handle redirections in the worker with the right method instead of in the method the redirection occured in (Closes: #668111) * methods/http.cc: - forbid redirects to change protocol --- apt-pkg/acquire-method.cc | 18 +++--------------- apt-pkg/acquire-worker.cc | 15 +++++++++++++++ apt-pkg/acquire.cc | 39 ++++++++++++++++++++++++++++++++++----- 3 files changed, 52 insertions(+), 20 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-method.cc b/apt-pkg/acquire-method.cc index e6e02bbc5..5bc1c159a 100644 --- a/apt-pkg/acquire-method.cc +++ b/apt-pkg/acquire-method.cc @@ -412,26 +412,14 @@ void pkgAcqMethod::Status(const char *Format,...) /*}}}*/ // AcqMethod::Redirect - Send a redirect message /*{{{*/ // --------------------------------------------------------------------- -/* This method sends the redirect message and also manipulates the queue - to keep the pipeline synchronized. */ +/* This method sends the redirect message and dequeues the item as + * the worker will enqueue again later on to the right queue */ void pkgAcqMethod::Redirect(const string &NewURI) { std::cout << "103 Redirect\nURI: " << Queue->Uri << "\n" << "New-URI: " << NewURI << "\n" << "\n" << std::flush; - - // Change the URI for the request. - Queue->Uri = NewURI; - - /* To keep the pipeline synchronized, move the current request to - the end of the queue, past the end of the current pipeline. */ - FetchItem *I; - for (I = Queue; I->Next != 0; I = I->Next) ; - I->Next = Queue; - Queue = Queue->Next; - I->Next->Next = 0; - if (QueueBack == 0) - QueueBack = I->Next; + Dequeue(); } /*}}}*/ // AcqMethod::FetchResult::FetchResult - Constructor /*{{{*/ diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc index d6db8bc02..9d90b08bc 100644 --- a/apt-pkg/acquire-worker.cc +++ b/apt-pkg/acquire-worker.cc @@ -244,6 +244,21 @@ bool pkgAcquire::Worker::RunMessages() string NewURI = LookupTag(Message,"New-URI",URI.c_str()); Itm->URI = NewURI; + + ItemDone(); + + pkgAcquire::Item *Owner = Itm->Owner; + pkgAcquire::ItemDesc Desc = *Itm; + + // Change the status so that it can be dequeued + Owner->Status = pkgAcquire::Item::StatIdle; + // Mark the item as done (taking care of all queues) + // and then put it in the main queue again + OwnerQ->ItemDone(Itm); + OwnerQ->Owner->Enqueue(Desc); + + if (Log != 0) + Log->Done(Desc); break; } diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 5e1419056..a8a5abd34 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -244,11 +244,19 @@ void pkgAcquire::Dequeue(Item *Itm) { Queue *I = Queues; bool Res = false; - for (; I != 0; I = I->Next) - Res |= I->Dequeue(Itm); - if (Debug == true) clog << "Dequeuing " << Itm->DestFile << endl; + + for (; I != 0; I = I->Next) + { + if (I->Dequeue(Itm)) + { + Res = true; + if (Debug == true) + clog << "Dequeued from " << I->Name << endl; + } + } + if (Res == true) ToFetch--; } @@ -269,9 +277,30 @@ string pkgAcquire::QueueName(string Uri,MethodConfig const *&Config) /* Single-Instance methods get exactly one queue per URI. This is also used for the Access queue method */ if (Config->SingleInstance == true || QueueMode == QueueAccess) - return U.Access; + return U.Access; + + string AccessSchema = U.Access + ':', + FullQueueName = AccessSchema + U.Host; + unsigned int Instances = 0, SchemaLength = AccessSchema.length(); + + Queue *I = Queues; + for (; I != 0; I = I->Next) { + // if the queue already exists, re-use it + if (I->Name == FullQueueName) + return FullQueueName; + + if (I->Name.compare(0, SchemaLength, AccessSchema) == 0) + Instances++; + } + + if (Debug) { + clog << "Found " << Instances << " instances of " << U.Access << endl; + } + + if (Instances >= (unsigned int)_config->FindI("Acquire::QueueHost::Limit",10)) + return U.Access; - return U.Access + ':' + U.Host; + return FullQueueName; } /*}}}*/ // Acquire::GetConfig - Fetch the configuration information /*{{{*/ -- cgit v1.2.3 From b270388bef045df8c1b364338f545791bba222c1 Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Tue, 15 May 2012 21:17:08 +0200 Subject: * apt-pkg/algorithms.cc: - fix memory leak of Flags in pkgSimulate by a proper destructor --- apt-pkg/algorithms.cc | 6 ++++++ apt-pkg/algorithms.h | 1 + 2 files changed, 7 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index e7b359981..2d710097a 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -58,6 +58,12 @@ pkgSimulate::pkgSimulate(pkgDepCache *Cache) : pkgPackageManager(Cache), FileNames[I] = Jnk; } /*}}}*/ +// Simulate::~Simulate - Destructor /*{{{*/ +pkgSimulate::~pkgSimulate() +{ + delete[] Flags; +} + /*}}}*/ // Simulate::Describe - Describe a package /*{{{*/ // --------------------------------------------------------------------- /* Parameter Current == true displays the current package version, diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h index 076542c20..aff8a68f2 100644 --- a/apt-pkg/algorithms.h +++ b/apt-pkg/algorithms.h @@ -78,6 +78,7 @@ private: public: pkgSimulate(pkgDepCache *Cache); + ~pkgSimulate(); }; /*}}}*/ class pkgProblemResolver /*{{{*/ -- cgit v1.2.3 From 500400fedd6e57eb0162a0e41fdd9ba05a2cae3d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 16 May 2012 15:55:32 +0200 Subject: * apt-pkg/contrib/fileutl.cc: - ensure that we close compressed fds, wait for forks and such even if the FileFd itself is set to not autoclose the given Fd --- apt-pkg/contrib/fileutl.cc | 65 +++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 24 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index c8e685a5a..c7f78cdfb 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -81,6 +81,31 @@ class FileFdPrivate { FileFdPrivate() : gz(NULL), bz2(NULL), compressed_fd(-1), compressor_pid(-1), pipe(false), openmode(0), seekpos(0) {}; + bool CloseDown(std::string const &FileName) + { + bool Res = true; +#ifdef HAVE_ZLIB + if (gz != NULL) { + int const e = gzclose(gz); + gz = NULL; + // gzdclose() 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()); + } +#endif +#ifdef HAVE_BZ2 + if (bz2 != NULL) { + BZ2_bzclose(bz2); + bz2 = NULL; + } +#endif + if (compressor_pid > 0) + ExecWait(compressor_pid, "FileFdCompressor", true); + compressor_pid = -1; + + return Res; + } + ~FileFdPrivate() { CloseDown(""); } }; // RunScripts - Run a set of scripts from a configuration subtree /*{{{*/ @@ -1171,6 +1196,12 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C FileFd::~FileFd() { Close(); + if (d != NULL) + { + d->CloseDown(FileName); + delete d; + d = NULL; + } } /*}}}*/ // FileFd::Read - Read a bit of the file /*{{{*/ @@ -1397,7 +1428,7 @@ bool FileFd::Seek(unsigned long long To) if (d->compressed_fd > 0) if (lseek(d->compressed_fd, 0, SEEK_SET) != 0) iFd = d->compressed_fd; - if (iFd <= 0) + if (iFd < 0) { Flags |= Fail; return _error->Error("Reopen is not implemented for pipes opened with FileFd::OpenDescriptor()!"); @@ -1670,21 +1701,15 @@ bool FileFd::Close() bool Res = true; if ((Flags & AutoClose) == AutoClose) { -#ifdef HAVE_ZLIB - if (d != NULL && d->gz != NULL) { - int const e = gzclose(d->gz); - // gzdclose() 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 -#ifdef HAVE_BZ2 - if (d != NULL && d->bz2 != NULL) - BZ2_bzclose(d->bz2); - else -#endif - if (iFd > 0 && close(iFd) != 0) - Res &= _error->Errno("close",_("Problem closing the file %s"), FileName.c_str()); + if ((Flags & Compressed) != Compressed && iFd > 0 && close(iFd) != 0) + Res &= _error->Errno("close",_("Problem closing the file %s"), FileName.c_str()); + + if (d != NULL) + { + Res &= d->CloseDown(FileName); + delete d; + d = NULL; + } } if ((Flags & Replace) == Replace && iFd >= 0) { @@ -1702,14 +1727,6 @@ bool FileFd::Close() 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; - } - if (Res == false) Flags |= Fail; return Res; -- cgit v1.2.3 From 65f9983436be310c768c4c42531ceea1e3a6d4ac Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 16 May 2012 16:44:15 +0200 Subject: * cmdline/apt-get.cc: - use the host architecture, not the build architecture for matching of [architecture restrictions] in Build-Depends (Closes: #672927) * --- apt-pkg/srcrecords.h | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-pkg') diff --git a/apt-pkg/srcrecords.h b/apt-pkg/srcrecords.h index 06f0dce6c..ed69d0d72 100644 --- a/apt-pkg/srcrecords.h +++ b/apt-pkg/srcrecords.h @@ -71,6 +71,7 @@ class pkgSrcRecords virtual std::string Section() const = 0; virtual const char **Binaries() = 0; // Ownership does not transfer + //FIXME: Add a parameter to specify which architecture to use for [wildcard] matching virtual bool BuildDepends(std::vector &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch = true) = 0; static const char *BuildDepType(unsigned char const &Type); -- cgit v1.2.3 From 177645edb5775337ccf6d3971835a122b12318d4 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 19 May 2012 23:07:30 +0200 Subject: * apt-pkg/packagemanager.cc: - do not run into loop on new-pre-depends-breaks (Closes: #673536) --- apt-pkg/packagemanager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 06151a165..46fc499c6 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -785,7 +785,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c VerIterator V(Cache,*I); PkgIterator P = V.ParentPkg(); // we are checking for installation as an easy 'protection' against or-groups and (unchosen) providers - if (P->CurrentVer == 0 || P != Pkg || (P.CurrentVer() != V && Cache[P].InstallVer != V)) + if (P != Pkg || (P.CurrentVer() != V && Cache[P].InstallVer != V)) continue; circle = true; break; -- cgit v1.2.3 From 527df5a20dbe8ce98fcbf1ffe28bb37ff2257a97 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 20 May 2012 18:58:37 +0200 Subject: * apt-pkg/aptconfiguration.cc: - longcode Translation files are saved with encoded underscore, so make sure to pick these files up as well for Acquire::Languages --- apt-pkg/aptconfiguration.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index 0fd470ed5..d763546f8 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -144,7 +144,7 @@ std::vector const Configuration::getLanguages(bool const &All, if (D != 0) { builtin.push_back("none"); for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D)) { - string const name = Ent->d_name; + string const name = SubstVar(Ent->d_name, "%5f", "_"); size_t const foundDash = name.rfind("-"); size_t const foundUnderscore = name.rfind("_", foundDash); if (foundDash == string::npos || foundUnderscore == string::npos || -- cgit v1.2.3 From 6bae2c5108a95267fedcc8f2312e91488ebece8d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 21 May 2012 19:12:25 +0200 Subject: =?UTF-8?q?*=20apt-pkg/contrib/mmap.cc:=20=20=20-=20have=20a=20dum?= =?UTF-8?q?my=20SyncToFd=20around=20in=20case=20of=20ReadOnly=20access=20t?= =?UTF-8?q?o=20a=20=20=20=20=20compressed=20file=20as=20we=20otherwise=20o?= =?UTF-8?q?n=20Close()=20do=20not=20delete[]=20the=20=20=20=20=20char=20bu?= =?UTF-8?q?ffer=20but=20munmap()=20it=E2=80=A6=20(Closes:=20#673815)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apt-pkg/contrib/mmap.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc index 160718ea5..2d12b6fe9 100644 --- a/apt-pkg/contrib/mmap.cc +++ b/apt-pkg/contrib/mmap.cc @@ -84,6 +84,7 @@ bool MMap::Map(FileFd &Fd) if ((Flags & ReadOnly) != ReadOnly) return _error->Error("Compressed file %s can only be mapped readonly", Fd.Name().c_str()); Base = new unsigned char[iSize]; + SyncToFd = new FileFd(); if (Fd.Seek(0L) == false || Fd.Read(Base, iSize) == false) return _error->Error("Compressed file %s can't be read into mmap", Fd.Name().c_str()); return true; -- cgit v1.2.3 From d3aac32ece65fd5424a94402f46db065298c07a8 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 22 May 2012 18:33:43 +0200 Subject: * apt-pkg/contrib/fileutl.cc: - dup() given compressed fd in OpenDescriptor if AutoClose is disabled as otherwise gzclose() and co will close it --- apt-pkg/contrib/fileutl.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index c7f78cdfb..119cd1974 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1024,7 +1024,20 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration: { Close(); Flags = (AutoClose) ? FileFd::AutoClose : 0; - iFd = Fd; + if (AutoClose == false && ( +#ifdef HAVE_ZLIB + compressor.Name == "gzip" || +#endif +#ifdef HAVE_BZ2 + compressor.Name == "bzip2" || +#endif + false)) + { + // Need to duplicate fd here or gzclose for cleanup will close the fd as well + iFd = dup(Fd); + } + else + iFd = Fd; this->FileName = ""; if (OpenInternDescriptor(Mode, compressor) == false) { @@ -1183,8 +1196,6 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C close(Pipe[0]); else close(Pipe[1]); - if ((Comp == true || FileName.empty() == true) && d->compressed_fd != -1) - close(d->compressed_fd); return true; } @@ -1712,7 +1723,7 @@ bool FileFd::Close() } } - if ((Flags & Replace) == Replace && iFd >= 0) { + if ((Flags & Replace) == Replace) { if (rename(TemporaryFileName.c_str(), FileName.c_str()) != 0) Res &= _error->Errno("rename",_("Problem renaming the file %s to %s"), TemporaryFileName.c_str(), FileName.c_str()); -- cgit v1.2.3 From ab59c1ca30640b90bb657d08b2c219bbaeb65783 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 9 Jun 2012 22:15:51 +0200 Subject: * apt-pkg/cdrom.cc: - fix regression from 0.9.3 which dumped the main configuration _config instead of the cdrom settings (Cnf) as identified and tested by Milan Kupcevic, thanks! (Closes: #674100) --- apt-pkg/cdrom.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index c10ca6bd1..8462e8286 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -409,7 +409,7 @@ bool pkgCdrom::WriteDatabase(Configuration &Cnf) /* Write out all of the configuration directives by walking the configuration tree */ - _config->Dump(Out, NULL, "%f \"%v\";\n", false); + Cnf.Dump(Out, NULL, "%f \"%v\";\n", false); Out.close(); -- cgit v1.2.3 From ae2be086c6996e6ed02b7d828fdcac38248a964d Mon Sep 17 00:00:00 2001 From: Daniel Hartwig Date: Sat, 9 Jun 2012 22:49:37 +0200 Subject: * apt-pkg/contrib/cmdline.cc: - apply patch from Daniel Hartwig to fix a segfault in case the LongOpt is empty (Closes: #676331) --- apt-pkg/contrib/cmndline.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc index 159f330a1..b8c7f7984 100644 --- a/apt-pkg/contrib/cmndline.cc +++ b/apt-pkg/contrib/cmndline.cc @@ -92,8 +92,9 @@ bool CommandLine::Parse(int argc,const char **argv) // Match up to a = against the list Args *A; const char *OptEnd = strchrnul(Opt, '='); - for (A = ArgList; A->end() == false && - stringcasecmp(Opt,OptEnd,A->LongOpt) != 0; A++); + for (A = ArgList; A->end() == false && + (A->LongOpt == 0 || stringcasecmp(Opt,OptEnd,A->LongOpt) != 0); + ++A); // Failed, look for a word after the first - (no-foo) bool PreceedMatch = false; -- cgit v1.2.3 From 7a6d9076595b2acc164d6f057f609c96c359ea08 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 9 Jun 2012 22:55:51 +0200 Subject: fix segfault with empty LongOpt in --no-* branch --- apt-pkg/contrib/cmndline.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc index b8c7f7984..75d02cad4 100644 --- a/apt-pkg/contrib/cmndline.cc +++ b/apt-pkg/contrib/cmndline.cc @@ -106,7 +106,8 @@ bool CommandLine::Parse(int argc,const char **argv) Opt++; for (A = ArgList; A->end() == false && - stringcasecmp(Opt,OptEnd,A->LongOpt) != 0; A++); + (A->LongOpt == 0 || stringcasecmp(Opt,OptEnd,A->LongOpt) != 0); + ++A); // Failed again.. if (A->end() == true && OptEnd - Opt != 1) -- cgit v1.2.3 From e5a91f7e42a72c97e12e66569f3b8fc777652c26 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 10 Jun 2012 00:08:28 +0200 Subject: * apt-pkg/deb/deblistparser.cc: - set pkgCacheGen::Essential to "all" again (Closes: #675449) * apt-pkg/algorithms.cc: - force install only for one essential package out of a group --- apt-pkg/algorithms.cc | 35 ++++++++++++++++++++++++++++++----- apt-pkg/deb/deblistparser.cc | 11 +++++------ 2 files changed, 35 insertions(+), 11 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 2d710097a..2f5fcc7ab 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -362,11 +362,36 @@ bool pkgDistUpgrade(pkgDepCache &Cache) if (I->CurrentVer != 0) Cache.MarkInstall(I, true, 0, false); - /* Now, auto upgrade all essential packages - this ensures that - the essential packages are present and working */ - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) - if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) - Cache.MarkInstall(I, true, 0, false); + /* Now, install each essential package which is not installed + (and not provided by another package in the same name group) */ + std::string essential = _config->Find("pkgCacheGen::Essential", "all"); + if (essential == "all") + { + for (pkgCache::GrpIterator G = Cache.GrpBegin(); G.end() == false; ++G) + { + bool isEssential = false; + bool instEssential = false; + for (pkgCache::PkgIterator P = G.PackageList(); P.end() == false; P = G.NextPkg(P)) + { + if ((P->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential) + continue; + isEssential = true; + if (Cache[P].Install() == true) + { + instEssential = true; + break; + } + } + if (isEssential == false || instEssential == true) + continue; + pkgCache::PkgIterator P = G.FindPreferredPkg(); + Cache.MarkInstall(P, true, 0, false); + } + } + else if (essential != "none") + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) + if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) + Cache.MarkInstall(I, true, 0, false); /* We do it again over all previously installed packages to force conflict resolution on them all. */ diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 7bef6772c..0a7e41538 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -243,13 +243,12 @@ bool debListParser::UsePackage(pkgCache::PkgIterator &Pkg, if (Pkg->Section == 0) Pkg->Section = UniqFindTagWrite("Section"); - // Packages which are not from the "native" arch doesn't get the essential flag - // in the default "native" mode - it is also possible to mark "all" or "none". - // The "installed" mode is handled by ParseStatus(), See #544481 and friends. string const static myArch = _config->Find("APT::Architecture"); - string const static essential = _config->Find("pkgCacheGen::Essential", "native"); - if ((essential == "native" && Pkg->Arch != 0 && myArch == Pkg.Arch()) || - essential == "all") + // Possible values are: "all", "native", "installed" and "none" + // The "installed" mode is handled by ParseStatus(), See #544481 and friends. + string const static essential = _config->Find("pkgCacheGen::Essential", "all"); + if (essential == "all" || + (essential == "native" && Pkg->Arch != 0 && myArch == Pkg.Arch())) if (Section.FindFlag("Essential",Pkg->Flags,pkgCache::Flag::Essential) == false) return false; if (Section.FindFlag("Important",Pkg->Flags,pkgCache::Flag::Important) == false) -- cgit v1.2.3 From f87fab03bade8a049b318df68dfa4c361fab944c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 10 Jun 2012 00:40:55 +0200 Subject: * apt-pkg/aptconfiguration.cc: - if APT::Languages=none save "none" in allCodes so that the detected configuration is cached as intended (Closes: #674690, LP: #1004947) --- apt-pkg/aptconfiguration.cc | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index d763546f8..d31ccb642 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -234,17 +234,21 @@ std::vector const Configuration::getLanguages(bool const &All, // override the configuration settings vector of languages. string const forceLang = _config->Find("Acquire::Languages",""); if (forceLang.empty() == false) { - if (forceLang == "environment") { - codes = environment; - } else if (forceLang != "none") - codes.push_back(forceLang); - else //if (forceLang == "none") - builtin.clear(); - allCodes = codes; - for (std::vector::const_iterator b = builtin.begin(); - b != builtin.end(); ++b) - if (std::find(allCodes.begin(), allCodes.end(), *b) == allCodes.end()) - allCodes.push_back(*b); + if (forceLang == "none") { + codes.clear(); + allCodes.clear(); + allCodes.push_back("none"); + } else { + if (forceLang == "environment") + codes = environment; + else + codes.push_back(forceLang); + allCodes = codes; + for (std::vector::const_iterator b = builtin.begin(); + b != builtin.end(); ++b) + if (std::find(allCodes.begin(), allCodes.end(), *b) == allCodes.end()) + allCodes.push_back(*b); + } if (All == true) return allCodes; else -- cgit v1.2.3 From d5648746d4d4ea3f71aae5578a42050385e7b61d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 11 Jun 2012 01:31:27 +0200 Subject: * apt-pkg/cacheiterators.h: - add an IsMultiArchImplicit() method for Dep- and PrvIterator --- apt-pkg/cacheiterators.h | 4 +++- apt-pkg/edsp.cc | 12 ++++-------- apt-pkg/pkgcache.cc | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index d5e018be9..dcd353119 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -285,6 +285,7 @@ class pkgCache::DepIterator : public Iterator { bool IsNegative() const; bool IsIgnorable(PrvIterator const &Prv) const; bool IsIgnorable(PkgIterator const &Pkg) const; + bool IsMultiArchImplicit() const; void GlobOr(DepIterator &Start,DepIterator &End); Version **AllTargets() const; bool SmartTargetPkg(PkgIterator &Result) const; @@ -329,8 +330,9 @@ class pkgCache::PrvIterator : public Iterator { inline VerIterator OwnerVer() const {return VerIterator(*Owner,Owner->VerP + S->Version);}; inline PkgIterator OwnerPkg() const {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[S->Version].ParentPkg);}; - inline PrvIterator() : Iterator(), Type(PrvVer) {}; + bool IsMultiArchImplicit() const; + inline PrvIterator() : Iterator(), Type(PrvVer) {}; inline PrvIterator(pkgCache &Owner, Provides *Trg, Version*) : Iterator(Owner, Trg), Type(PrvVer) { if (S == 0) diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc index 791aac72f..adb8788b3 100644 --- a/apt-pkg/edsp.cc +++ b/apt-pkg/edsp.cc @@ -118,8 +118,7 @@ void EDSP::WriteScenarioDependency(pkgDepCache &Cache, FILE* output, pkgCache::P bool orGroup = false; for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep) { - // Ignore implicit dependencies for multiarch here - if (strcmp(Pkg.Arch(), Dep.TargetPkg().Arch()) != 0) + if (Dep.IsMultiArchImplicit() == true) continue; if (orGroup == false) dependencies[Dep->Type].append(", "); @@ -140,8 +139,7 @@ void EDSP::WriteScenarioDependency(pkgDepCache &Cache, FILE* output, pkgCache::P string provides; for (pkgCache::PrvIterator Prv = Ver.ProvidesList(); Prv.end() == false; ++Prv) { - // Ignore implicit provides for multiarch here - if (strcmp(Pkg.Arch(), Prv.ParentPkg().Arch()) != 0 || strcmp(Pkg.Name(),Prv.Name()) == 0) + if (Prv.IsMultiArchImplicit() == true) continue; provides.append(", ").append(Prv.Name()); } @@ -159,8 +157,7 @@ void EDSP::WriteScenarioLimitedDependency(pkgDepCache &Cache, FILE* output, bool orGroup = false; for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep) { - // Ignore implicit dependencies for multiarch here - if (strcmp(Pkg.Arch(), Dep.TargetPkg().Arch()) != 0) + if (Dep.IsMultiArchImplicit() == true) continue; if (orGroup == false) { @@ -193,8 +190,7 @@ void EDSP::WriteScenarioLimitedDependency(pkgDepCache &Cache, FILE* output, string provides; for (pkgCache::PrvIterator Prv = Ver.ProvidesList(); Prv.end() == false; ++Prv) { - // Ignore implicit provides for multiarch here - if (strcmp(Pkg.Arch(), Prv.ParentPkg().Arch()) != 0 || strcmp(Pkg.Name(),Prv.Name()) == 0) + if (Prv.IsMultiArchImplicit() == true) continue; if (pkgset.find(Prv.ParentPkg()) == pkgset.end()) continue; diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 997c70768..e06e74579 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -708,6 +708,18 @@ bool pkgCache::DepIterator::IsIgnorable(PrvIterator const &Prv) const return false; } /*}}}*/ +// DepIterator::IsMultiArchImplicit - added by the cache generation /*{{{*/ +// --------------------------------------------------------------------- +/* MultiArch can be translated to SingleArch for an resolver and we did so, + by adding dependencies to help the resolver understand the problem, but + sometimes it is needed to identify these to ignore them… */ +bool pkgCache::DepIterator::IsMultiArchImplicit() const +{ + if (ParentPkg()->Arch != TargetPkg()->Arch) + return true; + return false; +} + /*}}}*/ // ostream operator to handle string representation of a dependecy /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -946,3 +958,17 @@ pkgCache::DescIterator pkgCache::VerIterator::TranslatedDescription() const }; /*}}}*/ +// PrvIterator::IsMultiArchImplicit - added by the cache generation /*{{{*/ +// --------------------------------------------------------------------- +/* MultiArch can be translated to SingleArch for an resolver and we did so, + by adding provides to help the resolver understand the problem, but + sometimes it is needed to identify these to ignore them… */ +bool pkgCache::PrvIterator::IsMultiArchImplicit() const +{ + pkgCache::PkgIterator const Owner = OwnerPkg(); + pkgCache::PkgIterator const Parent = ParentPkg(); + if (Owner->Arch != Parent->Arch || Owner->Name == Parent->Name) + return true; + return false; +} + /*}}}*/ -- cgit v1.2.3 From 0f485ee50e9bcd75a93f24b632280b5bcc078141 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Mon, 11 Jun 2012 02:06:40 +0200 Subject: * apt-pkg/deb/deblistparser.cc: - add support for arch-specific qualifiers in dependencies --- apt-pkg/deb/deblistparser.cc | 20 +++++++++++++++++--- apt-pkg/pkgcache.cc | 5 ++++- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 0a7e41538..4948c9be4 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -637,16 +637,18 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver, if (Section.Find(Tag,Start,Stop) == false) return true; - string Package; string const pkgArch = Ver.Arch(); - string Version; - unsigned int Op; while (1) { + string Package; + string Version; + unsigned int Op; + Start = ParseDepends(Start,Stop,Package,Version,Op,false,!MultiArchEnabled); if (Start == 0) return _error->Error("Problem parsing dependency %s",Tag); + size_t const found = Package.rfind(':'); if (MultiArchEnabled == true && (Type == pkgCache::Dep::Conflicts || @@ -658,6 +660,18 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver, if (NewDepends(Ver,Package,*a,Version,Op,Type) == false) return false; } + else if (MultiArchEnabled == true && found != string::npos && + strcmp(Package.c_str() + found, ":any") != 0) + { + string Arch = Package.substr(found+1, string::npos); + Package = Package.substr(0, found); + // Such dependencies are not supposed to be accepted … + // … but this is probably the best thing to do. + if (Arch == "native") + Arch = _config->Find("APT::Architecture"); + if (NewDepends(Ver,Package,Arch,Version,Op,Type) == false) + return false; + } else if (NewDepends(Ver,Package,pkgArch,Version,Op,Type) == false) return false; if (Start == Stop) diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index e06e74579..f694a237e 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -715,7 +715,10 @@ bool pkgCache::DepIterator::IsIgnorable(PrvIterator const &Prv) const sometimes it is needed to identify these to ignore them… */ bool pkgCache::DepIterator::IsMultiArchImplicit() const { - if (ParentPkg()->Arch != TargetPkg()->Arch) + if (ParentPkg()->Arch != TargetPkg()->Arch && + (S->Type == pkgCache::Dep::Replaces || + S->Type == pkgCache::Dep::DpkgBreaks || + S->Type == pkgCache::Dep::Conflicts)) return true; return false; } -- cgit v1.2.3 From cd9694bf7c962b1938690a96017afba54028488a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 14 Jun 2012 15:46:49 +0200 Subject: * deb/deblistparser.cc: - ensure that mixed positive/negative architecture wildcards are handled in the same way as dpkg handles them --- apt-pkg/deb/deblistparser.cc | 53 +++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 23 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 4948c9be4..d29b28d48 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -561,28 +561,27 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop, // Parse an architecture if (I != Stop && *I == '[') { + ++I; // malformed - I++; - if (I == Stop) - return 0; - - const char *End = I; - bool Found = false; - bool NegArch = false; - while (I != Stop) + if (unlikely(I == Stop)) + return 0; + + const char *End = I; + bool Found = false; + bool NegArch = false; + while (I != Stop) { - // look for whitespace or ending ']' - while (End != Stop && !isspace(*End) && *End != ']') - End++; - - if (End == Stop) + // look for whitespace or ending ']' + for (;End != Stop && !isspace(*End) && *End != ']'; ++End); + + if (unlikely(End == Stop)) return 0; if (*I == '!') - { + { NegArch = true; - I++; - } + ++I; + } if (stringcmp(arch,I,End) == 0) { Found = true; @@ -591,23 +590,31 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop, if (fnmatch(wildcard.c_str(), completeArch.c_str(), 0) == 0) Found = true; } - + + if (Found == true) + { + if (I[-1] != '!') + NegArch = false; + // we found a match, so fast-forward to the end of the wildcards + for (; End != Stop && *End != ']'; ++End); + } + if (*End++ == ']') { I = End; break; } - + I = End; for (;I != Stop && isspace(*I) != 0; I++); - } + } - if (NegArch) + if (NegArch == true) Found = !Found; - - if (Found == false) + + if (Found == false) Package = ""; /* not for this arch */ } - + // Skip whitespace for (;I != Stop && isspace(*I) != 0; I++); } -- cgit v1.2.3 From 424ff669be2d1871592247907d977ed9fba3229f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 14 Jun 2012 18:48:23 +0200 Subject: * apt-pkg/deb/deblistparser.cc: - use PackageArchitectureMatchesSpecification filter * apt-pkg/cachefilter.cc: - add PackageArchitectureMatchesSpecification (Closes: #672603) --- apt-pkg/cachefilter.cc | 51 ++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/cachefilter.h | 30 ++++++++++++++++++++++++++ apt-pkg/deb/deblistparser.cc | 32 +++++---------------------- 3 files changed, 86 insertions(+), 27 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cachefilter.cc b/apt-pkg/cachefilter.cc index fb444208c..35f95fe22 100644 --- a/apt-pkg/cachefilter.cc +++ b/apt-pkg/cachefilter.cc @@ -9,10 +9,12 @@ #include #include #include +#include #include #include +#include #include /*}}}*/ @@ -52,5 +54,54 @@ PackageNameMatchesRegEx::~PackageNameMatchesRegEx() { /*{{{*/ delete pattern; } /*}}}*/ + +// CompleteArch to - tuple /*{{{*/ +//---------------------------------------------------------------------- +/* The complete architecture, consisting of -. */ +static std::string CompleteArch(std::string const &arch) { + if (arch.find('-') != std::string::npos) { + // ensure that only -any- is replaced and not something like company- + std::string complete = std::string("-").append(arch).append("-"); + complete = SubstVar(complete, "-any-", "-*-"); + complete = complete.substr(1, complete.size()-2); + return complete; + } + else if (arch == "armel") return "linux-arm"; + else if (arch == "armhf") return "linux-arm"; + else if (arch == "lpia") return "linux-i386"; + else if (arch == "powerpcspe") return "linux-powerpc"; + else if (arch == "uclibc-linux-armel") return "linux-arm"; + else if (arch == "uclinux-armel") return "uclinux-arm"; + else if (arch == "any") return "*-*"; + else return "linux-" + arch; +} + /*}}}*/ +PackageArchitectureMatchesSpecification::PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern) :/*{{{*/ + literal(pattern), isPattern(isPattern), d(NULL) { + complete = CompleteArch(pattern); +} + /*}}}*/ +bool PackageArchitectureMatchesSpecification::operator() (char const * const &arch) {/*{{{*/ + if (strcmp(literal.c_str(), arch) == 0 || + strcmp(complete.c_str(), arch) == 0) + return true; + std::string const pkgarch = CompleteArch(arch); + if (isPattern == true) + return fnmatch(complete.c_str(), pkgarch.c_str(), 0) == 0; + return fnmatch(pkgarch.c_str(), complete.c_str(), 0) == 0; +} + /*}}}*/ +bool PackageArchitectureMatchesSpecification::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/ + return (*this)(Pkg.Arch()); +} + /*}}}*/ +bool PackageArchitectureMatchesSpecification::operator() (pkgCache::VerIterator const &Ver) {/*{{{*/ + return (*this)(Ver.ParentPkg()); +} + /*}}}*/ +PackageArchitectureMatchesSpecification::~PackageArchitectureMatchesSpecification() { /*{{{*/ +} + /*}}}*/ + } } diff --git a/apt-pkg/cachefilter.h b/apt-pkg/cachefilter.h index 5d426008b..25cd43f47 100644 --- a/apt-pkg/cachefilter.h +++ b/apt-pkg/cachefilter.h @@ -26,6 +26,36 @@ public: ~PackageNameMatchesRegEx(); }; /*}}}*/ +// PackageArchitectureMatchesSpecification /*{{{*/ +/** \class PackageArchitectureMatchesSpecification + \brief matching against architecture specification strings + + The strings are of the format - where either component, + or the whole string, can be the wildcard "any" as defined in + debian-policy §11.1 "Architecture specification strings". + + Examples: i386, mipsel, linux-any, any-amd64, any */ +class PackageArchitectureMatchesSpecification { + std::string literal; + std::string complete; + bool isPattern; + /** \brief dpointer placeholder (for later in case we need it) */ + void *d; +public: + /** \brief matching against architecture specification strings + * + * @param pattern is the architecture specification string + * @param isPattern defines if the given \b pattern is a + * architecture specification pattern to match others against + * or if it is the fixed string and matched against patterns + */ + PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern = true); + bool operator() (char const * const &arch); + bool operator() (pkgCache::PkgIterator const &Pkg); + bool operator() (pkgCache::VerIterator const &Ver); + ~PackageArchitectureMatchesSpecification(); +}; + /*}}}*/ } } #endif diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index d29b28d48..efb76ef54 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -22,7 +23,6 @@ #include #include -#include #include /*}}}*/ @@ -464,22 +464,6 @@ const char *debListParser::ConvertRelation(const char *I,unsigned int &Op) } return I; } - -/* - * CompleteArch: - * - * The complete architecture, consisting of -. - */ -static string CompleteArch(std::string const &arch) { - if (arch == "armel") return "linux-arm"; - if (arch == "armhf") return "linux-arm"; - if (arch == "lpia") return "linux-i386"; - if (arch == "powerpcspe") return "linux-powerpc"; - if (arch == "uclibc-linux-armel") return "linux-arm"; - if (arch == "uclinux-armel") return "uclinux-arm"; - - return (arch.find("-") != string::npos) ? arch : "linux-" + arch; -} /*}}}*/ // ListParser::ParseDepends - Parse a dependency element /*{{{*/ // --------------------------------------------------------------------- @@ -556,7 +540,7 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop, if (ParseArchFlags == true) { - string completeArch = CompleteArch(arch); + APT::CacheFilter::PackageArchitectureMatchesSpecification matchesArch(arch, false); // Parse an architecture if (I != Stop && *I == '[') @@ -583,16 +567,10 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop, ++I; } - if (stringcmp(arch,I,End) == 0) { - Found = true; - } else { - std::string wildcard = SubstVar(string(I, End), "any", "*"); - if (fnmatch(wildcard.c_str(), completeArch.c_str(), 0) == 0) - Found = true; - } - - if (Found == true) + std::string arch(I, End); + if (arch.empty() == false && matchesArch(arch.c_str()) == true) { + Found = true; if (I[-1] != '!') NegArch = false; // we found a match, so fast-forward to the end of the wildcards -- cgit v1.2.3 From 2f0d4029bff5699f0fd1a61616d38f7dd5c1d52c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 14 Jun 2012 19:03:37 +0200 Subject: * apt-pkg/cacheset.cc: - add PackageContainerInterface::FromGroup to support architecture specifications with wildcards on the commandline --- apt-pkg/cacheset.cc | 54 +++++++++++++++++++++++++++++++++++++++++++++++++---- apt-pkg/cacheset.h | 1 + 2 files changed, 51 insertions(+), 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc index e2dbe0e57..784d1f0bf 100644 --- a/apt-pkg/cacheset.cc +++ b/apt-pkg/cacheset.cc @@ -182,15 +182,61 @@ pkgCache::PkgIterator PackageContainerInterface::FromName(pkgCacheFile &Cache, return Pkg; } /*}}}*/ +// FromGroup - Returns the package defined by this string /*{{{*/ +bool PackageContainerInterface::FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, + std::string pkg, CacheSetHelper &helper) { + if (unlikely(Cache.GetPkgCache() == 0)) + return false; + + size_t const archfound = pkg.find_last_of(':'); + std::string arch; + if (archfound != std::string::npos) { + arch = pkg.substr(archfound+1); + pkg.erase(archfound); + } + + pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg); + if (Grp.end() == false) { + if (arch.empty() == true) { + pkgCache::PkgIterator Pkg = Grp.FindPreferredPkg(); + if (Pkg.end() == false) + { + pci->insert(Pkg); + return true; + } + } else { + bool found = false; + // for 'linux-any' return the first package matching, for 'linux-*' return all matches + bool const isGlobal = arch.find('*') != std::string::npos; + APT::CacheFilter::PackageArchitectureMatchesSpecification pams(arch); + for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg)) { + if (pams(Pkg) == false) + continue; + pci->insert(Pkg); + found = true; + if (isGlobal == false) + break; + } + if (found == true) + return true; + } + } + + pkgCache::PkgIterator Pkg = helper.canNotFindPkgName(Cache, pkg); + if (Pkg.end() == true) + return false; + + pci->insert(Pkg); + return true; +} + /*}}}*/ // FromString - Return all packages matching a specific string /*{{{*/ bool PackageContainerInterface::FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str, CacheSetHelper &helper) { bool found = true; _error->PushToStack(); - pkgCache::PkgIterator Pkg = FromName(Cache, str, helper); - if (Pkg.end() == false) - pci->insert(Pkg); - else if (FromTask(pci, Cache, str, helper) == false && + if (FromGroup(pci, Cache, str, helper) == false && + FromTask(pci, Cache, str, helper) == false && FromRegEx(pci, Cache, str, helper) == false) { helper.canNotFindPackage(pci, Cache, str); diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index 5b9900603..2a45910ba 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -139,6 +139,7 @@ public: static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper); + static bool FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper); static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper); -- cgit v1.2.3 From 0952aee667274d8d7986bc2d03597fdc6bde9584 Mon Sep 17 00:00:00 2001 From: Daniel Hartwig Date: Thu, 14 Jun 2012 19:14:55 +0200 Subject: * apt-pkg/pkgcachegen.cc: - always reset _error->StackCount in MakeStatusCache (Closes: #677175) --- apt-pkg/pkgcachegen.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 538d10b35..f70cbd02a 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -1316,10 +1316,11 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress } _error->RevertToStack(); } - else if (Debug == true) + else { _error->MergeWithStack(); - std::clog << "Open filebased MMap" << std::endl; + if (Debug == true) + std::clog << "Open filebased MMap" << std::endl; } } if (Writeable == false || CacheFile.empty() == true) -- cgit v1.2.3 From ef5dc12ccb6964a52c7c7674d2eff98435089d92 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 14 Jun 2012 19:40:12 +0200 Subject: * apt-pkg/pkgcache.cc: - do a string comparision for architecture checking in IsMultiArchImplicit as 'unique' strings in the pkgcache aren't unique (Closes: #677454) --- apt-pkg/pkgcache.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index f694a237e..9acb7da72 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -970,7 +970,7 @@ bool pkgCache::PrvIterator::IsMultiArchImplicit() const { pkgCache::PkgIterator const Owner = OwnerPkg(); pkgCache::PkgIterator const Parent = ParentPkg(); - if (Owner->Arch != Parent->Arch || Owner->Name == Parent->Name) + if (strcmp(Owner.Arch(), Parent.Arch()) != 0 || Owner->Name == Parent->Name) return true; return false; } -- cgit v1.2.3 From 7899a1339ced1e8fa10730e5619349b9fd782fac Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 16 Jun 2012 14:35:15 +0200 Subject: * apt-pkg/contrib/mmap.cc: - Fix the Fallback option to work correctly, by not calling realloc() on a map mapped by mmap(), and by using malloc and friends instead of new[]. --- apt-pkg/contrib/mmap.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc index 2d12b6fe9..131cefd6e 100644 --- a/apt-pkg/contrib/mmap.cc +++ b/apt-pkg/contrib/mmap.cc @@ -83,7 +83,7 @@ bool MMap::Map(FileFd &Fd) { if ((Flags & ReadOnly) != ReadOnly) return _error->Error("Compressed file %s can only be mapped readonly", Fd.Name().c_str()); - Base = new unsigned char[iSize]; + Base = malloc(iSize); SyncToFd = new FileFd(); if (Fd.Seek(0L) == false || Fd.Read(Base, iSize) == false) return _error->Error("Compressed file %s can't be read into mmap", Fd.Name().c_str()); @@ -91,17 +91,17 @@ bool MMap::Map(FileFd &Fd) } // Map it. - Base = mmap(0,iSize,Prot,Map,Fd.Fd(),0); + Base = (Flags & Fallback) ? MAP_FAILED : mmap(0,iSize,Prot,Map,Fd.Fd(),0); if (Base == (void *)-1) { - if (errno == ENODEV || errno == EINVAL) + if (errno == ENODEV || errno == EINVAL || (Flags & Fallback)) { // 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]; + Base = malloc(iSize); return Fd.Read(Base, iSize); } // FIXME: Writing to compressed fd's ? @@ -109,7 +109,7 @@ bool MMap::Map(FileFd &Fd) if (dupped_fd == -1) return _error->Errno("mmap", _("Couldn't duplicate file descriptor %i"), Fd.Fd()); - Base = new unsigned char[iSize]; + Base = calloc(iSize, 1); SyncToFd = new FileFd (dupped_fd); if (!SyncToFd->Seek(0L) || !SyncToFd->Read(Base, iSize)) return false; @@ -135,7 +135,7 @@ bool MMap::Close(bool DoSync) if (SyncToFd != NULL) { - delete[] (char *)Base; + free(Base); delete SyncToFd; SyncToFd = NULL; } @@ -283,8 +283,7 @@ DynamicMMap::DynamicMMap(unsigned long Flags,unsigned long const &WorkSpace, } #endif // fallback to a static allocated space - Base = new unsigned char[WorkSpace]; - memset(Base,0,WorkSpace); + Base = calloc(WorkSpace, 1); iSize = 0; } /*}}}*/ @@ -300,7 +299,7 @@ DynamicMMap::~DynamicMMap() #ifdef _POSIX_MAPPED_FILES munmap(Base, WorkSpace); #else - delete [] (unsigned char *)Base; + free(Base); #endif return; } -- cgit v1.2.3 From 61a406f0fc9c7b1807acb2ff146db6acd18e879c Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 16 Jun 2012 14:38:09 +0200 Subject: Zero out the new memory allocated with realloc(). --- apt-pkg/contrib/mmap.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc index 131cefd6e..77b4502f5 100644 --- a/apt-pkg/contrib/mmap.cc +++ b/apt-pkg/contrib/mmap.cc @@ -461,6 +461,8 @@ bool DynamicMMap::Grow() { return false; Base = realloc(Base, newSize); + /* Set new memory to 0 */ + memset((char*)Base + WorkSpace, 0, newSize - WorkSpace); if (Base == NULL) return false; } -- cgit v1.2.3 From e3026ce49a0839dfbe494af7e60d91bc7204f88e Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 16 Jun 2012 15:23:06 +0200 Subject: Fix previous commit: Do not call memset() if realloc() returned NULL. --- apt-pkg/contrib/mmap.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc index 77b4502f5..593bb063b 100644 --- a/apt-pkg/contrib/mmap.cc +++ b/apt-pkg/contrib/mmap.cc @@ -461,10 +461,11 @@ bool DynamicMMap::Grow() { return false; Base = realloc(Base, newSize); - /* Set new memory to 0 */ - memset((char*)Base + WorkSpace, 0, newSize - WorkSpace); if (Base == NULL) return false; + else + /* Set new memory to 0 */ + memset((char*)Base + WorkSpace, 0, newSize - WorkSpace); } Pools =(Pool*) Base + poolOffset; -- cgit v1.2.3 From 2b803d4069e1f05d0461fbad004482ff02100812 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 16 Jun 2012 19:55:43 +0200 Subject: do not dereference the storage for the unique strings as the pointer can change at the time of writing the strings, so first store it temporary and then save the index in the (possibily new) pointer location --- apt-pkg/deb/debindexfile.cc | 3 ++- apt-pkg/deb/deblistparser.cc | 16 +++++++++------- apt-pkg/edsp/edspindexfile.cc | 3 ++- 3 files changed, 13 insertions(+), 9 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 76c740341..de645bb6e 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -602,7 +602,8 @@ bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const pkgCache::PkgFileIterator CFile = Gen.GetCurFile(); CFile->Size = Pkg.FileSize(); CFile->mtime = Pkg.ModificationTime(); - CFile->Archive = Gen.WriteUniqString("now"); + map_ptrloc const storage = Gen.WriteUniqString("now"); + CFile->Archive = storage; if (Gen.MergeList(Parser) == false) return _error->Error("Problem with MergeList %s",File.c_str()); diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index efb76ef54..e93e51af3 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -782,7 +782,8 @@ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI, { // apt-secure does no longer download individual (per-section) Release // file. to provide Component pinning we use the section name now - FileI->Component = WriteUniqString(component); + map_ptrloc const storage = WriteUniqString(component); + FileI->Component = storage; // FIXME: Code depends on the fact that Release files aren't compressed FILE* release = fdopen(dup(File.Fd()), "r"); @@ -869,13 +870,14 @@ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI, break; *s = '\0'; } + map_ptrloc const storage = WriteUniqString(data); switch (writeTo) { - case Suite: FileI->Archive = WriteUniqString(data); break; - case Component: FileI->Component = WriteUniqString(data); break; - case Version: FileI->Version = WriteUniqString(data); break; - case Origin: FileI->Origin = WriteUniqString(data); break; - case Codename: FileI->Codename = WriteUniqString(data); break; - case Label: FileI->Label = WriteUniqString(data); break; + case Suite: FileI->Archive = storage; break; + case Component: FileI->Component = storage; break; + case Version: FileI->Version = storage; break; + case Origin: FileI->Origin = storage; break; + case Codename: FileI->Codename = storage; break; + case Label: FileI->Label = storage; break; case None: break; } } diff --git a/apt-pkg/edsp/edspindexfile.cc b/apt-pkg/edsp/edspindexfile.cc index 482581979..98ce4497a 100644 --- a/apt-pkg/edsp/edspindexfile.cc +++ b/apt-pkg/edsp/edspindexfile.cc @@ -51,7 +51,8 @@ bool edspIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const pkgCache::PkgFileIterator CFile = Gen.GetCurFile(); CFile->Size = Pkg.FileSize(); CFile->mtime = Pkg.ModificationTime(); - CFile->Archive = Gen.WriteUniqString("edsp::scenario"); + map_ptrloc const storage = Gen.WriteUniqString("edsp::scenario"); + CFile->Archive = storage; if (Gen.MergeList(Parser) == false) return _error->Error("Problem with MergeList %s",File.c_str()); -- cgit v1.2.3 From 0854ad8b8016d0132741a267492d72cfa0d3bd8e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 21 Jun 2012 12:32:56 +0200 Subject: check when finished downloading the InRelease file if it has the expected gpg clearsign signature and if not download Release/Release.gpg instead --- apt-pkg/acquire-item.cc | 10 +++++++++- apt-pkg/contrib/fileutl.cc | 20 ++++++++++++++++++++ apt-pkg/contrib/fileutl.h | 4 ++++ apt-pkg/indexcopy.cc | 6 +----- 4 files changed, 34 insertions(+), 6 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index a30e98858..9723cddac 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -1235,9 +1235,17 @@ void pkgAcqMetaIndex::Done(string Message,unsigned long long Size,string Hash, / } else { + // if we expect a ClearTextSignature (InRelase), ensure that + // this is what we get and if not fail to queue a + // Release/Release.gpg, see #346386 + if (SigFile == DestFile && !IsPgpClearTextSignature(DestFile)) + { + Failed(Message, Cfg); + return; + } + // There was a signature file, so pass it to gpgv for // verification - if (_config->FindB("Debug::pkgAcquire::Auth", false)) std::cerr << "Metaindex acquired, queueing gpg verification (" << SigFile << "," << DestFile << ")\n"; diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 1808489d7..7af5f5f5e 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -824,6 +824,26 @@ bool ExecWait(pid_t Pid,const char *Name,bool Reap) } /*}}}*/ +// IsPgpClearTextSignature - Check if a file is Pgp/GPG clearsigned /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool IsPgpClearTextSignature(string const &FileName) +{ + static const char* SIGMSG = "-----BEGIN PGP SIGNED MESSAGE-----\n"; + char buffer[sizeof(SIGMSG)]; + FILE* gpg = fopen(FileName.c_str(), "r"); + if (gpg == NULL) + return false; + + char const * const test = fgets(buffer, sizeof(buffer), gpg); + fclose(gpg); + if (test == NULL || strcmp(buffer, SIGMSG) != 0) + return false; + + return true; +} + + // FileFd::Open - Open a file /*{{{*/ // --------------------------------------------------------------------- /* The most commonly used open mode combinations are given with Mode */ diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 1ca41cb7d..c51add66e 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -179,6 +179,8 @@ bool WaitFd(int Fd,bool write = false,unsigned long timeout = 0); pid_t ExecFork(); bool ExecWait(pid_t Pid,const char *Name,bool Reap = false); +bool IsPgpClearTextSignature(std::string const &FileName); + // File string manipulators std::string flNotDir(std::string File); std::string flNotFile(std::string File); @@ -186,4 +188,6 @@ std::string flNoLink(std::string File); std::string flExtension(std::string File); std::string flCombine(std::string Dir,std::string File); + + #endif diff --git a/apt-pkg/indexcopy.cc b/apt-pkg/indexcopy.cc index e29e2819c..db3d10ecd 100644 --- a/apt-pkg/indexcopy.cc +++ b/apt-pkg/indexcopy.cc @@ -648,16 +648,12 @@ bool SigVerify::RunGPGV(std::string const &File, std::string const &FileGPG, { if (File == FileGPG) { - #define SIGMSG "-----BEGIN PGP SIGNED MESSAGE-----\n" - char buffer[sizeof(SIGMSG)]; FILE* gpg = fopen(File.c_str(), "r"); if (gpg == NULL) return _error->Errno("RunGPGV", _("Could not open file %s"), File.c_str()); - char const * const test = fgets(buffer, sizeof(buffer), gpg); fclose(gpg); - if (test == NULL || strcmp(buffer, SIGMSG) != 0) + if (!IsPgpClearTextSignature(File)) return _error->Error(_("File %s doesn't start with a clearsigned message"), File.c_str()); - #undef SIGMSG } -- cgit v1.2.3 From 479a2beb0f5605652689d74a78dd224b69ba2e8f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 21 Jun 2012 13:19:04 +0200 Subject: update comments and add one FIXME for the next ABI break --- apt-pkg/acquire-item.cc | 6 +++++- apt-pkg/contrib/fileutl.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 9723cddac..ddd3300f9 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -1235,10 +1235,14 @@ void pkgAcqMetaIndex::Done(string Message,unsigned long long Size,string Hash, / } else { + // FIXME: move this into pkgAcqMetaClearSig::Done on the next + // ABI break + // if we expect a ClearTextSignature (InRelase), ensure that // this is what we get and if not fail to queue a // Release/Release.gpg, see #346386 - if (SigFile == DestFile && !IsPgpClearTextSignature(DestFile)) + if (SigFile == DestFile && + !IsPgpClearTextSignature(DestFile)) { Failed(Message, Cfg); return; diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index c51add66e..a9cb45e9a 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -179,6 +179,7 @@ bool WaitFd(int Fd,bool write = false,unsigned long timeout = 0); pid_t ExecFork(); bool ExecWait(pid_t Pid,const char *Name,bool Reap = false); +// check if the given file starts with a PGP cleartext signature bool IsPgpClearTextSignature(std::string const &FileName); // File string manipulators -- cgit v1.2.3 From 947878508fbd153766a9ded131a04260ca4c7a83 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 9 Jul 2012 17:38:06 +0200 Subject: * apt-pkg/contrib/strutl.cc: - support \n and \r\n line endings in ReadMessages --- apt-pkg/contrib/strutl.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index ca096d736..df11a80ad 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -752,7 +752,8 @@ bool ReadMessages(int Fd, vector &List) // Look for the end of the message for (char *I = Buffer; I + 1 < End; I++) { - if (I[0] != '\n' || I[1] != '\n') + if (I[1] != '\n' || + (strncmp(I, "\n\n", 2) != 0 && strncmp(I, "\r\n\r\n", 4) != 0)) continue; // Pull the message out @@ -760,7 +761,7 @@ bool ReadMessages(int Fd, vector &List) PartialMessage += Message; // Fix up the buffer - for (; I < End && *I == '\n'; I++); + for (; I < End && (*I == '\r' || *I == '\n'); ++I); End -= I-Buffer; memmove(Buffer,I,End-Buffer); I = Buffer; -- cgit v1.2.3 From 1c89c98a56df709b4c4477bbd7b86f4e32cee214 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 10 Jul 2012 15:08:06 +0200 Subject: cherry pick -r1846 from bzr+ssh://bazaar.launchpad.net/~mvo/apt/lp346386/ --- apt-pkg/contrib/fileutl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 20d2a02f5..d63195c7d 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -858,7 +858,7 @@ bool ExecWait(pid_t Pid,const char *Name,bool Reap) bool IsPgpClearTextSignature(string const &FileName) { static const char* SIGMSG = "-----BEGIN PGP SIGNED MESSAGE-----\n"; - char buffer[sizeof(SIGMSG)]; + char buffer[strlen(SIGMSG)+1]; FILE* gpg = fopen(FileName.c_str(), "r"); if (gpg == NULL) return false; -- cgit v1.2.3 From fe5804fc5010dd8f2e9406187bfc1f6afeb29c5a Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 10 Jul 2012 15:19:09 +0200 Subject: cherry pick -r1847 from bzr+ssh://bazaar.launchpad.net/~mvo/apt/lp346386/ --- apt-pkg/acquire-item.cc | 3 +-- apt-pkg/contrib/fileutl.cc | 4 ++-- apt-pkg/contrib/fileutl.h | 2 +- apt-pkg/indexcopy.cc | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index ddd3300f9..665dd427e 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -1241,8 +1241,7 @@ void pkgAcqMetaIndex::Done(string Message,unsigned long long Size,string Hash, / // if we expect a ClearTextSignature (InRelase), ensure that // this is what we get and if not fail to queue a // Release/Release.gpg, see #346386 - if (SigFile == DestFile && - !IsPgpClearTextSignature(DestFile)) + if (SigFile == DestFile && !StartsWithGPGClearTextSignature(DestFile)) { Failed(Message, Cfg); return; diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index d63195c7d..960616f33 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -852,10 +852,10 @@ bool ExecWait(pid_t Pid,const char *Name,bool Reap) } /*}}}*/ -// IsPgpClearTextSignature - Check if a file is Pgp/GPG clearsigned /*{{{*/ +// StartsWithGPGClearTextSignature - Check if a file is Pgp/GPG clearsigned /*{{{*/ // --------------------------------------------------------------------- /* */ -bool IsPgpClearTextSignature(string const &FileName) +bool StartsWithGPGClearTextSignature(string const &FileName) { static const char* SIGMSG = "-----BEGIN PGP SIGNED MESSAGE-----\n"; char buffer[strlen(SIGMSG)+1]; diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 1e16540f7..510b1c984 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -181,7 +181,7 @@ pid_t ExecFork(); bool ExecWait(pid_t Pid,const char *Name,bool Reap = false); // check if the given file starts with a PGP cleartext signature -bool IsPgpClearTextSignature(std::string const &FileName); +bool StartsWithGPGClearTextSignature(std::string const &FileName); // File string manipulators std::string flNotDir(std::string File); diff --git a/apt-pkg/indexcopy.cc b/apt-pkg/indexcopy.cc index db3d10ecd..ddf1909b7 100644 --- a/apt-pkg/indexcopy.cc +++ b/apt-pkg/indexcopy.cc @@ -652,7 +652,7 @@ bool SigVerify::RunGPGV(std::string const &File, std::string const &FileGPG, if (gpg == NULL) return _error->Errno("RunGPGV", _("Could not open file %s"), File.c_str()); fclose(gpg); - if (!IsPgpClearTextSignature(File)) + if (!StartsWithGPGClearTextSignature(File)) return _error->Error(_("File %s doesn't start with a clearsigned message"), File.c_str()); } -- cgit v1.2.3