From 468720c59fcf48b20332cdb7b601b2b0d7cbbfbb Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 10 Dec 2011 19:31:36 +0100 Subject: enable FileFd to guess the compressor based on the filename if requested or to search for compressed silbings of the given filename and use this guessing instead of hardcoding Gzip compression --- apt-pkg/deb/debindexfile.cc | 13 +++++++------ apt-pkg/deb/debrecords.cc | 2 +- apt-pkg/deb/debsrcrecords.h | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 27c1f7f32..d9c448598 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -159,7 +159,7 @@ unsigned long debSourcesIndex::Size() const /* we need to ignore errors here; if the lists are absent, just return 0 */ _error->PushToStack(); - FileFd f = FileFd (IndexFile("Sources"), FileFd::ReadOnlyGzip); + FileFd f = FileFd (IndexFile("Sources"), FileFd::ReadOnly, FileFd::Extension); if (!f.Failed()) size = f.Size(); @@ -288,7 +288,7 @@ unsigned long debPackagesIndex::Size() const /* we need to ignore errors here; if the lists are absent, just return 0 */ _error->PushToStack(); - FileFd f = FileFd (IndexFile("Packages"), FileFd::ReadOnlyGzip); + FileFd f = FileFd (IndexFile("Packages"), FileFd::ReadOnly, FileFd::Extension); if (!f.Failed()) size = f.Size(); @@ -305,7 +305,7 @@ unsigned long debPackagesIndex::Size() const bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const { string PackageFile = IndexFile("Packages"); - FileFd Pkg(PackageFile,FileFd::ReadOnlyGzip); + FileFd Pkg(PackageFile,FileFd::ReadOnly, FileFd::Extension); debListParser Parser(&Pkg, Architecture); if (_error->PendingError() == true) @@ -319,6 +319,7 @@ bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const // Store the IMS information pkgCache::PkgFileIterator File = Gen.GetCurFile(); pkgCacheGenerator::Dynamic DynFile(File); + // FIXME: Get this info from FileFd instead struct stat St; if (fstat(Pkg.Fd(),&St) != 0) return _error->Errno("fstat","Failed to stat"); @@ -489,7 +490,7 @@ unsigned long debTranslationsIndex::Size() const /* we need to ignore errors here; if the lists are absent, just return 0 */ _error->PushToStack(); - FileFd f = FileFd (IndexFile(Language), FileFd::ReadOnlyGzip); + FileFd f = FileFd (IndexFile(Language), FileFd::ReadOnly, FileFd::Extension); if (!f.Failed()) size = f.Size(); @@ -509,7 +510,7 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const string TranslationFile = IndexFile(Language); if (FileExists(TranslationFile)) { - FileFd Trans(TranslationFile,FileFd::ReadOnlyGzip); + FileFd Trans(TranslationFile,FileFd::ReadOnly, FileFd::Extension); debListParser TransParser(&Trans); if (_error->PendingError() == true) return false; @@ -590,7 +591,7 @@ unsigned long debStatusIndex::Size() const /* */ bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const { - FileFd Pkg(File,FileFd::ReadOnlyGzip); + FileFd Pkg(File,FileFd::ReadOnly, FileFd::Extension); if (_error->PendingError() == true) return false; debListParser Parser(&Pkg); diff --git a/apt-pkg/deb/debrecords.cc b/apt-pkg/deb/debrecords.cc index 1afa7b74d..184c07c33 100644 --- a/apt-pkg/deb/debrecords.cc +++ b/apt-pkg/deb/debrecords.cc @@ -25,7 +25,7 @@ using std::string; // --------------------------------------------------------------------- /* */ debRecordParser::debRecordParser(string FileName,pkgCache &Cache) : - File(FileName,FileFd::ReadOnlyGzip), + File(FileName,FileFd::ReadOnly, FileFd::Extension), Tags(&File, std::max(Cache.Head().MaxVerFileSize, Cache.Head().MaxDescFileSize) + 200) { diff --git a/apt-pkg/deb/debsrcrecords.h b/apt-pkg/deb/debsrcrecords.h index 4c8d03224..5d2a67f4f 100644 --- a/apt-pkg/deb/debsrcrecords.h +++ b/apt-pkg/deb/debsrcrecords.h @@ -50,7 +50,7 @@ class debSrcRecordParser : public pkgSrcRecords::Parser virtual bool Files(std::vector &F); debSrcRecordParser(std::string const &File,pkgIndexFile const *Index) - : Parser(Index), Fd(File,FileFd::ReadOnlyGzip), Tags(&Fd,102400), + : Parser(Index), Fd(File,FileFd::ReadOnly, FileFd::Extension), Tags(&Fd,102400), Buffer(NULL) {} virtual ~debSrcRecordParser(); }; -- cgit v1.2.3 From 76a763e1f842543a53bc28db681d963d0fc4ae12 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 10 Dec 2011 20:03:49 +0100 Subject: * apt-pkg/contrib/fileutl.{h,cc}: - implement a ModificationTime method for FileFd --- apt-pkg/deb/debindexfile.cc | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index d9c448598..2635d52c8 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -319,12 +319,8 @@ bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const // Store the IMS information pkgCache::PkgFileIterator File = Gen.GetCurFile(); pkgCacheGenerator::Dynamic DynFile(File); - // FIXME: Get this info from FileFd instead - struct stat St; - if (fstat(Pkg.Fd(),&St) != 0) - return _error->Errno("fstat","Failed to stat"); - File->Size = St.st_size; - File->mtime = St.st_mtime; + File->Size = Pkg.FileSize(); + File->mtime = Pkg.ModificationTime(); if (Gen.MergeList(Parser) == false) return _error->Error("Problem with MergeList %s",PackageFile.c_str()); @@ -522,11 +518,8 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const // Store the IMS information pkgCache::PkgFileIterator TransFile = Gen.GetCurFile(); - struct stat TransSt; - if (fstat(Trans.Fd(),&TransSt) != 0) - return _error->Errno("fstat","Failed to stat"); - TransFile->Size = TransSt.st_size; - TransFile->mtime = TransSt.st_mtime; + TransFile->Size = Trans.FileSize(); + TransFile->mtime = Trans.ModificationTime(); if (Gen.MergeList(TransParser) == false) return _error->Error("Problem with MergeList %s",TranslationFile.c_str()); @@ -608,8 +601,8 @@ bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const struct stat St; if (fstat(Pkg.Fd(),&St) != 0) return _error->Errno("fstat","Failed to stat"); - CFile->Size = St.st_size; - CFile->mtime = St.st_mtime; + CFile->Size = Pkg.FileSize(); + CFile->mtime = Pkg.ModificationTime(); CFile->Archive = Gen.WriteUniqString("now"); if (Gen.MergeList(Parser) == false) -- cgit v1.2.3 From 699b209e5122f8fcd85fc4666c9b7020286ab0d0 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 13 Dec 2011 00:17:30 +0100 Subject: Allow the FileFd to use an external Compressor to uncompress a given file internally so that it is exported and can be used like a "normal" uncompressed file with FileFd This allows us to hide th zlib usage in the implementation and use gzip instead if we don't have zlib builtin (the same for other compressors). The code includes quiet a few FIXME's so while all tests are working it shouldn't be used just yet outside of libapt as it might break. --- apt-pkg/deb/deblistparser.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 28568d5e3..bdb50f6bf 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -773,6 +773,7 @@ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI, // file. to provide Component pinning we use the section name now FileI->Component = WriteUniqString(component); + // FIXME: Code depends on the fact that Release files aren't compressed FILE* release = fdopen(dup(File.Fd()), "r"); if (release == NULL) return false; -- cgit v1.2.3 From a4f6bdc8bd91c7282ae9ac60c44844c6f0058a65 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 13 Dec 2011 00:54:37 +0100 Subject: revert 2184.1.2: do not pollute namespace in headers The breakage is just to big for now, so guard the change with #ifndef APT_8_CLEANER_HEADERS and be nice to library users --- apt-pkg/deb/dpkgpm.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h index 6b62360b7..aab39f633 100644 --- a/apt-pkg/deb/dpkgpm.h +++ b/apt-pkg/deb/dpkgpm.h @@ -15,6 +15,11 @@ #include #include +#ifndef APT_8_CLEANER_HEADERS +using std::vector; +using std::map; +#endif + class pkgDPkgPMPrivate; class pkgDPkgPM : public pkgPackageManager -- cgit v1.2.3 From b9dadc24b9477b466bc8058c765d76c65ecc7125 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 13 Dec 2011 01:22:38 +0100 Subject: revert 2184.1.3: forward declaration instead of headers The breakage is just to big for now, so guard the change with #ifndef APT_8_CLEANER_HEADERS and be nice to library users --- apt-pkg/deb/deblistparser.h | 4 ++++ apt-pkg/deb/debmetaindex.h | 4 ++++ apt-pkg/deb/debrecords.h | 4 ++++ 3 files changed, 12 insertions(+) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index 9519d9711..386d291a2 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -14,6 +14,10 @@ #include #include +#ifndef APT_8_CLEANER_HEADERS +#include +#endif + class debListParser : public pkgCacheGenerator::ListParser { public: diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index 0cba2d8a8..b9ecab97c 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -8,6 +8,10 @@ #include #include +#ifndef APT_8_CLEANER_HEADERS +#include +#endif + class debReleaseIndex : public metaIndex { public: diff --git a/apt-pkg/deb/debrecords.h b/apt-pkg/deb/debrecords.h index 9c7ea6b48..b5e3bbdba 100644 --- a/apt-pkg/deb/debrecords.h +++ b/apt-pkg/deb/debrecords.h @@ -18,6 +18,10 @@ #include #include +#ifndef APT_8_CLEANER_HEADERS +#include +#endif + class debRecordParser : public pkgRecords::Parser { /** \brief dpointer placeholder (for later in case we need it) */ -- cgit v1.2.3 From 73688d27f60b2da3889a06362ee567101e3b331e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 15 Dec 2011 09:13:21 +0100 Subject: =?UTF-8?q?atleast=20libapt=20should=20announce=20to=20itself=20th?= =?UTF-8?q?at=20it=20is=20clean=E2=80=A6=20(and=20be=20it=20if=20it=20trie?= =?UTF-8?q?s=20to=20announce=20that=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apt-pkg/deb/debindexfile.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 2635d52c8..84791a70a 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -26,6 +26,8 @@ #include /*}}}*/ +using std::string; + // SourcesIndex::debSourcesIndex - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -- cgit v1.2.3 From 109eb1511d0cdfa4af3196105cada30bcbb77bc8 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 17 Dec 2011 23:53:31 +0100 Subject: try to avoid direct usage of .Fd() if possible and do read()s and co on the FileFd instead --- apt-pkg/deb/debindexfile.cc | 3 --- 1 file changed, 3 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 84791a70a..5dc2a2ac2 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -600,9 +600,6 @@ bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const // Store the IMS information pkgCache::PkgFileIterator CFile = Gen.GetCurFile(); - struct stat St; - if (fstat(Pkg.Fd(),&St) != 0) - return _error->Errno("fstat","Failed to stat"); CFile->Size = Pkg.FileSize(); CFile->mtime = Pkg.ModificationTime(); CFile->Archive = Gen.WriteUniqString("now"); -- cgit v1.2.3 From 86fc2ca8909eb686e2ad751acb0f0eaf706d9d5e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 13 Jan 2012 17:30:17 +0100 Subject: * apt-pkg/deb/dpkgpm.cc: - check if dpkg supports multiarch with --assert-multi-arch and if it does be always explicit about the architecture --- apt-pkg/deb/dpkgpm.cc | 73 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 21 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 7c0ed5639..4dc0baa50 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -108,7 +108,7 @@ ionice(int PID) { if (!FileExists("/usr/bin/ionice")) return false; - pid_t Process = ExecFork(); + pid_t Process = ExecFork(); if (Process == 0) { char buf[32]; @@ -829,6 +829,40 @@ static int racy_pselect(int nfds, fd_set *readfds, fd_set *writefds, */ bool pkgDPkgPM::Go(int OutStatusFd) { + // Generate the base argument list for dpkg + std::vector Args; + unsigned long StartSize = 0; + string const Tmp = _config->Find("Dir::Bin::dpkg","dpkg"); + Args.push_back(Tmp.c_str()); + StartSize += Tmp.length(); + + // Stick in any custom dpkg options + Configuration::Item const *Opts = _config->Tree("DPkg::Options"); + if (Opts != 0) + { + Opts = Opts->Child; + for (; Opts != 0; Opts = Opts->Next) + { + if (Opts->Value.empty() == true) + continue; + Args.push_back(Opts->Value.c_str()); + StartSize += Opts->Value.length(); + } + } + + size_t const BaseArgs = Args.size(); + // we need to detect if we can qualify packages with the architecture or not + Args.push_back("--assert-multi-arch"); + Args.push_back(NULL); + + pid_t dpkgAssertMultiArch = ExecFork(); + if (dpkgAssertMultiArch == 0) + { + execv(Args[0], (char**) &Args[0]); + _error->WarningE("dpkgGo", "Can't detect if dpkg supports multi-arch!"); + _exit(2); + } + fd_set rfds; struct timespec tv; sigset_t sigmask; @@ -905,27 +939,20 @@ bool pkgDPkgPM::Go(int OutStatusFd) // create log OpenLog(); - // Generate the base argument list for dpkg - std::vector Args; - unsigned long StartSize = 0; - string const Tmp = _config->Find("Dir::Bin::dpkg","dpkg"); - Args.push_back(Tmp.c_str()); - StartSize += Tmp.length(); - - // Stick in any custom dpkg options - Configuration::Item const *Opts = _config->Tree("DPkg::Options"); - if (Opts != 0) + bool dpkgMultiArch = false; + if (dpkgAssertMultiArch > 0) { - Opts = Opts->Child; - for (; Opts != 0; Opts = Opts->Next) + int Status = 0; + while (waitpid(dpkgAssertMultiArch, &Status, 0) != dpkgAssertMultiArch) { - if (Opts->Value.empty() == true) + if (errno == EINTR) continue; - Args.push_back(Opts->Value.c_str()); - StartSize += Opts->Value.length(); + _error->WarningE("dpkgGo", _("Waited for %s but it wasn't there"), "dpkg --assert-multi-arch"); + break; } + if (WIFEXITED(Status) == true && WEXITSTATUS(Status) == 0) + dpkgMultiArch = true; } - size_t const BaseArgs = Args.size(); // this loop is runs once per operation for (vector::const_iterator I = List.begin(); I != List.end();) @@ -965,14 +992,17 @@ bool pkgDPkgPM::Go(int OutStatusFd) if (J - I > (signed)MaxArgs) { J = I + MaxArgs; - Args.reserve(MaxArgs + 10); + unsigned long const size = MaxArgs + 10; + Args.reserve(size); + Packages.reserve(size); } else { - Args.reserve((J - I) + 10); + unsigned long const size = (J - I) + 10; + Args.reserve(size); + Packages.reserve(size); } - int fd[2]; pipe(fd); @@ -1047,7 +1077,8 @@ bool pkgDPkgPM::Go(int OutStatusFd) continue; if (I->Op == Item::Configure && disappearedPkgs.find(I->Pkg.Name()) != disappearedPkgs.end()) continue; - if (I->Pkg.Arch() == nativeArch || !strcmp(I->Pkg.Arch(), "all")) + // We keep this here to allow "smooth" transitions from e.g. multiarch dpkg/ubuntu to dpkg/debian + if (dpkgMultiArch == false && (I->Pkg.Arch() == nativeArch || !strcmp(I->Pkg.Arch(), "all"))) { char const * const name = I->Pkg.Name(); ADDARG(name); -- cgit v1.2.3