From 17019a09e703452735d5af2538654e0532d27d51 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 9 Feb 2012 18:06:29 +0100 Subject: call dpkg --assert-multi-arch with execvp instead of execv --- apt-pkg/aptconfiguration.cc | 2 +- apt-pkg/deb/dpkgpm.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index b5ad74831..721b6fd63 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -376,7 +376,7 @@ std::vector const Configuration::getArchitectures(bool const &Cache dup2(nullfd, STDIN_FILENO); dup2(external[1], STDOUT_FILENO); dup2(nullfd, STDERR_FILENO); - execv(Args[0], (char**) &Args[0]); + execvp(Args[0], (char**) &Args[0]); _error->WarningE("getArchitecture", "Can't detect foreign architectures supported by dpkg!"); _exit(100); } diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 8c63b0c9b..3f9e68210 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -905,7 +905,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) dup2(nullfd, STDIN_FILENO); dup2(nullfd, STDOUT_FILENO); dup2(nullfd, STDERR_FILENO); - execv(Args[0], (char**) &Args[0]); + execvp(Args[0], (char**) &Args[0]); _error->WarningE("dpkgGo", "Can't detect if dpkg supports multi-arch!"); _exit(2); } -- cgit v1.2.3 From dd7233af3e0287566af3946da4b06afd6ccca73a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 10 Feb 2012 15:01:31 +0100 Subject: ensure that architectures are not added multiple times --- apt-pkg/aptconfiguration.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index 721b6fd63..4324f0e63 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -392,7 +392,9 @@ std::vector const Configuration::getArchitectures(bool const &Cache if (arch[0] != '\0') { char const* archend = arch; for (; isspace(*archend) == 0 && *archend != '\0'; ++archend); - archs.push_back(string(arch, (archend - arch))); + string a(arch, (archend - arch)); + if (std::find(archs.begin(), archs.end(), a) == archs.end()) + archs.push_back(a); } arch = strtok(NULL, " "); } -- cgit v1.2.3 From 5eb9a474dca2f48a935c234357c3adc9b372423e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 11 Feb 2012 18:54:48 +0100 Subject: correctly ignore already (un)hold packages --- apt-pkg/cacheset.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index 91d7eec1c..6f0a0e358 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -191,6 +191,8 @@ public: /*{{{*/ inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; } inline bool operator!=(iterator const &i) const { return _iter != i._iter; }; inline bool operator==(iterator const &i) const { return _iter == i._iter; }; + inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; }; + inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; }; friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); } }; /*}}}*/ @@ -201,7 +203,9 @@ public: /*{{{*/ bool empty() const { return _cont.empty(); }; void clear() { return _cont.clear(); }; + //FIXME: on ABI break, replace the first with the second without bool void erase(iterator position) { _cont.erase((typename Container::iterator)position); }; + iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); }; size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); }; void erase(iterator first, iterator last) { _cont.erase(first, last); }; size_t size() const { return _cont.size(); }; @@ -507,6 +511,8 @@ public: /*{{{*/ inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; } inline bool operator!=(iterator const &i) const { return _iter != i._iter; }; inline bool operator==(iterator const &i) const { return _iter == i._iter; }; + inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; }; + inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; }; friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); } }; /*}}}*/ @@ -516,7 +522,9 @@ public: /*{{{*/ void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }; bool empty() const { return _cont.empty(); }; void clear() { return _cont.clear(); }; + //FIXME: on ABI break, replace the first with the second without bool void erase(iterator position) { _cont.erase((typename Container::iterator)position); }; + iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); }; size_t erase(const pkgCache::VerIterator x) { return _cont.erase(x); }; void erase(iterator first, iterator last) { _cont.erase(first, last); }; size_t size() const { return _cont.size(); }; -- cgit v1.2.3 From dd61e64da1fbae01dc82bab3635c946718cc0eb0 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 11 Feb 2012 21:01:35 +0100 Subject: save the universe by not printing messages about apport if a package with this name is not installed (Closes: #619646) --- apt-pkg/deb/dpkgpm.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 3f9e68210..499c3db8a 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1446,6 +1446,12 @@ void pkgDPkgPM::Reset() /* */ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg) { + // If apport doesn't exist or isn't installed do nothing + // This e.g. prevents messages in 'universes' without apport + pkgCache::PkgIterator apportPkg = Cache.FindPkg("apport"); + if (apportPkg.end() == true || apportPkg->CurrentVer == 0) + return; + string pkgname, reportfile, srcpkgname, pkgver, arch; string::size_type pos; FILE *report; -- cgit v1.2.3 From fbb2c7e04dd3155983560e0b01a71fd8f62f0b1b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 11 Feb 2012 22:36:03 +0100 Subject: * apt-pkg/cachefile.cc: - clean up lost atomic cachefiles with 'clean' (Closes: #650513) --- apt-pkg/cachefile.cc | 34 +++++++++++++++++++++ apt-pkg/contrib/fileutl.cc | 74 ++++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/contrib/fileutl.h | 1 + 3 files changed, 109 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc index 1b8d91a44..e425c940d 100644 --- a/apt-pkg/cachefile.cc +++ b/apt-pkg/cachefile.cc @@ -178,6 +178,40 @@ void pkgCacheFile::RemoveCaches() unlink(pkgcache.c_str()); if (srcpkgcache.empty() == false && RealFileExists(srcpkgcache) == true) unlink(srcpkgcache.c_str()); + if (pkgcache.empty() == false) + { + std::string cachedir = flNotFile(pkgcache); + std::string cachefile = flNotDir(pkgcache); + if (cachedir.empty() != true && cachefile.empty() != true) + { + cachefile.append("."); + std::vector caches = GetListOfFilesInDir(cachedir, false); + for (std::vector::const_iterator file = caches.begin(); file != caches.end(); ++file) + { + std::string nuke = flNotDir(*file); + if (strncmp(cachefile.c_str(), nuke.c_str(), cachefile.length()) != 0) + continue; + unlink(file->c_str()); + } + } + } + + if (srcpkgcache.empty() == true) + return; + + std::string cachedir = flNotFile(srcpkgcache); + std::string cachefile = flNotDir(srcpkgcache); + if (cachedir.empty() == true || cachefile.empty() == true) + return; + cachefile.append("."); + std::vector caches = GetListOfFilesInDir(cachedir, false); + for (std::vector::const_iterator file = caches.begin(); file != caches.end(); ++file) + { + std::string nuke = flNotDir(*file); + if (strncmp(cachefile.c_str(), nuke.c_str(), cachefile.length()) != 0) + continue; + unlink(file->c_str()); + } } /*}}}*/ // CacheFile::Close - close the cache files /*{{{*/ diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 529e7d655..557ba0ca6 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -454,6 +454,80 @@ std::vector GetListOfFilesInDir(string const &Dir, std::vector c } closedir(D); + if (SortList == true) + std::sort(List.begin(),List.end()); + return List; +} +std::vector GetListOfFilesInDir(string const &Dir, bool SortList) +{ + bool const Debug = _config->FindB("Debug::GetListOfFilesInDir", false); + if (Debug == true) + std::clog << "Accept in " << Dir << " all regular files" << std::endl; + + std::vector List; + + if (DirectoryExists(Dir.c_str()) == false) + { + _error->Error(_("List of files can't be created as '%s' is not a directory"), Dir.c_str()); + return List; + } + + DIR *D = opendir(Dir.c_str()); + if (D == 0) + { + _error->Errno("opendir",_("Unable to read %s"),Dir.c_str()); + return List; + } + + for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D)) + { + // skip "hidden" files + if (Ent->d_name[0] == '.') + continue; + + // Make sure it is a file and not something else + string const File = flCombine(Dir,Ent->d_name); +#ifdef _DIRENT_HAVE_D_TYPE + if (Ent->d_type != DT_REG) +#endif + { + if (RealFileExists(File.c_str()) == false) + { + if (Debug == true) + std::clog << "Bad file: " << Ent->d_name << " → it is not a real file" << std::endl; + continue; + } + } + + // Skip bad filenames ala run-parts + const char *C = Ent->d_name; + for (; *C != 0; ++C) + if (isalpha(*C) == 0 && isdigit(*C) == 0 + && *C != '_' && *C != '-' && *C != '.') + break; + + // we don't reach the end of the name -> bad character included + if (*C != 0) + { + if (Debug == true) + std::clog << "Bad file: " << Ent->d_name << " → bad character »" << *C << "« in filename" << std::endl; + continue; + } + + // skip filenames which end with a period. These are never valid + if (*(C - 1) == '.') + { + if (Debug == true) + std::clog << "Bad file: " << Ent->d_name << " → Period as last character" << std::endl; + continue; + } + + if (Debug == true) + std::clog << "Accept file: " << Ent->d_name << " in " << Dir << std::endl; + List.push_back(File); + } + closedir(D); + if (SortList == true) std::sort(List.begin(),List.end()); return List; diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 3814cfe44..1ca41cb7d 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -171,6 +171,7 @@ std::vector GetListOfFilesInDir(std::string const &Dir, std::string bool const &SortList, bool const &AllowNoExt=false); std::vector GetListOfFilesInDir(std::string const &Dir, std::vector const &Ext, bool const &SortList); +std::vector GetListOfFilesInDir(std::string const &Dir, bool SortList); std::string SafeGetCWD(); void SetCloseExec(int Fd,bool Close); void SetNonBlock(int Fd,bool Block); -- cgit v1.2.3 From d90d3a05de6c550ae2bf54347cda7b39074e63ef Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 18 Feb 2012 18:23:09 +0100 Subject: * apt-pkg/indexrecords.cc: - do not create empty Entries as a sideeffect of Lookup() --- apt-pkg/indexrecords.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc index cdb9250e8..af2639beb 100644 --- a/apt-pkg/indexrecords.cc +++ b/apt-pkg/indexrecords.cc @@ -44,7 +44,10 @@ time_t indexRecords::GetValidUntil() const const indexRecords::checkSum *indexRecords::Lookup(const string MetaKey) { - return Entries[MetaKey]; + std::map::const_iterator sum = Entries.find(MetaKey); + if (sum == Entries.end()) + return NULL; + return sum->second; } bool indexRecords::Exists(string const &MetaKey) const -- cgit v1.2.3 From c0d58f4276a75f3cd6ebedf20458321a3477a048 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 18 Feb 2012 19:17:57 +0100 Subject: ensure that the cache-directories are really directories before trying to get a list of included files from them --- apt-pkg/cachefile.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc index e425c940d..f852542e5 100644 --- a/apt-pkg/cachefile.cc +++ b/apt-pkg/cachefile.cc @@ -182,7 +182,7 @@ void pkgCacheFile::RemoveCaches() { std::string cachedir = flNotFile(pkgcache); std::string cachefile = flNotDir(pkgcache); - if (cachedir.empty() != true && cachefile.empty() != true) + if (cachedir.empty() != true && cachefile.empty() != true && DirectoryExists(cachedir) == true) { cachefile.append("."); std::vector caches = GetListOfFilesInDir(cachedir, false); @@ -201,7 +201,7 @@ void pkgCacheFile::RemoveCaches() std::string cachedir = flNotFile(srcpkgcache); std::string cachefile = flNotDir(srcpkgcache); - if (cachedir.empty() == true || cachefile.empty() == true) + if (cachedir.empty() == true || cachefile.empty() == true || DirectoryExists(cachedir) == false) return; cachefile.append("."); std::vector caches = GetListOfFilesInDir(cachedir, false); -- cgit v1.2.3 From 8e3900d0d7efc11d538b944ed1d9e4e3d5286ff6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 18 Feb 2012 19:40:13 +0100 Subject: * apt-pkg/acquire-item.cc: - drop support for i18n/Index file (introduced in 0.8.11) and use the Release file instead to get the Translations (Closes: #649314) * ftparchive/writer.cc: - add 'Translation-*' to the default patterns i18n/Index was never used outside debian - and even here it isn't used consistently as only 'main' has such a file. As the Release file now includes the Translation-* files we therefore drop support for i18n/Index. A version supporting it was never part of a debian release and still supporting it would mean that we get 99% of the time a 404 as response to the request anyway and confuse archive maintainers who want to provide all files APT tries to acquire. --- apt-pkg/acquire-item.cc | 67 ++++++++++++++------------------------------- apt-pkg/deb/debmetaindex.cc | 36 ++++++++---------------- 2 files changed, 31 insertions(+), 72 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index f231c42b4..ca40b0bd7 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -189,14 +189,14 @@ void pkgAcquire::Item::ReportMirrorFailure(string FailCode) /*}}}*/ // AcqSubIndex::AcqSubIndex - Constructor /*{{{*/ // --------------------------------------------------------------------- -/* Get the Index file first and see if there are languages available - * If so, create a pkgAcqIndexTrans for the found language(s). - */ +/* Get a sub-index file based on checksums from a 'master' file and + possibly query additional files */ pkgAcqSubIndex::pkgAcqSubIndex(pkgAcquire *Owner, string const &URI, string const &URIDesc, string const &ShortDesc, HashString const &ExpectedHash) : Item(Owner), ExpectedHash(ExpectedHash) { + /* XXX: Beware: Currently this class does nothing (of value) anymore ! */ Debug = _config->FindB("Debug::pkgAcquire::SubIndex",false); DestFile = _config->FindDir("Dir::State::lists") + "partial/"; @@ -236,17 +236,7 @@ void pkgAcqSubIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /*{{{* Status = StatDone; Dequeue(); - // No good Index is provided, so try guessing - std::vector langs = APT::Configuration::getLanguages(true); - for (std::vector::const_iterator l = langs.begin(); - l != langs.end(); ++l) - { - if (*l == "none") continue; - string const file = "Translation-" + *l; - new pkgAcqIndexTrans(Owner, Desc.URI.substr(0, Desc.URI.rfind('/')+1).append(file), - Desc.Description.erase(Desc.Description.rfind(' ')+1).append(file), - file); - } + // No good Index is provided } /*}}}*/ void pkgAcqSubIndex::Done(string Message,unsigned long long Size,string Md5Hash, /*{{{*/ @@ -305,38 +295,7 @@ bool pkgAcqSubIndex::ParseIndex(string const &IndexFile) /*{{{*/ indexRecords SubIndexParser; if (FileExists(IndexFile) == false || SubIndexParser.Load(IndexFile) == false) return false; - - std::vector lang = APT::Configuration::getLanguages(true); - for (std::vector::const_iterator l = lang.begin(); - l != lang.end(); ++l) - { - if (*l == "none") - continue; - - string file = "Translation-" + *l; - indexRecords::checkSum const *Record = SubIndexParser.Lookup(file); - HashString expected; - if (Record == NULL) - { - // FIXME: the Index file provided by debian currently only includes bz2 records - Record = SubIndexParser.Lookup(file + ".bz2"); - if (Record == NULL) - continue; - } - else - { - expected = Record->Hash; - if (expected.empty() == true) - continue; - } - - IndexTarget target; - target.Description = Desc.Description.erase(Desc.Description.rfind(' ')+1).append(file); - target.MetaKey = file; - target.ShortDesc = file; - target.URI = Desc.URI.substr(0, Desc.URI.rfind('/')+1).append(file); - new pkgAcqIndexTrans(Owner, &target, expected, &SubIndexParser); - } + // so something with the downloaded index return true; } /*}}}*/ @@ -1385,6 +1344,18 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/ return; } #endif + bool transInRelease = false; + { + std::vector const keys = MetaIndexParser->MetaKeys(); + for (std::vector::const_iterator k = keys.begin(); k != keys.end(); ++k) + // FIXME: Feels wrong to check for hardcoded string here, but what should we do else… + if (k->find("Translation-") != std::string::npos) + { + transInRelease = true; + break; + } + } + for (vector ::const_iterator Target = IndexTargets->begin(); Target != IndexTargets->end(); ++Target) @@ -1422,8 +1393,10 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/ if ((*Target)->IsSubIndex() == true) new pkgAcqSubIndex(Owner, (*Target)->URI, (*Target)->Description, (*Target)->ShortDesc, ExpectedIndexHash); - else + else if (transInRelease == false || MetaIndexParser->Exists((*Target)->MetaKey) == true) + { new pkgAcqIndexTrans(Owner, *Target, ExpectedIndexHash, MetaIndexParser); + } continue; } diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 5d3a80aa5..bcc617da7 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -128,7 +128,7 @@ string debReleaseIndex::TranslationIndexURISuffix(const char *Type, const string { string Res =""; if (Dist[Dist.size() - 1] != '/') - Res += Section + "/i18n/"; + Res += Section + "/i18n/Translation-"; return Res + Type; } @@ -210,31 +210,17 @@ vector * debReleaseIndex::ComputeIndexTargets() const { if (lang.empty() == true) return IndexTargets; - // get the Translations: - // - if its a dists-style repository get the i18n/Index first - // - if its flat try to acquire files by guessing - if (Dist[Dist.size() - 1] == '/') { - for (std::set::const_iterator s = sections.begin(); - s != sections.end(); ++s) { - for (std::vector::const_iterator l = lang.begin(); - l != lang.end(); ++l) { - IndexTarget * Target = new OptionalIndexTarget(); - Target->ShortDesc = "Translation-" + *l; - Target->MetaKey = TranslationIndexURISuffix(l->c_str(), *s); - Target->URI = TranslationIndexURI(l->c_str(), *s); - Target->Description = Info (Target->ShortDesc.c_str(), *s); - IndexTargets->push_back(Target); - } - } - } else { - for (std::set::const_iterator s = sections.begin(); - s != sections.end(); ++s) { - IndexTarget * Target = new OptionalSubIndexTarget(); - Target->ShortDesc = "TranslationIndex"; - Target->MetaKey = TranslationIndexURISuffix("Index", *s); - Target->URI = TranslationIndexURI("Index", *s); + // get the Translation-* files, later we will skip download of non-existent if we have an index + for (std::set::const_iterator s = sections.begin(); + s != sections.end(); ++s) { + for (std::vector::const_iterator l = lang.begin(); + l != lang.end(); ++l) { + IndexTarget * Target = new OptionalIndexTarget(); + Target->ShortDesc = "Translation-" + *l; + Target->MetaKey = TranslationIndexURISuffix(l->c_str(), *s); + Target->URI = TranslationIndexURI(l->c_str(), *s); Target->Description = Info (Target->ShortDesc.c_str(), *s); - IndexTargets->push_back (Target); + IndexTargets->push_back(Target); } } -- cgit v1.2.3 From f55602cb0cd7403206752479b2ec11c6367e2f6d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 18 Feb 2012 19:48:04 +0100 Subject: use pdiff for Translation-* files if available (Closes: #657902) Beware: pdiffs for Translation-* are only acquired if their availability is advertised in the Release file. --- apt-pkg/acquire-item.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index ca40b0bd7..4e6fb7ff9 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -1395,7 +1395,12 @@ void pkgAcqMetaIndex::QueueIndexes(bool verify) /*{{{*/ (*Target)->ShortDesc, ExpectedIndexHash); else if (transInRelease == false || MetaIndexParser->Exists((*Target)->MetaKey) == true) { - new pkgAcqIndexTrans(Owner, *Target, ExpectedIndexHash, MetaIndexParser); + if (_config->FindB("Acquire::PDiffs",true) == true && transInRelease == true && + MetaIndexParser->Exists(string((*Target)->MetaKey).append(".diff/Index")) == true) + new pkgAcqDiffIndex(Owner, (*Target)->URI, (*Target)->Description, + (*Target)->ShortDesc, ExpectedIndexHash); + else + new pkgAcqIndexTrans(Owner, *Target, ExpectedIndexHash, MetaIndexParser); } continue; } -- cgit v1.2.3 From b3887af24029cdc6179470fcb8587fff39a3eee9 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 2 Mar 2012 22:01:51 +0100 Subject: * apt-pkg/packagemanager.cc: - when calculating pre-dependencies ensure that both unpack and configure are considered (instead of only configure) LP: #927993 --- apt-pkg/packagemanager.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index a370f15a3..701b64af1 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -611,10 +611,19 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c continue; } - if (Debug) - clog << OutputInDepth(Depth) << "Trying to SmartConfigure " << Pkg.Name() << endl; - Bad = !SmartConfigure(Pkg, Depth + 1); - } + // check if it needs unpack or if if configure is enough + if (!List->IsFlag(Pkg,pkgOrderList::UnPacked)) + { + if (Debug) + clog << OutputInDepth(Depth) << "Trying to SmartUnpack " << Pkg.Name() << endl; + // SmartUnpack with the ImmediateFlag to ensure its really ready + Bad = !SmartUnPack(Pkg, true, Depth + 1); + } else { + if (Debug) + clog << OutputInDepth(Depth) << "Trying to SmartConfigure " << Pkg.Name() << endl; + Bad = !SmartConfigure(Pkg, Depth + 1); + } + } /* If this or element did not match then continue on to the next or element until a matching element is found */ -- cgit v1.2.3 From 6b92f60c38c2d50040bc3f07d52e8da80ef23bff Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 3 Mar 2012 10:02:06 +0100 Subject: eanup the ordering-code avoiding a break (no function change) --- apt-pkg/packagemanager.cc | 51 +++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index a370f15a3..42473341c 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -689,35 +689,30 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c } // Check if it needs to be unpacked - if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false && + if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false && List->IsNow(BrokenPkg)) { - if (List->IsFlag(BrokenPkg,pkgOrderList::Loop) && PkgLoop) { - // This dependancy has already been dealt with by another SmartUnPack on Pkg - break; - } else if (List->IsFlag(Pkg,pkgOrderList::Loop)) { - /* Found a break, so unpack the package, but dont remove loop as already set. - This means that there is another SmartUnPack call for this - package and it will remove the loop flag. */ - if (Debug) - cout << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl; - - SmartUnPack(BrokenPkg, false, Depth + 1); - } else { - List->Flag(Pkg,pkgOrderList::Loop); - // Found a break, so unpack the package - if (Debug) - cout << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.Name() << " to avoid break" << endl; - - SmartUnPack(BrokenPkg, false, Depth + 1); - List->RmFlag(Pkg,pkgOrderList::Loop); - } - } - - // Check if a package needs to be removed - if (Cache[BrokenPkg].Delete() == true && !List->IsFlag(BrokenPkg,pkgOrderList::Configured)) { - if (Debug) - cout << OutputInDepth(Depth) << " Removing " << BrokenPkg.Name() << " to avoid break" << endl; - SmartRemove(BrokenPkg); + if (List->IsFlag(BrokenPkg,pkgOrderList::Loop) && PkgLoop) { + // This dependancy has already been dealt with by another SmartUnPack on Pkg + break; + } else { + // Found a break, so unpack the package, + // but do not set loop if another SmartUnPack already deals with it + if (Debug) + cout << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.Name() << " to avoid " << End << endl; + if (PkgLoop == false) + List->Flag(Pkg,pkgOrderList::Loop); + SmartUnPack(BrokenPkg, false, Depth + 1); + if (PkgLoop == false) + List->RmFlag(Pkg,pkgOrderList::Loop); + } + } else { + // Check if a package needs to be removed + if (Cache[BrokenPkg].Delete() == true && !List->IsFlag(BrokenPkg,pkgOrderList::Configured)) + { + if (Debug) + cout << OutputInDepth(Depth) << " Removing " << BrokenPkg.Name() << " to avoid " << End << endl; + SmartRemove(BrokenPkg); + } } } } -- cgit v1.2.3 From 2264548ff25c3e7f8b6df22fdd59a95b11ad1462 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 3 Mar 2012 10:08:19 +0100 Subject: show in the debug output if we are looping in the avoid breaks --- apt-pkg/packagemanager.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 42473341c..2738a8a6b 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -698,7 +698,12 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c // Found a break, so unpack the package, // but do not set loop if another SmartUnPack already deals with it if (Debug) - cout << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.Name() << " to avoid " << End << endl; + { + cout << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.Name() << " to avoid " << End; + if (PkgLoop == true) + cout << " (Looping)"; + cout << std::endl; + } if (PkgLoop == false) List->Flag(Pkg,pkgOrderList::Loop); SmartUnPack(BrokenPkg, false, Depth + 1); -- cgit v1.2.3 From 440d3d654a5f85e8b5c0472e91f425fbac9541b8 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 3 Mar 2012 11:43:21 +0100 Subject: * apt-pkg/packagemanager.cc: - do not try to a void a breaks if the broken package pre-depends on the breaker, but let dpkg auto-deconfigure it --- apt-pkg/packagemanager.cc | 52 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 12 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 2738a8a6b..05eb1a06b 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -680,7 +680,6 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c { VerIterator Ver(Cache,*I); PkgIterator BrokenPkg = Ver.ParentPkg(); - VerIterator InstallVer(Cache,Cache[BrokenPkg].InstallVer); if (BrokenPkg.CurrentVer() != Ver) { if (Debug) @@ -695,20 +694,49 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c // This dependancy has already been dealt with by another SmartUnPack on Pkg break; } else { - // Found a break, so unpack the package, + // Found a break, so see if we can unpack the package to avoid it // but do not set loop if another SmartUnPack already deals with it - if (Debug) + VerIterator InstallVer(Cache,Cache[BrokenPkg].InstallVer); + bool circle = false; + for (pkgCache::DepIterator D = InstallVer.DependsList(); D.end() == false; ++D) + { + if (D->Type != pkgCache::Dep::PreDepends) + continue; + SPtrArray VL = D.AllTargets(); + for (Version **I = VL; *I != 0; ++I) + { + 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)) + continue; + circle = true; + break; + } + if (circle == true) + break; + } + if (circle == true) + { + if (Debug) + cout << OutputInDepth(Depth) << " Avoiding " << End << " avoided as " << BrokenPkg.FullName() << " has a pre-depends on " << Pkg.FullName() << std::endl; + continue; + } + else { - cout << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.Name() << " to avoid " << End; - if (PkgLoop == true) - cout << " (Looping)"; - cout << std::endl; + if (Debug) + { + cout << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.FullName() << " to avoid " << End; + if (PkgLoop == true) + cout << " (Looping)"; + cout << std::endl; + } + if (PkgLoop == false) + List->Flag(Pkg,pkgOrderList::Loop); + SmartUnPack(BrokenPkg, false, Depth + 1); + if (PkgLoop == false) + List->RmFlag(Pkg,pkgOrderList::Loop); } - if (PkgLoop == false) - List->Flag(Pkg,pkgOrderList::Loop); - SmartUnPack(BrokenPkg, false, Depth + 1); - if (PkgLoop == false) - List->RmFlag(Pkg,pkgOrderList::Loop); } } else { // Check if a package needs to be removed -- cgit v1.2.3 From de498a528cd6fc36c4bb22bf8dec6558e21cc9b6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 4 Mar 2012 22:50:21 +0100 Subject: * apt-pkg/acquire-item.cc: - remove 'old' InRelease file if we can't get a new one before proceeding with Release.gpg to avoid the false impression of a still trusted repository by a (still present) old InRelease file. Thanks to Simon Ruderich for reporting this issue! (CVE-2012-0214) Effected are all versions >= 0.8.11 Possible attack summary: - Attacker needs to find a user which has run at least one successful 'apt-get update' against an archive providing InRelease files. - Create a Packages file with his preferred content. - Attacker then prevents the download of InRelease, Release and Release.gpg (alternatively he creates a valid Release file and sends this, the other two files need to be missing either way). - User updates against this, getting the modified Packages file without any indication of being unsigned (beside the "Ign InRelease" and "Ign Release.gpg" in the output of 'apt-get update'). => deb files from this source are considered 'trusted' (and therefore the user isn't asked for an additional confirmation before install) --- apt-pkg/acquire-item.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 4e6fb7ff9..545a57d37 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -1598,6 +1598,13 @@ void pkgAcqMetaClearSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /* { if (AuthPass == false) { + // Remove the 'old' InRelease file if we try Release.gpg now as otherwise + // the file will stay around and gives a false-auth impression (CVE-2012-0214) + string FinalFile = _config->FindDir("Dir::State::lists"); + FinalFile.append(URItoFileName(RealURI)); + if (FileExists(FinalFile)) + unlink(FinalFile.c_str()); + new pkgAcqMetaSig(Owner, MetaSigURI, MetaSigURIDesc, MetaSigShortDesc, MetaIndexURI, MetaIndexURIDesc, MetaIndexShortDesc, -- cgit v1.2.3 From b1803e01ec18a4946523f3c3d0cbff2f0347ff30 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 4 Mar 2012 23:01:59 +0100 Subject: handle a SIGINT in all modes as a break after the currently running dpkg transaction instead of ignoring it completely --- apt-pkg/deb/dpkgpm.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 499c3db8a..8aea2e1c8 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -860,6 +860,8 @@ static int racy_pselect(int nfds, fd_set *readfds, fd_set *writefds, */ bool pkgDPkgPM::Go(int OutStatusFd) { + pkgPackageManager::SigINTStop = false; + // Generate the base argument list for dpkg std::vector Args; unsigned long StartSize = 0; @@ -1429,9 +1431,8 @@ bool pkgDPkgPM::Go(int OutStatusFd) } void SigINT(int sig) { - if (_config->FindB("APT::Immediate-Configure-All",false)) - pkgPackageManager::SigINTStop = true; -} + pkgPackageManager::SigINTStop = true; +} /*}}}*/ // pkgDpkgPM::Reset - Dump the contents of the command list /*{{{*/ // --------------------------------------------------------------------- -- cgit v1.2.3 From dcaa1185506986142bccd990a5dca4c6ec1228cf Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 4 Mar 2012 23:47:05 +0100 Subject: fix a bunch of cppcheck "(warning) Member variable '<#>' is not initialized in the constructor." messages (no functional change) --- apt-pkg/acquire.cc | 2 +- apt-pkg/algorithms.cc | 2 +- apt-pkg/cachefile.cc | 2 +- apt-pkg/cachefilter.cc | 2 +- apt-pkg/deb/dpkgpm.cc | 4 +++- apt-pkg/orderlist.cc | 14 ++++++-------- apt-pkg/packagemanager.cc | 11 +++++------ apt-pkg/pkgrecords.cc | 2 +- apt-pkg/pkgsystem.cc | 4 ++-- apt-pkg/sourcelist.cc | 2 +- apt-pkg/srcrecords.cc | 2 +- apt-pkg/tagfile.cc | 5 ++++- apt-pkg/version.cc | 4 ++-- 13 files changed, 29 insertions(+), 27 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index cdc3fba4b..573a85c2f 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -766,7 +766,7 @@ void pkgAcquire::Queue::Bump() // AcquireStatus::pkgAcquireStatus - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgAcquireStatus::pkgAcquireStatus() : Update(true), MorePulses(false) +pkgAcquireStatus::pkgAcquireStatus() : d(NULL), Update(true), MorePulses(false) { Start(); } diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index c337ace87..ed3534f0d 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -471,7 +471,7 @@ bool pkgMinimizeUpgrade(pkgDepCache &Cache) // ProblemResolver::pkgProblemResolver - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgProblemResolver::pkgProblemResolver(pkgDepCache *pCache) : Cache(*pCache) +pkgProblemResolver::pkgProblemResolver(pkgDepCache *pCache) : d(NULL), Cache(*pCache) { // Allocate memory unsigned long Size = Cache.Head().PackageCount; diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc index f852542e5..7c2276185 100644 --- a/apt-pkg/cachefile.cc +++ b/apt-pkg/cachefile.cc @@ -30,7 +30,7 @@ // CacheFile::CacheFile - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgCacheFile::pkgCacheFile() : Map(NULL), Cache(NULL), DCache(NULL), +pkgCacheFile::pkgCacheFile() : d(NULL), Map(NULL), Cache(NULL), DCache(NULL), SrcList(NULL), Policy(NULL) { } diff --git a/apt-pkg/cachefilter.cc b/apt-pkg/cachefilter.cc index 210a9a9ab..9ec3fa699 100644 --- a/apt-pkg/cachefilter.cc +++ b/apt-pkg/cachefilter.cc @@ -18,7 +18,7 @@ /*}}}*/ namespace APT { namespace CacheFilter { -PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string const &Pattern) {/*{{{*/ +PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string const &Pattern) : d(NULL) {/*{{{*/ pattern = new regex_t; int const Res = regcomp(pattern, Pattern.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB); if (Res == 0) diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 8aea2e1c8..469132634 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -51,8 +51,10 @@ using namespace std; class pkgDPkgPMPrivate { public: - pkgDPkgPMPrivate() : dpkgbuf_pos(0), term_out(NULL), history_out(NULL) + pkgDPkgPMPrivate() : stdin_is_dev_null(false), dpkgbuf_pos(0), + term_out(NULL), history_out(NULL) { + dpkgbuf[0] = '\0'; } bool stdin_is_dev_null; // the buffer we use for the dpkg status-fd reading diff --git a/apt-pkg/orderlist.cc b/apt-pkg/orderlist.cc index 0ac9a83e3..3a179b2a2 100644 --- a/apt-pkg/orderlist.cc +++ b/apt-pkg/orderlist.cc @@ -82,16 +82,14 @@ pkgOrderList *pkgOrderList::Me = 0; // OrderList::pkgOrderList - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgOrderList::pkgOrderList(pkgDepCache *pCache) : Cache(*pCache) +pkgOrderList::pkgOrderList(pkgDepCache *pCache) : Cache(*pCache), + Primary(NULL), Secondary(NULL), + RevDepends(NULL), Remove(NULL), + AfterEnd(NULL), FileList(NULL), + LoopCount(-1), Depth(0) { - FileList = 0; - Primary = 0; - Secondary = 0; - RevDepends = 0; - Remove = 0; - LoopCount = -1; Debug = _config->FindB("Debug::pkgOrderList",false); - + /* Construct the arrays, egcs 1.0.1 bug requires the package count hack */ unsigned long Size = Cache.Head().PackageCount; diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 05eb1a06b..5b5961aca 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -36,11 +36,13 @@ bool pkgPackageManager::SigINTStop = false; // PM::PackageManager - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgPackageManager::pkgPackageManager(pkgDepCache *pCache) : Cache(*pCache) +pkgPackageManager::pkgPackageManager(pkgDepCache *pCache) : Cache(*pCache), + List(NULL), Res(Incomplete) { FileNames = new string[Cache.Head().PackageCount]; - List = 0; Debug = _config->FindB("Debug::pkgPackageManager",false); + NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true); + ImmConfigureAll = _config->FindB("APT::Immediate-Configure-All",false); } /*}}}*/ // PM::PackageManager - Destructor /*{{{*/ @@ -169,10 +171,7 @@ bool pkgPackageManager::CreateOrderList() delete List; List = new pkgOrderList(&Cache); - - NoImmConfigure = !_config->FindB("APT::Immediate-Configure",true); - ImmConfigureAll = _config->FindB("APT::Immediate-Configure-All",false); - + if (Debug && ImmConfigureAll) clog << "CreateOrderList(): Adding Immediate flag for all packages because of APT::Immediate-Configure-All" << endl; diff --git a/apt-pkg/pkgrecords.cc b/apt-pkg/pkgrecords.cc index c5b3bebd7..36dab3480 100644 --- a/apt-pkg/pkgrecords.cc +++ b/apt-pkg/pkgrecords.cc @@ -22,7 +22,7 @@ // Records::pkgRecords - Constructor /*{{{*/ // --------------------------------------------------------------------- /* This will create the necessary structures to access the status files */ -pkgRecords::pkgRecords(pkgCache &Cache) : Cache(Cache), +pkgRecords::pkgRecords(pkgCache &Cache) : d(NULL), Cache(Cache), Files(Cache.HeaderP->PackageFileCount) { for (pkgCache::PkgFileIterator I = Cache.FileBegin(); diff --git a/apt-pkg/pkgsystem.cc b/apt-pkg/pkgsystem.cc index f61c140fa..05ba6e0e6 100644 --- a/apt-pkg/pkgsystem.cc +++ b/apt-pkg/pkgsystem.cc @@ -26,11 +26,11 @@ unsigned long pkgSystem::GlobalListLen = 0; // System::pkgSystem - Constructor /*{{{*/ // --------------------------------------------------------------------- /* Add it to the global list.. */ -pkgSystem::pkgSystem() +pkgSystem::pkgSystem() : Label(NULL), VS(NULL) { assert(GlobalListLen < sizeof(SysList)/sizeof(*SysList)); SysList[GlobalListLen] = this; - GlobalListLen++; + ++GlobalListLen; } /*}}}*/ // System::GetSystem - Get the named system /*{{{*/ diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index f5f458099..0fddfb451 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -33,7 +33,7 @@ unsigned long pkgSourceList::Type::GlobalListLen = 0; // Type::Type - Constructor /*{{{*/ // --------------------------------------------------------------------- /* Link this to the global list of items*/ -pkgSourceList::Type::Type() +pkgSourceList::Type::Type() : Name(NULL), Label(NULL) { ItmList[GlobalListLen] = this; GlobalListLen++; diff --git a/apt-pkg/srcrecords.cc b/apt-pkg/srcrecords.cc index 48b643eac..d63d2c422 100644 --- a/apt-pkg/srcrecords.cc +++ b/apt-pkg/srcrecords.cc @@ -25,7 +25,7 @@ // SrcRecords::pkgSrcRecords - Constructor /*{{{*/ // --------------------------------------------------------------------- /* Open all the source index files */ -pkgSrcRecords::pkgSrcRecords(pkgSourceList &List) : Files(0), Current(0) +pkgSrcRecords::pkgSrcRecords(pkgSourceList &List) : d(NULL), Files(0), Current(0) { for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); ++I) { diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index ec86173df..79811899a 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -30,7 +30,10 @@ using std::string; class pkgTagFilePrivate { public: - pkgTagFilePrivate(FileFd *pFd, unsigned long long Size) : Fd(*pFd), Size(Size) + pkgTagFilePrivate(FileFd *pFd, unsigned long long Size) : Fd(*pFd), Buffer(NULL), + Start(NULL), End(NULL), + Done(false), iOffset(0), + Size(Size) { } FileFd &Fd; diff --git a/apt-pkg/version.cc b/apt-pkg/version.cc index a9d4fb763..cb2c34c0f 100644 --- a/apt-pkg/version.cc +++ b/apt-pkg/version.cc @@ -23,10 +23,10 @@ unsigned long pkgVersioningSystem::GlobalListLen = 0; // pkgVS::pkgVersioningSystem - Constructor /*{{{*/ // --------------------------------------------------------------------- /* Link to the global list of versioning systems supported */ -pkgVersioningSystem::pkgVersioningSystem() +pkgVersioningSystem::pkgVersioningSystem() : Label(NULL) { VSList[GlobalListLen] = this; - GlobalListLen++; + ++GlobalListLen; } /*}}}*/ // pkgVS::GetVS - Find a VS by name /*{{{*/ -- cgit v1.2.3 From b3c36c6e2f0c78797d1398e3176aac6a48b36295 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 5 Mar 2012 00:25:32 +0100 Subject: set char-limits for the scanf parsing previous crash-reports --- apt-pkg/deb/dpkgpm.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 469132634..c46a81209 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1542,7 +1542,7 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg) if(strstr(strbuf,"Package:") == strbuf) { char pkgname[255], version[255]; - if(sscanf(strbuf, "Package: %s %s", pkgname, version) == 2) + if(sscanf(strbuf, "Package: %254s %254s", pkgname, version) == 2) if(strcmp(pkgver.c_str(), version) == 0) { fclose(report); -- cgit v1.2.3 From 324cbd5693a3cf13224561aa14fc2057d8696469 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 5 Mar 2012 00:37:54 +0100 Subject: as we parse datestrings from external sources a lot specify the length of the integer fields as well to avoid crashes in scanf as cppchecks warns: "(warning) scanf without field width limits can crash with huge input data" --- apt-pkg/contrib/strutl.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 861cdcbeb..99efa8d98 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -910,17 +910,17 @@ bool StrToTime(const string &Val,time_t &Result) // Handle RFC 1123 time Month[0] = 0; - if (sscanf(I," %d %3s %d %d:%d:%d GMT",&Tm.tm_mday,Month,&Tm.tm_year, + if (sscanf(I," %2d %3s %4d %2d:%2d:%2d GMT",&Tm.tm_mday,Month,&Tm.tm_year, &Tm.tm_hour,&Tm.tm_min,&Tm.tm_sec) != 6) { // Handle RFC 1036 time - if (sscanf(I," %d-%3s-%d %d:%d:%d GMT",&Tm.tm_mday,Month, + if (sscanf(I," %2d-%3s-%3d %2d:%2d:%2d GMT",&Tm.tm_mday,Month, &Tm.tm_year,&Tm.tm_hour,&Tm.tm_min,&Tm.tm_sec) == 6) Tm.tm_year += 1900; else { // asctime format - if (sscanf(I," %3s %d %d:%d:%d %d",Month,&Tm.tm_mday, + if (sscanf(I," %3s %2d %2d:%2d:%2d %4d",Month,&Tm.tm_mday, &Tm.tm_hour,&Tm.tm_min,&Tm.tm_sec,&Tm.tm_year) != 6) { // 'ftp' time -- cgit v1.2.3 From 945099df10a67c3c7f52fcfef165a2782e51809e Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 5 Mar 2012 14:57:11 +0100 Subject: * apt-pkg/deb/deblistparser.cc: - Set the Essential flag on APT instead of only Important --- apt-pkg/deb/deblistparser.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index bdb50f6bf..84e6c38c5 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -249,7 +249,7 @@ bool debListParser::UsePackage(pkgCache::PkgIterator &Pkg, return false; if (strcmp(Pkg.Name(),"apt") == 0) - Pkg->Flags |= pkgCache::Flag::Important; + Pkg->Flags |= pkgCache::Flag::Essential | pkgCache::Flag::Important; if (ParseStatus(Pkg,Ver) == false) return false; -- cgit v1.2.3 From fb805d80bfc6027e2242796dbda306e712cfac09 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 5 Mar 2012 15:10:54 +0100 Subject: * apt-pkg/packagemanager.cc: - Do not use immediate configuration for packages with the Important flag --- apt-pkg/packagemanager.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index a370f15a3..4eb539579 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -184,8 +184,7 @@ bool pkgPackageManager::CreateOrderList() continue; // Mark the package and its dependends for immediate configuration - if ((((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential || - (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) && + if ((((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) && NoImmConfigure == false) || ImmConfigureAll) { if(Debug && !ImmConfigureAll) -- cgit v1.2.3 From c520086906f0479d04946f926e3d2dd30df82945 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 5 Mar 2012 15:12:31 +0100 Subject: * Treat the Important flag like the Essential flag with two differences: - No Immediate configuration (see above) - Not automatically installed during dist-upgrade --- apt-pkg/algorithms.cc | 13 +++++++++++-- apt-pkg/depcache.cc | 8 ++++++++ apt-pkg/packagemanager.cc | 6 ++++-- 3 files changed, 23 insertions(+), 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index c337ace87..ef9b5411d 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -556,7 +556,8 @@ void pkgProblemResolver::MakeScores() essantial package above most other packages but low enough to allow an obsolete essential packages to be removed by a conflicts on a powerfull normal package (ie libc6) */ - if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) + if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential + || (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) Score += PrioEssentials; // We transform the priority @@ -631,7 +632,8 @@ void pkgProblemResolver::MakeScores() { if ((Flags[I->ID] & Protected) != 0) Scores[I->ID] += AddProtected; - if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) + if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential || + (I->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) Scores[I->ID] += AddEssential; } } @@ -1430,6 +1432,13 @@ static int PrioComp(const void *A,const void *B) if ((L.ParentPkg()->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential && (R.ParentPkg()->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) return -1; + + if ((L.ParentPkg()->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important && + (R.ParentPkg()->Flags & pkgCache::Flag::Important) != pkgCache::Flag::Important) + return 1; + if ((L.ParentPkg()->Flags & pkgCache::Flag::Important) != pkgCache::Flag::Important && + (R.ParentPkg()->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) + return -1; if (L->Priority != R->Priority) return R->Priority - L->Priority; diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 9449c7306..1eea55560 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -963,6 +963,13 @@ struct CompareProviders { else if ((B->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) return true; } + if ((A->Flags & pkgCache::Flag::Important) != (B->Flags & pkgCache::Flag::Important)) + { + if ((A->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) + return false; + else if ((B->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important) + return true; + } // higher priority seems like a good idea if (AV->Priority != BV->Priority) return AV->Priority < BV->Priority; @@ -1641,6 +1648,7 @@ bool pkgDepCache::MarkRequired(InRootSetFunc &userFunc) { if(!(PkgState[p->ID].Flags & Flag::Auto) || (p->Flags & Flag::Essential) || + (p->Flags & Flag::Important) || userFunc.InRootSet(p) || // be nice even then a required package violates the policy (#583517) // and do the full mark process also for required packages diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 4eb539579..d8e9621a4 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -486,7 +486,8 @@ bool pkgPackageManager::EarlyRemove(PkgIterator Pkg) // Essential packages get special treatment bool IsEssential = false; - if ((Pkg->Flags & pkgCache::Flag::Essential) != 0) + if ((Pkg->Flags & pkgCache::Flag::Essential) != 0 || + (Pkg->Flags & pkgCache::Flag::Important) != 0) IsEssential = true; /* Check for packages that are the dependents of essential packages and @@ -496,7 +497,8 @@ bool pkgPackageManager::EarlyRemove(PkgIterator Pkg) for (DepIterator D = Pkg.RevDependsList(); D.end() == false && IsEssential == false; ++D) if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) - if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0) + if ((D.ParentPkg()->Flags & pkgCache::Flag::Essential) != 0 || + (D.ParentPkg()->Flags & pkgCache::Flag::Important) != 0) IsEssential = true; } -- cgit v1.2.3 From 84e254d6aee034fec6ca10c4e5765d1280d0de0e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 6 Mar 2012 10:53:35 +0100 Subject: * apt-pkg/contrib/fileutl.cc: - do not warn about the ignoring of directories (Closes: #662762) --- apt-pkg/contrib/fileutl.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 557ba0ca6..1808489d7 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -387,6 +387,13 @@ std::vector GetListOfFilesInDir(string const &Dir, std::vector c { if (RealFileExists(File.c_str()) == false) { + // do not show ignoration warnings for directories + if ( +#ifdef _DIRENT_HAVE_D_TYPE + Ent->d_type == DT_DIR || +#endif + DirectoryExists(File.c_str()) == true) + continue; if (SilentIgnore.Match(Ent->d_name) == false) _error->Notice(_("Ignoring '%s' in directory '%s' as it is not a regular file"), Ent->d_name, Dir.c_str()); continue; -- cgit v1.2.3 From de31189fca11b7de937a64de90bcc050b76f9181 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 6 Mar 2012 17:58:16 +0100 Subject: add Debug::pkgAcqArchive::NoQueue to disable package downloading --- apt-pkg/acquire-item.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 545a57d37..a30e98858 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -1810,7 +1810,18 @@ bool pkgAcqArchive::QueueNext() else PartialSize = Buf.st_size; } - + + // Disables download of archives - useful if no real installation follows, + // e.g. if we are just interested in proposed installation order + if (_config->FindB("Debug::pkgAcqArchive::NoQueue", false) == true) + { + Complete = true; + Local = true; + Status = StatDone; + StoreFilename = DestFile = FinalFile; + return true; + } + // Create the item Local = false; Desc.URI = Index->ArchiveURI(PkgFile); -- cgit v1.2.3 From c4f931f8570519323a49f320258e0ae9fb121acb Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 7 Mar 2012 09:20:31 +0100 Subject: * apt-pkg/packagemanager.cc: - fix inconsistent clog/cout usage in the debug output --- apt-pkg/packagemanager.cc | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 382ee4383..48c380be3 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -413,7 +413,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) { List->Flag(Pkg,pkgOrderList::Loop); if (Debug) - cout << OutputInDepth(Depth) << "Unpacking " << DepPkg.Name() << " to avoid loop" << endl; + clog << OutputInDepth(Depth) << "Unpacking " << DepPkg.Name() << " to avoid loop" << endl; SmartUnPack(DepPkg, true, Depth + 1); List->RmFlag(Pkg,pkgOrderList::Loop); } @@ -547,12 +547,12 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c clog << OutputInDepth(Depth) << "SmartUnPack " << Pkg.Name(); VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); if (Pkg.CurrentVer() == 0) - cout << " (install version " << InstallVer.VerStr() << ")"; + clog << " (install version " << InstallVer.VerStr() << ")"; else - cout << " (replace version " << Pkg.CurrentVer().VerStr() << " with " << InstallVer.VerStr() << ")"; + clog << " (replace version " << Pkg.CurrentVer().VerStr() << " with " << InstallVer.VerStr() << ")"; if (PkgLoop) - cout << " (Only Perform PreUnpack Checks)"; - cout << endl; + clog << " (Only Perform PreUnpack Checks)"; + clog << endl; } VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); @@ -655,13 +655,13 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c // See if the current version is conflicting if (ConflictPkg.CurrentVer() == Ver && List->IsNow(ConflictPkg)) { - cout << OutputInDepth(Depth) << Pkg.Name() << " conflicts with " << ConflictPkg.Name() << endl; + clog << OutputInDepth(Depth) << Pkg.Name() << " conflicts with " << ConflictPkg.Name() << endl; /* If a loop is not present or has not yet been detected, attempt to unpack packages to resolve this conflict. If there is a loop present, remove packages to resolve this conflict */ if (!List->IsFlag(ConflictPkg,pkgOrderList::Loop)) { if (Cache[ConflictPkg].Keep() == 0 && Cache[ConflictPkg].InstallVer != 0) { if (Debug) - cout << OutputInDepth(Depth) << OutputInDepth(Depth) << "Unpacking " << ConflictPkg.Name() << " to prevent conflict" << endl; + clog << OutputInDepth(Depth) << OutputInDepth(Depth) << "Unpacking " << ConflictPkg.Name() << " to prevent conflict" << endl; List->Flag(Pkg,pkgOrderList::Loop); SmartUnPack(ConflictPkg,false, Depth + 1); // Remove loop to allow it to be used later if needed @@ -673,7 +673,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c } else { if (!List->IsFlag(ConflictPkg,pkgOrderList::Removed)) { if (Debug) - cout << OutputInDepth(Depth) << "Because of conficts knot, removing " << ConflictPkg.Name() << " to conflict violation" << endl; + clog << OutputInDepth(Depth) << "Because of conficts knot, removing " << ConflictPkg.Name() << " to conflict violation" << endl; if (EarlyRemove(ConflictPkg) == false) return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name()); } @@ -728,17 +728,17 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c if (circle == true) { if (Debug) - cout << OutputInDepth(Depth) << " Avoiding " << End << " avoided as " << BrokenPkg.FullName() << " has a pre-depends on " << Pkg.FullName() << std::endl; + clog << OutputInDepth(Depth) << " Avoiding " << End << " avoided as " << BrokenPkg.FullName() << " has a pre-depends on " << Pkg.FullName() << std::endl; continue; } else { if (Debug) { - cout << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.FullName() << " to avoid " << End; + clog << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.FullName() << " to avoid " << End; if (PkgLoop == true) - cout << " (Looping)"; - cout << std::endl; + clog << " (Looping)"; + clog << std::endl; } if (PkgLoop == false) List->Flag(Pkg,pkgOrderList::Loop); @@ -752,7 +752,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c if (Cache[BrokenPkg].Delete() == true && !List->IsFlag(BrokenPkg,pkgOrderList::Configured)) { if (Debug) - cout << OutputInDepth(Depth) << " Removing " << BrokenPkg.Name() << " to avoid " << End << endl; + clog << OutputInDepth(Depth) << " Removing " << BrokenPkg.Name() << " to avoid " << End << endl; SmartRemove(BrokenPkg); } } -- cgit v1.2.3 From 796848567bafde162c2f7fa293e35f3aa1b70459 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 7 Mar 2012 11:16:58 +0100 Subject: show which dependency couldn't be satisfied in the debug output --- 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 382ee4383..feddc3bf8 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -422,7 +422,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) if (Start==End) { if (Bad && Debug && List->IsFlag(DepPkg,pkgOrderList::Loop) == false) - std::clog << OutputInDepth(Depth) << "Could not satisfy dependencies for " << Pkg.Name() << std::endl; + std::clog << OutputInDepth(Depth) << "Could not satisfy " << Start << std::endl; break; } else { Start++; -- cgit v1.2.3 From 90436124e1957f685673f0926a3cd8edc6d2fcdf Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 12 Mar 2012 19:30:48 +0100 Subject: ensure that the fullname of a package is displayed in the debug output --- apt-pkg/packagemanager.cc | 58 +++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index feddc3bf8..eff92738f 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -152,7 +152,7 @@ void pkgPackageManager::ImmediateAdd(PkgIterator I, bool UseInstallVer, unsigned if(!List->IsFlag(D.TargetPkg(), pkgOrderList::Immediate)) { if(Debug) - clog << OutputInDepth(Depth) << "ImmediateAdd(): Adding Immediate flag to " << D.TargetPkg() << " cause of " << D.DepType() << " " << I.Name() << endl; + clog << OutputInDepth(Depth) << "ImmediateAdd(): Adding Immediate flag to " << D.TargetPkg() << " cause of " << D.DepType() << " " << I.FullName() << endl; List->Flag(D.TargetPkg(),pkgOrderList::Immediate); ImmediateAdd(D.TargetPkg(), UseInstallVer, Depth + 1); } @@ -187,7 +187,7 @@ bool pkgPackageManager::CreateOrderList() NoImmConfigure == false) || ImmConfigureAll) { if(Debug && !ImmConfigureAll) - clog << "CreateOrderList(): Adding Immediate flag for " << I.Name() << endl; + clog << "CreateOrderList(): Adding Immediate flag for " << I.FullName() << endl; List->Flag(I,pkgOrderList::Immediate); if (!ImmConfigureAll) { @@ -256,7 +256,7 @@ bool pkgPackageManager::CheckRConflicts(PkgIterator Pkg,DepIterator D, if (EarlyRemove(D.ParentPkg()) == false) return _error->Error("Reverse conflicts early remove for package '%s' failed", - Pkg.Name()); + Pkg.FullName().c_str()); } return true; } @@ -294,9 +294,9 @@ bool pkgPackageManager::ConfigureAll() if (ConfigurePkgs == true && SmartConfigure(Pkg, 0) == false) { if (ImmConfigureAll) _error->Error(_("Could not perform immediate configuration on '%s'. " - "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),1); + "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.FullName().c_str(),1); else - _error->Error("Internal error, packages left unconfigured. %s",Pkg.Name()); + _error->Error("Internal error, packages left unconfigured. %s",Pkg.FullName().c_str()); return false; } @@ -325,7 +325,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) if (Debug) { VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); - clog << OutputInDepth(Depth) << "SmartConfigure " << Pkg.Name() << " (" << InstallVer.VerStr() << ")"; + clog << OutputInDepth(Depth) << "SmartConfigure " << Pkg.FullName() << " (" << InstallVer.VerStr() << ")"; if (PkgLoop) clog << " (Only Correct Dependencies)"; clog << endl; @@ -413,7 +413,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) { List->Flag(Pkg,pkgOrderList::Loop); if (Debug) - cout << OutputInDepth(Depth) << "Unpacking " << DepPkg.Name() << " to avoid loop" << endl; + cout << OutputInDepth(Depth) << "Unpacking " << DepPkg.FullName() << " to avoid loop" << endl; SmartUnPack(DepPkg, true, Depth + 1); List->RmFlag(Pkg,pkgOrderList::Loop); } @@ -432,7 +432,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) if (Bad) { if (Debug) - _error->Warning(_("Could not configure '%s'. "),Pkg.Name()); + _error->Warning(_("Could not configure '%s'. "),Pkg.FullName().c_str()); return false; } @@ -442,7 +442,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) static bool const ConfigurePkgs = (conf == "all" || conf == "smart"); if (List->IsFlag(Pkg,pkgOrderList::Configured)) - return _error->Error("Internal configure error on '%s'.", Pkg.Name()); + return _error->Error("Internal configure error on '%s'.", Pkg.FullName().c_str()); if (ConfigurePkgs == true && Configure(Pkg) == false) return false; @@ -462,7 +462,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) // Sanity Check if (List->IsFlag(Pkg,pkgOrderList::Configured) == false) - return _error->Error(_("Could not configure '%s'. "),Pkg.Name()); + return _error->Error(_("Could not configure '%s'. "),Pkg.FullName().c_str()); return true; } @@ -508,7 +508,7 @@ bool pkgPackageManager::EarlyRemove(PkgIterator Pkg) "removing the essential package %s due to a " "Conflicts/Pre-Depends loop. This is often bad, " "but if you really want to do it, activate the " - "APT::Force-LoopBreak option."),Pkg.Name()); + "APT::Force-LoopBreak option."),Pkg.FullName().c_str()); } bool Res = SmartRemove(Pkg); @@ -544,7 +544,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop); if (Debug) { - clog << OutputInDepth(Depth) << "SmartUnPack " << Pkg.Name(); + clog << OutputInDepth(Depth) << "SmartUnPack " << Pkg.FullName(); VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); if (Pkg.CurrentVer() == 0) cout << " (install version " << InstallVer.VerStr() << ")"; @@ -574,7 +574,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c while (End->Type == pkgCache::Dep::PreDepends) { if (Debug) - clog << OutputInDepth(Depth) << "PreDepends order for " << Pkg.Name() << std::endl; + clog << OutputInDepth(Depth) << "PreDepends order for " << Pkg.FullName() << std::endl; // Look for possible ok targets. SPtrArray VList = Start.AllTargets(); @@ -590,7 +590,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c { Bad = false; if (Debug) - clog << OutputInDepth(Depth) << "Found ok package " << Pkg.Name() << endl; + clog << OutputInDepth(Depth) << "Found ok package " << Pkg.FullName() << endl; continue; } } @@ -615,12 +615,12 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c if (!List->IsFlag(Pkg,pkgOrderList::UnPacked)) { if (Debug) - clog << OutputInDepth(Depth) << "Trying to SmartUnpack " << Pkg.Name() << endl; + clog << OutputInDepth(Depth) << "Trying to SmartUnpack " << Pkg.FullName() << endl; // SmartUnpack with the ImmediateFlag to ensure its really ready Bad = !SmartUnPack(Pkg, true, Depth + 1); } else { if (Debug) - clog << OutputInDepth(Depth) << "Trying to SmartConfigure " << Pkg.Name() << endl; + clog << OutputInDepth(Depth) << "Trying to SmartConfigure " << Pkg.FullName() << endl; Bad = !SmartConfigure(Pkg, Depth + 1); } } @@ -633,7 +633,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c if (Start == End) return _error->Error("Couldn't configure pre-depend %s for %s, " "probably a dependency cycle.", - End.TargetPkg().Name(),Pkg.Name()); + End.TargetPkg().FullName().c_str(),Pkg.FullName().c_str()); ++Start; } else @@ -655,27 +655,27 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c // See if the current version is conflicting if (ConflictPkg.CurrentVer() == Ver && List->IsNow(ConflictPkg)) { - cout << OutputInDepth(Depth) << Pkg.Name() << " conflicts with " << ConflictPkg.Name() << endl; + cout << OutputInDepth(Depth) << Pkg.FullName() << " conflicts with " << ConflictPkg.FullName() << endl; /* If a loop is not present or has not yet been detected, attempt to unpack packages to resolve this conflict. If there is a loop present, remove packages to resolve this conflict */ if (!List->IsFlag(ConflictPkg,pkgOrderList::Loop)) { if (Cache[ConflictPkg].Keep() == 0 && Cache[ConflictPkg].InstallVer != 0) { if (Debug) - cout << OutputInDepth(Depth) << OutputInDepth(Depth) << "Unpacking " << ConflictPkg.Name() << " to prevent conflict" << endl; + cout << OutputInDepth(Depth) << OutputInDepth(Depth) << "Unpacking " << ConflictPkg.FullName() << " to prevent conflict" << endl; List->Flag(Pkg,pkgOrderList::Loop); SmartUnPack(ConflictPkg,false, Depth + 1); // Remove loop to allow it to be used later if needed List->RmFlag(Pkg,pkgOrderList::Loop); } else { if (EarlyRemove(ConflictPkg) == false) - return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name()); + return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.FullName().c_str()); } } else { if (!List->IsFlag(ConflictPkg,pkgOrderList::Removed)) { if (Debug) - cout << OutputInDepth(Depth) << "Because of conficts knot, removing " << ConflictPkg.Name() << " to conflict violation" << endl; + cout << OutputInDepth(Depth) << "Because of conficts knot, removing " << ConflictPkg.FullName() << " to conflict violation" << endl; if (EarlyRemove(ConflictPkg) == false) - return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.Name()); + return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.FullName().c_str()); } } } @@ -752,7 +752,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c if (Cache[BrokenPkg].Delete() == true && !List->IsFlag(BrokenPkg,pkgOrderList::Configured)) { if (Debug) - cout << OutputInDepth(Depth) << " Removing " << BrokenPkg.Name() << " to avoid " << End << endl; + cout << OutputInDepth(Depth) << " Removing " << BrokenPkg.FullName() << " to avoid " << End << endl; SmartRemove(BrokenPkg); } } @@ -815,7 +815,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c // Perform immedate configuration of the package. if (SmartConfigure(Pkg, Depth + 1) == false) _error->Warning(_("Could not perform immediate configuration on '%s'. " - "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),2); + "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.FullName().c_str(),2); } return true; @@ -855,11 +855,11 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() { if (!List->IsFlag(Pkg,pkgOrderList::Configured) && !NoImmConfigure) { if (SmartConfigure(Pkg, 0) == false && Debug) - _error->Warning("Internal Error, Could not configure %s",Pkg.Name()); + _error->Warning("Internal Error, Could not configure %s",Pkg.FullName().c_str()); // FIXME: The above warning message might need changing } else { if (Debug == true) - clog << "Skipping already done " << Pkg.Name() << endl; + clog << "Skipping already done " << Pkg.FullName() << endl; } continue; @@ -868,7 +868,7 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() if (List->IsMissing(Pkg) == true) { if (Debug == true) - clog << "Sequence completed at " << Pkg.Name() << endl; + clog << "Sequence completed at " << Pkg.FullName() << endl; if (DoneSomething == false) { _error->Error("Internal Error, ordering was unable to handle the media swap"); @@ -882,7 +882,7 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() Pkg.State() == pkgCache::PkgIterator::NeedsNothing && (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall) { - _error->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg.Name()); + _error->Error("Internal Error, trying to manipulate a kept package (%s)",Pkg.FullName().c_str()); return Failed; } @@ -915,7 +915,7 @@ pkgPackageManager::OrderResult pkgPackageManager::OrderInstall() if (List->IsFlag(*I,pkgOrderList::Configured) == false) { _error->Error("Internal error, packages left unconfigured. %s", - PkgIterator(Cache,*I).Name()); + PkgIterator(Cache,*I).FullName().c_str()); return Failed; } } -- cgit v1.2.3 From 2dd2c801ba4bbd2c57bc0f6fe590e11c16f46822 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 13 Mar 2012 11:37:15 +0100 Subject: * apt-pkg/packagemanager.cc: - recheck all dependencies if we changed a package in SmartConfigure as this could break an earlier dependency (LP: #940396) --- apt-pkg/packagemanager.cc | 190 +++++++++++++++++++++++++++------------------- 1 file changed, 111 insertions(+), 79 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index eff92738f..5ba1225a0 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -321,7 +321,7 @@ bool pkgPackageManager::ConfigureAll() bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) { // If this is true, only check and correct and dependencies without the Loop flag - bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop); + bool const PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop); if (Debug) { VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); @@ -336,99 +336,131 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) /* Because of the ordered list, most dependencies should be unpacked, however if there is a loop (A depends on B, B depends on A) this will not be the case, so check for dependencies before configuring. */ - bool Bad = false; - for (DepIterator D = instVer.DependsList(); - D.end() == false; ) - { - // Compute a single dependency element (glob or) - pkgCache::DepIterator Start; - pkgCache::DepIterator End; - D.GlobOr(Start,End); - - if (End->Type == pkgCache::Dep::Depends) - Bad = true; - - // Check for dependanices that have not been unpacked, probably due to loops. - while (End->Type == pkgCache::Dep::Depends) { - PkgIterator DepPkg; - VerIterator InstallVer; - SPtrArray VList = Start.AllTargets(); - - // Check through each version of each package that could satisfy this dependancy - for (Version **I = VList; *I != 0; I++) { - VerIterator Ver(Cache,*I); - DepPkg = Ver.ParentPkg(); - InstallVer = VerIterator(Cache,Cache[DepPkg].InstallVer); + bool Bad = false, Changed = false; + do { + Changed = false; + for (DepIterator D = instVer.DependsList(); D.end() == false; ) + { + // Compute a single dependency element (glob or) + pkgCache::DepIterator Start, End; + D.GlobOr(Start,End); + + if (End->Type != pkgCache::Dep::Depends) + continue; + Bad = true; + + // Search for dependencies which are unpacked but aren't configured yet (maybe loops) + for (DepIterator Cur = Start; true; ++Cur) + { + SPtrArray VList = Cur.AllTargets(); - // Check if the current version of the package is avalible and will satisfy this dependancy - if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true && - !List->IsFlag(DepPkg,pkgOrderList::Removed) && DepPkg.State() == PkgIterator::NeedsNothing) + for (Version **I = VList; *I != 0; ++I) { - Bad = false; - break; - } - - // Check if the version that is going to be installed will satisfy the dependancy - if (Cache[DepPkg].InstallVer == *I) { - if (List->IsFlag(DepPkg,pkgOrderList::UnPacked)) { - if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop) { - // This dependancy has already been dealt with by another SmartConfigure on Pkg - Bad = false; - break; - } else if (List->IsFlag(Pkg,pkgOrderList::Loop)) { - /* Check for a loop to prevent one forming - If A depends on B and B depends on A, SmartConfigure will - just hop between them if this is not checked. Dont remove the - loop flag after finishing however as loop is already set. - This means that there is another SmartConfigure call for this - package and it will remove the loop flag */ - Bad = !SmartConfigure(DepPkg, Depth + 1); - } else { - /* Check for a loop to prevent one forming - If A depends on B and B depends on A, SmartConfigure will - just hop between them if this is not checked */ - List->Flag(Pkg,pkgOrderList::Loop); - Bad = !SmartConfigure(DepPkg, Depth + 1); - List->RmFlag(Pkg,pkgOrderList::Loop); - } - // If SmartConfigure was succesfull, Bad is false, so break - if (!Bad) break; - } else if (List->IsFlag(DepPkg,pkgOrderList::Configured)) { - Bad = false; - break; + VerIterator Ver(Cache,*I); + PkgIterator DepPkg = Ver.ParentPkg(); + + // Check if the current version of the package is available and will satisfy this dependency + if (DepPkg.CurrentVer() == Ver && List->IsNow(DepPkg) == true && + List->IsFlag(DepPkg,pkgOrderList::Removed) == false && + DepPkg.State() == PkgIterator::NeedsNothing) + { + Bad = false; + break; + } + + // Check if the version that is going to be installed will satisfy the dependency + if (Cache[DepPkg].InstallVer != *I) + continue; + + if (List->IsFlag(DepPkg,pkgOrderList::UnPacked)) + { + if (List->IsFlag(DepPkg,pkgOrderList::Loop) && PkgLoop) + { + // This dependency has already been dealt with by another SmartConfigure on Pkg + Bad = false; + break; + } + /* Check for a loop to prevent one forming + If A depends on B and B depends on A, SmartConfigure will + just hop between them if this is not checked. Dont remove the + loop flag after finishing however as loop is already set. + This means that there is another SmartConfigure call for this + package and it will remove the loop flag */ + if (PkgLoop == false) + List->Flag(Pkg,pkgOrderList::Loop); + if (SmartConfigure(DepPkg, Depth + 1) == true) + { + Bad = false; + if (List->IsFlag(DepPkg,pkgOrderList::Loop) == false) + Changed = true; + } + if (PkgLoop == false) + List->RmFlag(Pkg,pkgOrderList::Loop); + // If SmartConfigure was succesfull, Bad is false, so break + if (Bad == false) + break; + } + else if (List->IsFlag(DepPkg,pkgOrderList::Configured)) + { + Bad = false; + break; } } - } - - /* If the dependany is still not satisfied, try, if possible, unpacking a package to satisfy it */ - if (InstallVer != 0 && Bad) { - if (List->IsNow(DepPkg)) { - Bad = false; - if (List->IsFlag(Pkg,pkgOrderList::Loop)) + if (Cur == End) + break; + } + + if (Bad == false) + continue; + + // Check for dependencies that have not been unpacked, probably due to loops. + for (DepIterator Cur = Start; true; ++Cur) + { + SPtrArray VList = Cur.AllTargets(); + + for (Version **I = VList; *I != 0; ++I) + { + VerIterator Ver(Cache,*I); + PkgIterator DepPkg = Ver.ParentPkg(); + + // Check if the version that is going to be installed will satisfy the dependency + if (Cache[DepPkg].InstallVer != *I || List->IsNow(DepPkg) == false) + continue; + + if (PkgLoop == true) { if (Debug) std::clog << OutputInDepth(Depth) << "Package " << Pkg << " loops in SmartConfigure" << std::endl; + Bad = false; + break; } else { - List->Flag(Pkg,pkgOrderList::Loop); if (Debug) - cout << OutputInDepth(Depth) << "Unpacking " << DepPkg.FullName() << " to avoid loop" << endl; - SmartUnPack(DepPkg, true, Depth + 1); - List->RmFlag(Pkg,pkgOrderList::Loop); + cout << OutputInDepth(Depth) << "Unpacking " << DepPkg.FullName() << " to avoid loop " << Cur << endl; + if (PkgLoop == false) + List->Flag(Pkg,pkgOrderList::Loop); + if (SmartUnPack(DepPkg, true, Depth + 1) == true) + { + Bad = false; + if (List->IsFlag(DepPkg,pkgOrderList::Loop) == false) + Changed = true; + } + if (PkgLoop == false) + List->RmFlag(Pkg,pkgOrderList::Loop); + if (Bad == false) + break; } } + + if (Cur == End) + break; } - - if (Start==End) { - if (Bad && Debug && List->IsFlag(DepPkg,pkgOrderList::Loop) == false) - std::clog << OutputInDepth(Depth) << "Could not satisfy " << Start << std::endl; - break; - } else { - Start++; - } + + if (Bad == true && Changed == false && Debug == true) + std::clog << OutputInDepth(Depth) << "Could not satisfy " << Start << std::endl; } - } + } while (Changed == true); if (Bad) { if (Debug) -- cgit v1.2.3 From 98ee49227a1f1669306cbfc1b15c5243ed13cc8a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 13 Mar 2012 12:39:05 +0100 Subject: recheck dependencies in SmartUnpack after a change, too --- apt-pkg/packagemanager.cc | 361 +++++++++++++++++++++++++--------------------- 1 file changed, 196 insertions(+), 165 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 5ba1225a0..73637d071 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -590,198 +590,229 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); /* PreUnpack Checks: This loop checks and attempts to rectify and problems that would prevent the package being unpacked. - It addresses: PreDepends, Conflicts, Obsoletes and Breaks (DpkgBreaks). Any resolutions that do not require it should + It addresses: PreDepends, Conflicts, Obsoletes and Breaks (DpkgBreaks). Any resolutions that do not require it should avoid configuration (calling SmartUnpack with Immediate=true), this is because when unpacking some packages with - complex dependancy structures, trying to configure some packages while breaking the loops can complicate things . - This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured), + complex dependancy structures, trying to configure some packages while breaking the loops can complicate things . + This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured), or by the ConfigureAll call at the end of the for loop in OrderInstall. */ - for (DepIterator D = instVer.DependsList(); - D.end() == false; ) - { - // Compute a single dependency element (glob or) - pkgCache::DepIterator Start; - pkgCache::DepIterator End; - D.GlobOr(Start,End); - - while (End->Type == pkgCache::Dep::PreDepends) + bool Changed = false; + do { + Changed = false; + for (DepIterator D = instVer.DependsList(); D.end() == false; ) { - if (Debug) - clog << OutputInDepth(Depth) << "PreDepends order for " << Pkg.FullName() << std::endl; + // Compute a single dependency element (glob or) + pkgCache::DepIterator Start, End; + D.GlobOr(Start,End); - // Look for possible ok targets. - SPtrArray VList = Start.AllTargets(); - bool Bad = true; - for (Version **I = VList; *I != 0 && Bad == true; I++) - { - VerIterator Ver(Cache,*I); - PkgIterator Pkg = Ver.ParentPkg(); - - // See if the current version is ok - if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true && - Pkg.State() == PkgIterator::NeedsNothing) + if (End->Type == pkgCache::Dep::PreDepends) + { + bool Bad = true; + if (Debug) + clog << OutputInDepth(Depth) << "PreDepends order for " << Pkg.FullName() << std::endl; + + // Look for easy targets: packages that are already okay + for (DepIterator Cur = Start; Bad == true; ++Cur) { - Bad = false; - if (Debug) - clog << OutputInDepth(Depth) << "Found ok package " << Pkg.FullName() << endl; - continue; - } - } - - // Look for something that could be configured. - for (Version **I = VList; *I != 0 && Bad == true; I++) - { - VerIterator Ver(Cache,*I); - PkgIterator Pkg = Ver.ParentPkg(); - - // Not the install version - if (Cache[Pkg].InstallVer != *I || - (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)) - continue; - - if (List->IsFlag(Pkg,pkgOrderList::Configured)) { - Bad = false; - continue; + SPtrArray VList = Start.AllTargets(); + for (Version **I = VList; *I != 0; ++I) + { + VerIterator Ver(Cache,*I); + PkgIterator Pkg = Ver.ParentPkg(); + + // See if the current version is ok + if (Pkg.CurrentVer() == Ver && List->IsNow(Pkg) == true && + Pkg.State() == PkgIterator::NeedsNothing) + { + Bad = false; + if (Debug) + clog << OutputInDepth(Depth) << "Found ok package " << Pkg.FullName() << endl; + break; + } + } + if (Cur == End) + break; } - // check if it needs unpack or if if configure is enough - if (!List->IsFlag(Pkg,pkgOrderList::UnPacked)) - { - if (Debug) - clog << OutputInDepth(Depth) << "Trying to SmartUnpack " << Pkg.FullName() << endl; - // SmartUnpack with the ImmediateFlag to ensure its really ready - Bad = !SmartUnPack(Pkg, true, Depth + 1); - } else { - if (Debug) - clog << OutputInDepth(Depth) << "Trying to SmartConfigure " << Pkg.FullName() << endl; - Bad = !SmartConfigure(Pkg, Depth + 1); - } - } + // Look for something that could be configured. + for (DepIterator Cur = Start; Bad == true; ++Cur) + { + SPtrArray VList = Start.AllTargets(); + for (Version **I = VList; *I != 0; ++I) + { + VerIterator Ver(Cache,*I); + PkgIterator Pkg = Ver.ParentPkg(); - /* If this or element did not match then continue on to the - next or element until a matching element is found */ - if (Bad == true) - { - // This triggers if someone make a pre-depends/depend loop. - if (Start == End) - return _error->Error("Couldn't configure pre-depend %s for %s, " - "probably a dependency cycle.", - End.TargetPkg().FullName().c_str(),Pkg.FullName().c_str()); - ++Start; - } - else - break; - } - - if (End->Type == pkgCache::Dep::Conflicts || - End->Type == pkgCache::Dep::Obsoletes) - { - /* Look for conflicts. Two packages that are both in the install - state cannot conflict so we don't check.. */ - SPtrArray VList = End.AllTargets(); - for (Version **I = VList; *I != 0; I++) - { - VerIterator Ver(Cache,*I); - PkgIterator ConflictPkg = Ver.ParentPkg(); - VerIterator InstallVer(Cache,Cache[ConflictPkg].InstallVer); - - // See if the current version is conflicting - if (ConflictPkg.CurrentVer() == Ver && List->IsNow(ConflictPkg)) - { - cout << OutputInDepth(Depth) << Pkg.FullName() << " conflicts with " << ConflictPkg.FullName() << endl; - /* If a loop is not present or has not yet been detected, attempt to unpack packages - to resolve this conflict. If there is a loop present, remove packages to resolve this conflict */ - if (!List->IsFlag(ConflictPkg,pkgOrderList::Loop)) { - if (Cache[ConflictPkg].Keep() == 0 && Cache[ConflictPkg].InstallVer != 0) { - if (Debug) - cout << OutputInDepth(Depth) << OutputInDepth(Depth) << "Unpacking " << ConflictPkg.FullName() << " to prevent conflict" << endl; - List->Flag(Pkg,pkgOrderList::Loop); - SmartUnPack(ConflictPkg,false, Depth + 1); - // Remove loop to allow it to be used later if needed - List->RmFlag(Pkg,pkgOrderList::Loop); - } else { - if (EarlyRemove(ConflictPkg) == false) - return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.FullName().c_str()); - } - } else { - if (!List->IsFlag(ConflictPkg,pkgOrderList::Removed)) { - if (Debug) - cout << OutputInDepth(Depth) << "Because of conficts knot, removing " << ConflictPkg.FullName() << " to conflict violation" << endl; - if (EarlyRemove(ConflictPkg) == false) - return _error->Error("Internal Error, Could not early remove %s",ConflictPkg.FullName().c_str()); - } + // Not the install version + if (Cache[Pkg].InstallVer != *I || + (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing)) + continue; + + if (List->IsFlag(Pkg,pkgOrderList::Configured)) + { + Bad = false; + break; + } + + // check if it needs unpack or if if configure is enough + if (List->IsFlag(Pkg,pkgOrderList::UnPacked) == false) + { + if (Debug) + clog << OutputInDepth(Depth) << "Trying to SmartUnpack " << Pkg.FullName() << endl; + // SmartUnpack with the ImmediateFlag to ensure its really ready + if (SmartUnPack(Pkg, true, Depth + 1) == true) + { + Bad = false; + if (List->IsFlag(Pkg,pkgOrderList::Loop) == false) + Changed = true; + break; + } + } + else + { + if (Debug) + clog << OutputInDepth(Depth) << "Trying to SmartConfigure " << Pkg.FullName() << endl; + if (SmartConfigure(Pkg, Depth + 1) == true) + { + Bad = false; + if (List->IsFlag(Pkg,pkgOrderList::Loop) == false) + Changed = true; + break; + } + } } } + + if (Bad == true) + { + if (Start == End) + return _error->Error("Couldn't configure pre-depend %s for %s, " + "probably a dependency cycle.", + End.TargetPkg().FullName().c_str(),Pkg.FullName().c_str()); + } + else + continue; } - } - - // Check for breaks - if (End->Type == pkgCache::Dep::DpkgBreaks) { - SPtrArray VList = End.AllTargets(); - for (Version **I = VList; *I != 0; I++) + else if (End->Type == pkgCache::Dep::Conflicts || + End->Type == pkgCache::Dep::Obsoletes) { - VerIterator Ver(Cache,*I); - PkgIterator BrokenPkg = Ver.ParentPkg(); - if (BrokenPkg.CurrentVer() != Ver) + /* Look for conflicts. Two packages that are both in the install + state cannot conflict so we don't check.. */ + SPtrArray VList = End.AllTargets(); + for (Version **I = VList; *I != 0; I++) { - if (Debug) - std::clog << OutputInDepth(Depth) << " Ignore not-installed version " << Ver.VerStr() << " of " << Pkg.FullName() << " for " << End << std::endl; - continue; - } + VerIterator Ver(Cache,*I); + PkgIterator ConflictPkg = Ver.ParentPkg(); + VerIterator InstallVer(Cache,Cache[ConflictPkg].InstallVer); - // Check if it needs to be unpacked - if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false && - List->IsNow(BrokenPkg)) { - if (List->IsFlag(BrokenPkg,pkgOrderList::Loop) && PkgLoop) { - // This dependancy has already been dealt with by another SmartUnPack on Pkg - break; - } else { - // Found a break, so see if we can unpack the package to avoid it - // but do not set loop if another SmartUnPack already deals with it - VerIterator InstallVer(Cache,Cache[BrokenPkg].InstallVer); - bool circle = false; - for (pkgCache::DepIterator D = InstallVer.DependsList(); D.end() == false; ++D) + // See if the current version is conflicting + if (ConflictPkg.CurrentVer() == Ver && List->IsNow(ConflictPkg)) + { + cout << OutputInDepth(Depth) << Pkg.FullName() << " conflicts with " << ConflictPkg.FullName() << endl; + /* If a loop is not present or has not yet been detected, attempt to unpack packages + to resolve this conflict. If there is a loop present, remove packages to resolve this conflict */ + if (List->IsFlag(ConflictPkg,pkgOrderList::Loop) == false) { - if (D->Type != pkgCache::Dep::PreDepends) - continue; - SPtrArray VL = D.AllTargets(); - for (Version **I = VL; *I != 0; ++I) + if (Cache[ConflictPkg].Keep() == 0 && Cache[ConflictPkg].InstallVer != 0) { - 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)) - continue; - circle = true; - break; + if (Debug) + cout << OutputInDepth(Depth) << OutputInDepth(Depth) << "Unpacking " << ConflictPkg.FullName() << " to prevent conflict" << endl; + List->Flag(Pkg,pkgOrderList::Loop); + if (SmartUnPack(ConflictPkg,false, Depth + 1) == true) + if (List->IsFlag(ConflictPkg,pkgOrderList::Loop) == false) + Changed = true; + // Remove loop to allow it to be used later if needed + List->RmFlag(Pkg,pkgOrderList::Loop); } - if (circle == true) - break; + else if (EarlyRemove(ConflictPkg) == false) + return _error->Error("Internal Error, Could not early remove %s (1)",ConflictPkg.FullName().c_str()); } - if (circle == true) + else if (List->IsFlag(ConflictPkg,pkgOrderList::Removed) == false) { if (Debug) - cout << OutputInDepth(Depth) << " Avoiding " << End << " avoided as " << BrokenPkg.FullName() << " has a pre-depends on " << Pkg.FullName() << std::endl; - continue; + cout << OutputInDepth(Depth) << "Because of conficts knot, removing " << ConflictPkg.FullName() << " to conflict violation" << endl; + if (EarlyRemove(ConflictPkg) == false) + return _error->Error("Internal Error, Could not early remove %s (2)",ConflictPkg.FullName().c_str()); + } + } + } + } + else if (End->Type == pkgCache::Dep::DpkgBreaks) + { + SPtrArray VList = End.AllTargets(); + for (Version **I = VList; *I != 0; ++I) + { + VerIterator Ver(Cache,*I); + PkgIterator BrokenPkg = Ver.ParentPkg(); + if (BrokenPkg.CurrentVer() != Ver) + { + if (Debug) + std::clog << OutputInDepth(Depth) << " Ignore not-installed version " << Ver.VerStr() << " of " << Pkg.FullName() << " for " << End << std::endl; + continue; + } + + // Check if it needs to be unpacked + if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false && + List->IsNow(BrokenPkg)) + { + if (List->IsFlag(BrokenPkg,pkgOrderList::Loop) && PkgLoop) + { + // This dependancy has already been dealt with by another SmartUnPack on Pkg + break; } else { - if (Debug) + // Found a break, so see if we can unpack the package to avoid it + // but do not set loop if another SmartUnPack already deals with it + // Also, avoid it if the package we would unpack pre-depends on this one + VerIterator InstallVer(Cache,Cache[BrokenPkg].InstallVer); + bool circle = false; + for (pkgCache::DepIterator D = InstallVer.DependsList(); D.end() == false; ++D) { - cout << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.FullName() << " to avoid " << End; - if (PkgLoop == true) - cout << " (Looping)"; - cout << std::endl; + if (D->Type != pkgCache::Dep::PreDepends) + continue; + SPtrArray VL = D.AllTargets(); + for (Version **I = VL; *I != 0; ++I) + { + 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)) + continue; + circle = true; + break; + } + if (circle == true) + break; + } + if (circle == true) + { + if (Debug) + cout << OutputInDepth(Depth) << " Avoiding " << End << " avoided as " << BrokenPkg.FullName() << " has a pre-depends on " << Pkg.FullName() << std::endl; + continue; + } + else + { + if (Debug) + { + cout << OutputInDepth(Depth) << " Unpacking " << BrokenPkg.FullName() << " to avoid " << End; + if (PkgLoop == true) + cout << " (Looping)"; + cout << std::endl; + } + if (PkgLoop == false) + List->Flag(Pkg,pkgOrderList::Loop); + if (SmartUnPack(BrokenPkg, false, Depth + 1) == true) + { + if (List->IsFlag(BrokenPkg,pkgOrderList::Loop) == false) + Changed = true; + } + if (PkgLoop == false) + List->RmFlag(Pkg,pkgOrderList::Loop); } - if (PkgLoop == false) - List->Flag(Pkg,pkgOrderList::Loop); - SmartUnPack(BrokenPkg, false, Depth + 1); - if (PkgLoop == false) - List->RmFlag(Pkg,pkgOrderList::Loop); } } - } else { // Check if a package needs to be removed - if (Cache[BrokenPkg].Delete() == true && !List->IsFlag(BrokenPkg,pkgOrderList::Configured)) + else if (Cache[BrokenPkg].Delete() == true && List->IsFlag(BrokenPkg,pkgOrderList::Configured) == false) { if (Debug) cout << OutputInDepth(Depth) << " Removing " << BrokenPkg.FullName() << " to avoid " << End << endl; @@ -790,7 +821,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c } } } - } + } while (Changed == true); // Check for reverse conflicts. if (CheckRConflicts(Pkg,Pkg.RevDependsList(), -- cgit v1.2.3 From bce4caa3078503bc1bec5221c5251d9e418a0f2a Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 13 Mar 2012 14:32:40 +0100 Subject: add APT::pkgPackageManager::MaxLoopCount to ensure that the ordering code does not get into a endless loop when it flip-flops between two states --- apt-pkg/packagemanager.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 698c8606f..dd8f306f2 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -337,7 +337,10 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) however if there is a loop (A depends on B, B depends on A) this will not be the case, so check for dependencies before configuring. */ bool Bad = false, Changed = false; - do { + const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 100); + unsigned int i=0; + do + { Changed = false; for (DepIterator D = instVer.DependsList(); D.end() == false; ) { @@ -460,6 +463,8 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) if (Bad == true && Changed == false && Debug == true) std::clog << OutputInDepth(Depth) << "Could not satisfy " << Start << std::endl; } + if (i++ > max_loops) + return _error->Error("Internal error: MaxLoopCount reached in SmartUnPack for %s, aborting", Pkg.FullName().c_str()); } while (Changed == true); if (Bad) { @@ -596,7 +601,10 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured), or by the ConfigureAll call at the end of the for loop in OrderInstall. */ bool Changed = false; - do { + const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 100); + unsigned int i; + do + { Changed = false; for (DepIterator D = instVer.DependsList(); D.end() == false; ) { @@ -821,6 +829,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c } } } + if (i++ > max_loops) + return _error->Error("Internal error: MaxLoopCount reached in SmartConfigure for %s, aborting", Pkg.FullName().c_str()); } while (Changed == true); // Check for reverse conflicts. -- cgit v1.2.3 From 31bda5000136d77f516cf2080257835fb44deaef Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 20 Mar 2012 17:05:11 +0100 Subject: * apt-pkg/acquire-worker.cc: - check return of write() as gcc recommends * apt-pkg/acquire.cc: - check return of write() as gcc recommends * apt-pkg/cdrom.cc: - check return of chdir() and link() as gcc recommends * apt-pkg/clean.cc: - check return of chdir() as gcc recommends * apt-pkg/contrib/netrc.cc: - check return of asprintf() as gcc recommends --- apt-pkg/acquire-worker.cc | 18 +++++++++++++++++- apt-pkg/acquire.cc | 18 +++++++++++++++++- apt-pkg/cdrom.cc | 6 ++++-- apt-pkg/clean.cc | 11 +++++++---- apt-pkg/contrib/netrc.cc | 3 +-- 5 files changed, 46 insertions(+), 10 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc index 3bb977e14..d79b2b16d 100644 --- a/apt-pkg/acquire-worker.cc +++ b/apt-pkg/acquire-worker.cc @@ -431,7 +431,23 @@ bool pkgAcquire::Worker::MediaChange(string Message) << Drive << ":" // drive << msg.str() // l10n message << endl; - write(status_fd, status.str().c_str(), status.str().size()); + + std::string const dlstatus = status.str(); + size_t done = 0; + size_t todo = dlstatus.size(); + errno = 0; + int res = 0; + do + { + res = write(status_fd, dlstatus.c_str() + done, todo); + if (res < 0 && errno == EINTR) + continue; + if (res < 0) + break; + done += res; + todo -= res; + } + while (res > 0 && todo > 0); } if (Log == 0 || Log->MediaChange(LookupTag(Message,"Media"), diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 573a85c2f..19bcca8a1 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -872,7 +872,23 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) << ":" << (CurrentBytes/float(TotalBytes)*100.0) << ":" << msg << endl; - write(fd, status.str().c_str(), status.str().size()); + + std::string const dlstatus = status.str(); + size_t done = 0; + size_t todo = dlstatus.size(); + errno = 0; + int res = 0; + do + { + res = write(fd, dlstatus.c_str() + done, todo); + if (res < 0 && errno == EINTR) + continue; + if (res < 0) + break; + done += res; + todo -= res; + } + while (res > 0 && todo > 0); } return true; diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index 4462d4e24..50c204371 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -430,7 +430,8 @@ bool pkgCdrom::WriteDatabase(Configuration &Cnf) Out.close(); - link(DFile.c_str(),string(DFile + '~').c_str()); + 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) return _error->Errno("rename","Failed to rename %s.new to %s", DFile.c_str(),DFile.c_str()); @@ -697,7 +698,8 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/ return false; } - chdir(StartDir.c_str()); + if (chdir(StartDir.c_str()) != 0) + return _error->Errno("chdir","Unable to change to %s", StartDir.c_str()); if (_config->FindB("Debug::aptcdrom",false) == true) { diff --git a/apt-pkg/clean.cc b/apt-pkg/clean.cc index ed8fa1aa9..9c167eaa5 100644 --- a/apt-pkg/clean.cc +++ b/apt-pkg/clean.cc @@ -54,9 +54,11 @@ bool pkgArchiveCleaner::Go(std::string Dir,pkgCache &Cache) struct stat St; if (stat(Dir->d_name,&St) != 0) { - chdir(StartDir.c_str()); + _error->Errno("stat",_("Unable to stat %s."),Dir->d_name); closedir(D); - return _error->Errno("stat",_("Unable to stat %s."),Dir->d_name); + if (chdir(StartDir.c_str()) != 0) + return _error->Errno("chdir", _("Unable to change to %s"), StartDir.c_str()); + return false; } // Grab the package name @@ -115,8 +117,9 @@ bool pkgArchiveCleaner::Go(std::string Dir,pkgCache &Cache) Erase(Dir->d_name,Pkg,Ver,St); }; - chdir(StartDir.c_str()); closedir(D); - return true; + if (chdir(StartDir.c_str()) != 0) + return _error->Errno("chdir", _("Unable to change to %s"), StartDir.c_str()); + return true; } /*}}}*/ diff --git a/apt-pkg/contrib/netrc.cc b/apt-pkg/contrib/netrc.cc index cb7d36088..56e59d84b 100644 --- a/apt-pkg/contrib/netrc.cc +++ b/apt-pkg/contrib/netrc.cc @@ -68,8 +68,7 @@ int parsenetrc (char *host, char *login, char *password, char *netrcfile = NULL) if (!home) return -1; - asprintf (&netrcfile, "%s%s%s", home, DIR_CHAR, NETRC); - if(!netrcfile) + if (asprintf (&netrcfile, "%s%s%s", home, DIR_CHAR, NETRC) == -1 || netrcfile == NULL) return -1; else netrc_alloc = true; -- cgit v1.2.3 From 319790f4f86f595724fb2bd5aa6274d345469010 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 20 Mar 2012 19:23:32 +0100 Subject: * methods/rred.cc: - check return of writev() as gcc recommends * methods/mirror.cc: - check return of chdir() as gcc recommends * apt-pkg/deb/dpkgpm.cc: - check return of write() a gcc recommends * apt-inst/deb/debfile.cc: - check return of chdir() as gcc recommends * apt-inst/deb/dpkgdb.cc: - check return of chdir() as gcc recommends --- apt-pkg/deb/dpkgpm.cc | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index c46a81209..63c5a6380 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -163,6 +163,25 @@ pkgCache::VerIterator FindNowVersion(const pkgCache::PkgIterator &Pkg) return Ver; } /*}}}*/ +ssize_t retry_write(int fd, const void *buf, size_t count) +{ + int Res; + ssize_t i = 0; + errno = 0; + do + { + Res = write(fd, buf, count); + if (Res < 0 && errno == EINTR) + continue; + if (Res < 0) + break; + buf = (char *)buf + Res; + count -= Res; + i += Res; + } + while (Res > 0 && count > 0); + return i; +} // DPkgPM::pkgDPkgPM - Constructor /*{{{*/ // --------------------------------------------------------------------- @@ -425,7 +444,7 @@ void pkgDPkgPM::DoStdin(int master) unsigned char input_buf[256] = {0,}; ssize_t len = read(0, input_buf, sizeof(input_buf)); if (len) - write(master, input_buf, len); + retry_write(master, input_buf, len); else d->stdin_is_dev_null = true; } @@ -451,7 +470,7 @@ void pkgDPkgPM::DoTerminalPty(int master) } if(len <= 0) return; - write(1, term_buf, len); + retry_write(1, term_buf, len); if(d->term_out) fwrite(term_buf, len, sizeof(char), d->term_out); } @@ -526,7 +545,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) << ":" << s << endl; if(OutStatusFd > 0) - write(OutStatusFd, status.str().c_str(), status.str().size()); + retry_write(OutStatusFd, status.str().c_str(), status.str().size()); if (Debug == true) std::clog << "send: '" << status.str() << "'" << endl; @@ -550,7 +569,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) << ":" << list[3] << endl; if(OutStatusFd > 0) - write(OutStatusFd, status.str().c_str(), status.str().size()); + retry_write(OutStatusFd, status.str().c_str(), status.str().size()); if (Debug == true) std::clog << "send: '" << status.str() << "'" << endl; pkgFailures++; @@ -564,7 +583,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) << ":" << list[3] << endl; if(OutStatusFd > 0) - write(OutStatusFd, status.str().c_str(), status.str().size()); + retry_write(OutStatusFd, status.str().c_str(), status.str().size()); if (Debug == true) std::clog << "send: '" << status.str() << "'" << endl; return; @@ -592,7 +611,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) << ":" << s << endl; if(OutStatusFd > 0) - write(OutStatusFd, status.str().c_str(), status.str().size()); + retry_write(OutStatusFd, status.str().c_str(), status.str().size()); if (Debug == true) std::clog << "send: '" << status.str() << "'" << endl; } @@ -1055,7 +1074,8 @@ bool pkgDPkgPM::Go(int OutStatusFd) } int fd[2]; - pipe(fd); + if (pipe(fd) != 0) + return _error->Errno("pipe","Failed to create IPC pipe to dpkg"); #define ADDARG(X) Args.push_back(X); Size += strlen(X) #define ADDARGC(X) Args.push_back(X); Size += sizeof(X) - 1 @@ -1236,7 +1256,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) << (PackagesDone/float(PackagesTotal)*100.0) << ":" << _("Running dpkg") << endl; - write(OutStatusFd, status.str().c_str(), status.str().size()); + retry_write(OutStatusFd, status.str().c_str(), status.str().size()); } Child = ExecFork(); -- cgit v1.2.3 From 9179f697ed4796a86f820b516f034fd679e48be4 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 22 Mar 2012 00:16:11 +0100 Subject: the previously used VERSION didn't work everywhere so we are switching to the more standard PACKAGE_VERSION and make it work in every file --- apt-pkg/init.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc index a1c47c030..76278921f 100644 --- a/apt-pkg/init.cc +++ b/apt-pkg/init.cc @@ -24,7 +24,7 @@ #define Stringfy_(x) # x #define Stringfy(x) Stringfy_(x) -const char *pkgVersion = VERSION; +const char *pkgVersion = PACKAGE_VERSION; const char *pkgLibVersion = Stringfy(APT_PKG_MAJOR) "." Stringfy(APT_PKG_MINOR) "." Stringfy(APT_PKG_RELEASE); -- cgit v1.2.3 From 136a6c13c8df7c403dd5284ff8bda20c8a84b614 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 22 Mar 2012 22:18:05 +0100 Subject: make these retry_write methods static so that they don't end up as symbols --- apt-pkg/deb/dpkgpm.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 63c5a6380..1a21c03eb 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -163,7 +163,8 @@ pkgCache::VerIterator FindNowVersion(const pkgCache::PkgIterator &Pkg) return Ver; } /*}}}*/ -ssize_t retry_write(int fd, const void *buf, size_t count) +static ssize_t +retry_write(int fd, const void *buf, size_t count) { int Res; ssize_t i = 0; -- cgit v1.2.3 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 7efb8c8ef10c1d0b9479c24a6a5b4e96fc0e6286 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 5 Apr 2012 15:18:03 +0200 Subject: detect zlib correctly. We still don't allow to build without it to remain compatible with users accessing it directly, but this prepares for a drop of this strict requirement in the future --- apt-pkg/contrib/fileutl.cc | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 1808489d7..691657cb4 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -44,14 +44,8 @@ #include #include -// FIXME: Compressor Fds have some speed disadvantages and are a bit buggy currently, -// so while the current implementation satisfies the testcases it is not a real option -// to disable it for now -#define APT_USE_ZLIB 1 -#if APT_USE_ZLIB -#include -#else -#pragma message "Usage of zlib is DISABLED!" +#ifdef HAVE_ZLIB + #include #endif #ifdef WORDS_BIGENDIAN @@ -65,7 +59,7 @@ using namespace std; class FileFdPrivate { public: -#if APT_USE_ZLIB +#ifdef HAVE_ZLIB gzFile gz; #else void* gz; @@ -1016,7 +1010,7 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C d->compressor = compressor; if (compressor.Name == "." || compressor.Binary.empty() == true) return true; -#if APT_USE_ZLIB +#ifdef HAVE_ZLIB else if (compressor.Name == "gzip") { if ((Mode & ReadWrite) == ReadWrite) @@ -1137,7 +1131,7 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual) *((char *)To) = '\0'; do { -#if APT_USE_ZLIB +#ifdef HAVE_ZLIB if (d->gz != NULL) Res = gzread(d->gz,To,Size); else @@ -1149,7 +1143,7 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual) if (errno == EINTR) continue; Flags |= Fail; -#if APT_USE_ZLIB +#ifdef HAVE_ZLIB if (d->gz != NULL) { int err; @@ -1190,7 +1184,7 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual) char* FileFd::ReadLine(char *To, unsigned long long const Size) { *To = '\0'; -#if APT_USE_ZLIB +#ifdef HAVE_ZLIB if (d->gz != NULL) return gzgets(d->gz, To, Size); #endif @@ -1221,7 +1215,7 @@ bool FileFd::Write(const void *From,unsigned long long Size) errno = 0; do { -#if APT_USE_ZLIB +#ifdef HAVE_ZLIB if (d->gz != NULL) Res = gzwrite(d->gz,From,Size); else @@ -1289,7 +1283,7 @@ bool FileFd::Seek(unsigned long long To) return true; } int res; -#if APT_USE_ZLIB +#ifdef HAVE_ZLIB if (d->gz) res = gzseek(d->gz,To,SEEK_SET); else @@ -1325,7 +1319,7 @@ bool FileFd::Skip(unsigned long long Over) } int res; -#if APT_USE_ZLIB +#ifdef HAVE_ZLIB if (d->gz != NULL) res = gzseek(d->gz,Over,SEEK_CUR); else @@ -1373,7 +1367,7 @@ unsigned long long FileFd::Tell() return d->seekpos; off_t Res; -#if APT_USE_ZLIB +#ifdef HAVE_ZLIB if (d->gz != NULL) Res = gztell(d->gz); else @@ -1427,7 +1421,7 @@ unsigned long long FileFd::Size() size = Tell(); Seek(oldSeek); } -#if APT_USE_ZLIB +#ifdef HAVE_ZLIB // 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 @@ -1500,7 +1494,7 @@ bool FileFd::Close() bool Res = true; if ((Flags & AutoClose) == AutoClose) { -#if APT_USE_ZLIB +#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 -- cgit v1.2.3 From 2024154c6d4fa1142b022d54f8c88cf8991929ff Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 5 Apr 2012 18:49:13 +0200 Subject: * apt-pkg/aptconfiguration.cc: - if present, prefer xz binary over lzma --- apt-pkg/aptconfiguration.cc | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index 4324f0e63..2fdb837c5 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -432,9 +432,30 @@ bool const Configuration::checkArchitecture(std::string const &Arch) { // setDefaultConfigurationForCompressors /*{{{*/ void Configuration::setDefaultConfigurationForCompressors() { // Set default application paths to check for optional compression types - _config->CndSet("Dir::Bin::lzma", "/usr/bin/lzma"); - _config->CndSet("Dir::Bin::xz", "/usr/bin/xz"); _config->CndSet("Dir::Bin::bzip2", "/bin/bzip2"); + _config->CndSet("Dir::Bin::xz", "/usr/bin/xz"); + if (FileExists(_config->FindFile("Dir::Bin::xz")) == true) { + _config->CndSet("Dir::Bin::lzma", _config->Find("Dir::Bin::xz")); + _config->Set("APT::Compressor::lzma::Binary", "xz"); + if (_config->Exists("APT::Compressor::lzma::CompressArg") == false) { + _config->Set("APT::Compressor::lzma::CompressArg::", "--format=lzma"); + _config->Set("APT::Compressor::lzma::CompressArg::", "-9"); + } + if (_config->Exists("APT::Compressor::lzma::UncompressArg") == false) { + _config->Set("APT::Compressor::lzma::UncompressArg::", "--format=lzma"); + _config->Set("APT::Compressor::lzma::UncompressArg::", "-d"); + } + } else { + _config->CndSet("Dir::Bin::lzma", "/usr/bin/lzma"); + if (_config->Exists("APT::Compressor::lzma::CompressArg") == false) { + _config->Set("APT::Compressor::lzma::CompressArg::", "--suffix="); + _config->Set("APT::Compressor::lzma::CompressArg::", "-9"); + } + if (_config->Exists("APT::Compressor::lzma::UncompressArg") == false) { + _config->Set("APT::Compressor::lzma::UncompressArg::", "--suffix="); + _config->Set("APT::Compressor::lzma::UncompressArg::", "-d"); + } + } } /*}}}*/ // getCompressors - Return Vector of usbale compressors /*{{{*/ @@ -458,10 +479,10 @@ const Configuration::getCompressors(bool const Cached) { compressors.push_back(Compressor("gzip",".gz","gzip","-9n","-d",2)); if (_config->Exists("Dir::Bin::bzip2") == false || FileExists(_config->FindFile("Dir::Bin::bzip2")) == true) compressors.push_back(Compressor("bzip2",".bz2","bzip2","-9","-d",3)); - if (_config->Exists("Dir::Bin::lzma") == false || FileExists(_config->FindFile("Dir::Bin::lzma")) == true) - compressors.push_back(Compressor("lzma",".lzma","lzma","-9","-d",4)); if (_config->Exists("Dir::Bin::xz") == false || FileExists(_config->FindFile("Dir::Bin::xz")) == true) - compressors.push_back(Compressor("xz",".xz","xz","-6","-d",5)); + compressors.push_back(Compressor("xz",".xz","xz","-6","-d",4)); + if (_config->Exists("Dir::Bin::lzma") == false || FileExists(_config->FindFile("Dir::Bin::lzma")) == true) + compressors.push_back(Compressor("lzma",".lzma","lzma","-9","-d",5)); std::vector const comp = _config->FindVector("APT::Compressor"); for (std::vector::const_iterator c = comp.begin(); @@ -494,7 +515,7 @@ Configuration::Compressor::Compressor(char const *name, char const *extension, char const *binary, char const *compressArg, char const *uncompressArg, unsigned short const cost) { - std::string const config = std::string("APT:Compressor::").append(name).append("::"); + std::string const config = std::string("APT::Compressor::").append(name).append("::"); Name = _config->Find(std::string(config).append("Name"), name); Extension = _config->Find(std::string(config).append("Extension"), extension); Binary = _config->Find(std::string(config).append("Binary"), binary); -- cgit v1.2.3 From 8dd623dbd616ee23dc96a2c99a4415b153dd7290 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 5 Apr 2012 19:02:08 +0200 Subject: if we have zlib builtin insert add a dummy gzip compressor for FileFD --- apt-pkg/aptconfiguration.cc | 4 ++++ apt-pkg/contrib/fileutl.cc | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index 2fdb837c5..f00852775 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -477,6 +477,10 @@ const Configuration::getCompressors(bool const Cached) { compressors.push_back(Compressor(".", "", "", "", "", 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","/bin/false", "", "", 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)); if (_config->Exists("Dir::Bin::xz") == false || FileExists(_config->FindFile("Dir::Bin::xz")) == true) diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 691657cb4..30d0b6662 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -829,7 +829,6 @@ bool FileFd::Open(string FileName,unsigned int const Mode,CompressMode Compress, if (Compress == Auto && (Mode & WriteOnly) == WriteOnly) return _error->Error("Autodetection on %s only works in ReadOnly openmode!", FileName.c_str()); - // FIXME: Denote inbuilt compressors somehow - as we don't need to have the binaries for them std::vector const compressors = APT::Configuration::getCompressors(); std::vector::const_iterator compressor = compressors.begin(); if (Compress == Auto) -- cgit v1.2.3 From c4997486bffc76e2581e9072bff05eba0feeb29c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 5 Apr 2012 20:51:36 +0200 Subject: - add libbz2-dev as new build-dependency - remove the libz-dev alternative from zlib1g-dev build-dependency - do the same for bz2 builtin if available * apt-pkg/contrib/fileutl.cc: - use libz2 library for (de)compression instead of the bzip2 binary as the first is a dependency of dpkg and the later just priority:optional so we gain 'easier' access to bz2-compressed Translation files this way --- apt-pkg/aptconfiguration.cc | 6 ++- apt-pkg/contrib/fileutl.cc | 107 ++++++++++++++++++++++++++++++++++++++++---- apt-pkg/makefile | 8 +++- 3 files changed, 110 insertions(+), 11 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index f00852775..d6691e392 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -479,10 +479,14 @@ const Configuration::getCompressors(bool const Cached) { compressors.push_back(Compressor("gzip",".gz","gzip","-9n","-d",2)); #ifdef HAVE_ZLIB else - compressors.push_back(Compressor("gzip",".gz","/bin/false", "", "", 2)); + compressors.push_back(Compressor("gzip",".gz","false", "", "", 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)); +#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)); if (_config->Exists("Dir::Bin::lzma") == false || FileExists(_config->FindFile("Dir::Bin::lzma")) == true) diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 30d0b6662..536571fee 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -47,6 +47,9 @@ #ifdef HAVE_ZLIB #include #endif +#ifdef HAVE_BZ2 + #include +#endif #ifdef WORDS_BIGENDIAN #include @@ -63,6 +66,11 @@ class FileFdPrivate { gzFile gz; #else void* gz; +#endif +#ifdef HAVE_BZ2 + BZFILE* bz2; +#else + void* bz2; #endif int compressed_fd; pid_t compressor_pid; @@ -70,7 +78,8 @@ class FileFdPrivate { APT::Configuration::Compressor compressor; unsigned int openmode; unsigned long long seekpos; - FileFdPrivate() : gz(NULL), compressed_fd(-1), compressor_pid(-1), pipe(false), + FileFdPrivate() : gz(NULL), bz2(NULL), + compressed_fd(-1), compressor_pid(-1), pipe(false), openmode(0), seekpos(0) {}; }; @@ -1017,13 +1026,29 @@ bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::C else if ((Mode & WriteOnly) == WriteOnly) d->gz = gzdopen(iFd, "w"); else - d->gz = gzdopen (iFd, "r"); + d->gz = gzdopen(iFd, "r"); if (d->gz == NULL) return false; Flags |= Compressed; return true; } #endif +#ifdef HAVE_BZ2 + else if (compressor.Name == "bzip2") + { + if ((Mode & ReadWrite) == ReadWrite) + d->bz2 = BZ2_bzdopen(iFd, "r+"); + else if ((Mode & WriteOnly) == WriteOnly) + d->bz2 = BZ2_bzdopen(iFd, "w"); + else + d->bz2 = BZ2_bzdopen(iFd, "r"); + if (d->bz2 == NULL) + return false; + Flags |= Compressed; + return true; + } +#endif + if ((Mode & ReadWrite) == ReadWrite) return _error->Error("ReadWrite mode is not supported for file %s", FileName.c_str()); @@ -1132,7 +1157,12 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual) { #ifdef HAVE_ZLIB if (d->gz != NULL) - Res = gzread(d->gz,To,Size); + Res = gzread(d->gz,To,Size); + else +#endif +#ifdef HAVE_BZ2 + if (d->bz2 != NULL) + Res = BZ2_bzread(d->bz2,To,Size); else #endif Res = read(iFd,To,Size); @@ -1150,6 +1180,15 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual) if (err != Z_ERRNO) return _error->Error("gzread: %s (%d: %s)", _("Read error"), err, errmsg); } +#endif +#ifdef HAVE_BZ2 + if (d->bz2 != NULL) + { + int err; + char const * const errmsg = BZ2_bzerror(d->bz2, &err); + if (err != BZ_IO_ERROR) + return _error->Error("BZ2_bzread: %s (%d: %s)", _("Read error"), err, errmsg); + } #endif return _error->Errno("read",_("Read error")); } @@ -1218,6 +1257,11 @@ bool FileFd::Write(const void *From,unsigned long long Size) if (d->gz != NULL) Res = gzwrite(d->gz,From,Size); else +#endif +#ifdef HAVE_BZ2 + if (d->bz2 != NULL) + Res = BZ2_bzwrite(d->bz2,(void*)From,Size); + else #endif Res = write(iFd,From,Size); if (Res < 0 && errno == EINTR) @@ -1225,6 +1269,24 @@ bool FileFd::Write(const void *From,unsigned long long Size) if (Res < 0) { Flags |= Fail; +#ifdef HAVE_ZLIB + if (d->gz != NULL) + { + int err; + char const * const errmsg = gzerror(d->gz, &err); + if (err != Z_ERRNO) + return _error->Error("gzwrite: %s (%d: %s)", _("Write error"), err, errmsg); + } +#endif +#ifdef HAVE_BZ2 + if (d->bz2 != NULL) + { + int err; + char const * const errmsg = BZ2_bzerror(d->bz2, &err); + if (err != BZ_IO_ERROR) + return _error->Error("BZ2_bzwrite: %s (%d: %s)", _("Write error"), err, errmsg); + } +#endif return _error->Errno("write",_("Write error")); } @@ -1246,7 +1308,11 @@ bool FileFd::Write(const void *From,unsigned long long Size) /* */ bool FileFd::Seek(unsigned long long To) { - if (d->pipe == true) + if (d->pipe == true +#ifdef HAVE_BZ2 + || d->bz2 != NULL +#endif + ) { // Our poor man seeking in pipes is costly, so try to avoid it unsigned long long seekpos = Tell(); @@ -1257,6 +1323,10 @@ bool FileFd::Seek(unsigned long long To) if ((d->openmode & ReadOnly) != ReadOnly) return _error->Error("Reopen is only implemented for read-only files!"); +#ifdef HAVE_BZ2 + if (d->bz2 != NULL) + BZ2_bzclose(d->bz2); +#endif close(iFd); iFd = 0; if (TemporaryFileName.empty() == false) @@ -1303,7 +1373,11 @@ bool FileFd::Seek(unsigned long long To) /* */ bool FileFd::Skip(unsigned long long Over) { - if (d->pipe == true) + if (d->pipe == true +#ifdef HAVE_BZ2 + || d->bz2 != NULL +#endif + ) { d->seekpos += Over; char buffer[1024]; @@ -1339,11 +1413,13 @@ bool FileFd::Skip(unsigned long long Over) /* */ bool FileFd::Truncate(unsigned long long To) { - if (d->gz != NULL) +#if defined HAVE_ZLIB || defined HAVE_BZ2 + if (d->gz != NULL || d->bz2 != NULL) { Flags |= Fail; - return _error->Error("Truncating gzipped files is not implemented (%s)", FileName.c_str()); + return _error->Error("Truncating compressed files is not implemented (%s)", FileName.c_str()); } +#endif if (ftruncate(iFd,To) != 0) { Flags |= Fail; @@ -1362,7 +1438,11 @@ 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->pipe == true +#ifdef HAVE_BZ2 + || d->bz2 != NULL +#endif + ) return d->seekpos; off_t Res; @@ -1409,7 +1489,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->pipe == true +#ifdef HAVE_BZ2 + || (d->bz2 && size > 0) +#endif + ) { unsigned long long const oldSeek = Tell(); char ignore[1000]; @@ -1500,6 +1584,11 @@ bool FileFd::Close() 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()); diff --git a/apt-pkg/makefile b/apt-pkg/makefile index e1f69dd65..27d7ead24 100644 --- a/apt-pkg/makefile +++ b/apt-pkg/makefile @@ -14,7 +14,13 @@ include ../buildlib/libversion.mak LIBRARY=apt-pkg MAJOR=$(LIBAPTPKG_MAJOR) MINOR=$(LIBAPTPKG_RELEASE) -SLIBS=$(PTHREADLIB) $(INTLLIBS) -lutil -ldl -lz +SLIBS=$(PTHREADLIB) $(INTLLIBS) -lutil -ldl +ifeq ($(HAVE_ZLIB),yes) +SLIBS+= -lz +endif +ifeq ($(HAVE_BZ2),yes) +SLIBS+= -lbz2 +endif APT_DOMAIN:=libapt-pkg$(LIBAPTPKG_MAJOR) # Source code for the contributed non-core things -- cgit v1.2.3 From 8bcbc69451bfb00977c16fdb03662c844f6e861e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 11 Apr 2012 11:57:48 +0200 Subject: use xz-utils in the testcases instead of lzma and ensure that we really ignore the presents (or absence) of lzma if we decided to use xz --- 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 d6691e392..d72b0c5ae 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -435,7 +435,7 @@ void Configuration::setDefaultConfigurationForCompressors() { _config->CndSet("Dir::Bin::bzip2", "/bin/bzip2"); _config->CndSet("Dir::Bin::xz", "/usr/bin/xz"); if (FileExists(_config->FindFile("Dir::Bin::xz")) == true) { - _config->CndSet("Dir::Bin::lzma", _config->Find("Dir::Bin::xz")); + _config->Clear("Dir::Bin::lzma"); _config->Set("APT::Compressor::lzma::Binary", "xz"); if (_config->Exists("APT::Compressor::lzma::CompressArg") == false) { _config->Set("APT::Compressor::lzma::CompressArg::", "--format=lzma"); -- cgit v1.2.3 From d68d65ad637526e46ea77ab83e07470d26df15fc Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 11 Apr 2012 13:25:28 +0200 Subject: use a static FileFd::Write overload to reduce duplication of write()-retry code --- apt-pkg/acquire-worker.cc | 27 +++------------------------ apt-pkg/acquire.cc | 16 +--------------- apt-pkg/contrib/fileutl.cc | 22 ++++++++++++++++++++++ apt-pkg/contrib/fileutl.h | 1 + apt-pkg/deb/dpkgpm.cc | 34 +++++++--------------------------- 5 files changed, 34 insertions(+), 66 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc index d79b2b16d..77e2fc311 100644 --- a/apt-pkg/acquire-worker.cc +++ b/apt-pkg/acquire-worker.cc @@ -433,21 +433,7 @@ bool pkgAcquire::Worker::MediaChange(string Message) << endl; std::string const dlstatus = status.str(); - size_t done = 0; - size_t todo = dlstatus.size(); - errno = 0; - int res = 0; - do - { - res = write(status_fd, dlstatus.c_str() + done, todo); - if (res < 0 && errno == EINTR) - continue; - if (res < 0) - break; - done += res; - todo -= res; - } - while (res > 0 && todo > 0); + FileFd::Write(status_fd, dlstatus.c_str(), dlstatus.size()); } if (Log == 0 || Log->MediaChange(LookupTag(Message,"Media"), @@ -546,17 +532,10 @@ bool pkgAcquire::Worker::QueueItem(pkgAcquire::Queue::QItem *Item) /* */ bool pkgAcquire::Worker::OutFdReady() { - int Res; - do - { - Res = write(OutFd,OutQueue.c_str(),OutQueue.length()); - } - while (Res < 0 && errno == EINTR); - - if (Res <= 0) + if (FileFd::Write(OutFd,OutQueue.c_str(),OutQueue.length()) == false) return MethodFailure(); - OutQueue.erase(0,Res); + OutQueue.clear(); if (OutQueue.empty() == true) OutReady = false; diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 19bcca8a1..5e1419056 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -874,21 +874,7 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) << endl; std::string const dlstatus = status.str(); - size_t done = 0; - size_t todo = dlstatus.size(); - errno = 0; - int res = 0; - do - { - res = write(fd, dlstatus.c_str() + done, todo); - if (res < 0 && errno == EINTR) - continue; - if (res < 0) - break; - done += res; - todo -= res; - } - while (res > 0 && todo > 0); + FileFd::Write(fd, dlstatus.c_str(), dlstatus.size()); } return true; diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 536571fee..9e3611b26 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1301,6 +1301,28 @@ bool FileFd::Write(const void *From,unsigned long long Size) Flags |= Fail; return _error->Error(_("write, still have %llu to write but couldn't"), Size); +} +bool FileFd::Write(int Fd, const void *From, unsigned long long Size) +{ + int Res; + errno = 0; + do + { + Res = write(Fd,From,Size); + if (Res < 0 && errno == EINTR) + continue; + if (Res < 0) + return _error->Errno("write",_("Write error")); + + From = (char *)From + Res; + Size -= Res; + } + while (Res > 0 && Size > 0); + + if (Size == 0) + return true; + + return _error->Error(_("write, still have %llu to write but couldn't"), Size); } /*}}}*/ // FileFd::Seek - Seek in the file /*{{{*/ diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 1ca41cb7d..426664d3a 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -78,6 +78,7 @@ class FileFd bool Read(void *To,unsigned long long Size,unsigned long long *Actual = 0); char* ReadLine(char *To, unsigned long long const Size); bool Write(const void *From,unsigned long long Size); + bool static Write(int Fd, const void *From, unsigned long long Size); bool Seek(unsigned long long To); bool Skip(unsigned long long To); bool Truncate(unsigned long long To); diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 1a21c03eb..496daf1df 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -163,26 +163,6 @@ pkgCache::VerIterator FindNowVersion(const pkgCache::PkgIterator &Pkg) return Ver; } /*}}}*/ -static ssize_t -retry_write(int fd, const void *buf, size_t count) -{ - int Res; - ssize_t i = 0; - errno = 0; - do - { - Res = write(fd, buf, count); - if (Res < 0 && errno == EINTR) - continue; - if (Res < 0) - break; - buf = (char *)buf + Res; - count -= Res; - i += Res; - } - while (Res > 0 && count > 0); - return i; -} // DPkgPM::pkgDPkgPM - Constructor /*{{{*/ // --------------------------------------------------------------------- @@ -445,7 +425,7 @@ void pkgDPkgPM::DoStdin(int master) unsigned char input_buf[256] = {0,}; ssize_t len = read(0, input_buf, sizeof(input_buf)); if (len) - retry_write(master, input_buf, len); + FileFd::Write(master, input_buf, len); else d->stdin_is_dev_null = true; } @@ -471,7 +451,7 @@ void pkgDPkgPM::DoTerminalPty(int master) } if(len <= 0) return; - retry_write(1, term_buf, len); + FileFd::Write(1, term_buf, len); if(d->term_out) fwrite(term_buf, len, sizeof(char), d->term_out); } @@ -546,7 +526,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) << ":" << s << endl; if(OutStatusFd > 0) - retry_write(OutStatusFd, status.str().c_str(), status.str().size()); + FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size()); if (Debug == true) std::clog << "send: '" << status.str() << "'" << endl; @@ -570,7 +550,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) << ":" << list[3] << endl; if(OutStatusFd > 0) - retry_write(OutStatusFd, status.str().c_str(), status.str().size()); + FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size()); if (Debug == true) std::clog << "send: '" << status.str() << "'" << endl; pkgFailures++; @@ -584,7 +564,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) << ":" << list[3] << endl; if(OutStatusFd > 0) - retry_write(OutStatusFd, status.str().c_str(), status.str().size()); + FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size()); if (Debug == true) std::clog << "send: '" << status.str() << "'" << endl; return; @@ -612,7 +592,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) << ":" << s << endl; if(OutStatusFd > 0) - retry_write(OutStatusFd, status.str().c_str(), status.str().size()); + FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size()); if (Debug == true) std::clog << "send: '" << status.str() << "'" << endl; } @@ -1257,7 +1237,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) << (PackagesDone/float(PackagesTotal)*100.0) << ":" << _("Running dpkg") << endl; - retry_write(OutStatusFd, status.str().c_str(), status.str().size()); + FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size()); } Child = ExecFork(); -- cgit v1.2.3 From 91ea3def40864efbe9b0bcbc0f65b2ad0e08ba9a Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 12 Apr 2012 15:13:08 +0200 Subject: apt-pkg/packagemanager.cc: tweak MaxLoopCount to 500 and improve the error message --- apt-pkg/packagemanager.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index dd8f306f2..c62c4d187 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -337,7 +337,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) however if there is a loop (A depends on B, B depends on A) this will not be the case, so check for dependencies before configuring. */ bool Bad = false, Changed = false; - const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 100); + const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 500); unsigned int i=0; do { @@ -601,7 +601,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c This will be either dealt with if the package is configured as a dependency of Pkg (if and when Pkg is configured), 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", 100); + const unsigned int max_loops = _config->FindI("APT::pkgPackageManager::MaxLoopCount", 500); unsigned int i; do { @@ -830,7 +830,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c } } if (i++ > max_loops) - return _error->Error("Internal error: MaxLoopCount reached in SmartConfigure for %s, aborting", Pkg.FullName().c_str()); + return _error->Error("Internal error: APT::pkgPackageManager::MaxLoopCount reached in SmartConfigure for %s, aborting", Pkg.FullName().c_str()); } while (Changed == true); // Check for reverse conflicts. -- 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