From 01366a44bf85a61d0a533e867922b6097bfb216d Mon Sep 17 00:00:00 2001 From: Steve McIntyre Date: Wed, 23 Nov 2011 19:34:58 +0100 Subject: factored out the decompressor code in IndexCopy::CopyPackages() and TranslationsCopy::CopyTranslations() into a single common function --- apt-pkg/cdrom.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg/cdrom.cc') diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index 07983e44f..872879752 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -116,7 +116,7 @@ bool pkgCdrom::FindPackages(string CD, } } - // see if we find translatin indexes + // see if we find translation indices if (stat("i18n",&Buf) == 0) { D = opendir("i18n"); -- cgit v1.2.3 From 78c9276d29172cbe72fc65ac56bde1627a8f86d1 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 24 Nov 2011 00:53:47 +0100 Subject: use getCompressors() instead of getCompressorTypes() and use it everywhere to replace hardcoding of compressiontypes and compressors --- apt-pkg/cdrom.cc | 125 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 65 insertions(+), 60 deletions(-) (limited to 'apt-pkg/cdrom.cc') diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index 872879752..2c40c731d 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -82,66 +82,68 @@ bool pkgCdrom::FindPackages(string CD, /* Aha! We found some package files. We assume that everything under this dir is controlled by those package files so we don't look down anymore */ - std::vector types = APT::Configuration::getCompressionTypes(); - types.push_back(""); - for (std::vector::const_iterator t = types.begin(); - t != types.end(); ++t) - { - std::string filename = std::string("Packages"); - if ((*t).size() > 0) - filename.append("."+*t); - if (stat(filename.c_str(), &Buf) == 0) - { - List.push_back(CD); - - // Continue down if thorough is given - if (_config->FindB("APT::CDROM::Thorough",false) == false) - return true; - break; - } - } - for (std::vector::const_iterator t = types.begin(); - t != types.end(); ++t) - { - std::string filename = std::string("Sources"); - if ((*t).size() > 0) - filename.append("."+*t); - { - SList.push_back(CD); - - // Continue down if thorough is given - if (_config->FindB("APT::CDROM::Thorough",false) == false) - return true; - break; - } - } + std::vector const compressor = APT::Configuration::getCompressors(); + for (std::vector::const_iterator c = compressor.begin(); + c != compressor.end(); ++c) + { + if (stat(std::string("Packages").append(c->Extension).c_str(), &Buf) != 0) + continue; + + if (_config->FindB("Debug::aptcdrom",false) == true) + std::clog << "Found Packages in " << CD << std::endl; + List.push_back(CD); + + // Continue down if thorough is given + if (_config->FindB("APT::CDROM::Thorough",false) == false) + return true; + break; + } + for (std::vector::const_iterator c = compressor.begin(); + c != compressor.end(); ++c) + { + if (stat(std::string("Sources").append(c->Extension).c_str(), &Buf) != 0) + continue; + + if (_config->FindB("Debug::aptcdrom",false) == true) + std::clog << "Found Sources in " << CD << std::endl; + SList.push_back(CD); + + // Continue down if thorough is given + if (_config->FindB("APT::CDROM::Thorough",false) == false) + return true; + break; + } // see if we find translation indices - if (stat("i18n",&Buf) == 0) + if (DirectoryExists("i18n") == true) { D = opendir("i18n"); for (struct dirent *Dir = readdir(D); Dir != 0; Dir = readdir(D)) { - if(strstr(Dir->d_name,"Translation") != NULL) + if(strncmp(Dir->d_name, "Translation-", strlen("Translation-")) != 0) + continue; + string file = Dir->d_name; + for (std::vector::const_iterator c = compressor.begin(); + c != compressor.end(); ++c) { - if (_config->FindB("Debug::aptcdrom",false) == true) - std::clog << "found translations: " << Dir->d_name << "\n"; - string file = Dir->d_name; - for (std::vector::const_iterator t = types.begin(); - t != types.end(); ++t) - { - std::string needle = "." + *t; - if(file.substr(file.size()-needle.size()) == needle) - file = file.substr(0, file.size()-needle.size()); - TransList.push_back(CD+"i18n/"+ file); - break; - } + string fileext = flExtension(file); + if (file == fileext) + fileext.clear(); + else if (fileext.empty() == false) + fileext = "." + fileext; + + if (c->Extension == fileext) + { + if (_config->FindB("Debug::aptcdrom",false) == true) + std::clog << "Found translation " << Dir->d_name << " in " << CD << "i18n/" << std::endl; + TransList.push_back(CD + "i18n/" + file); + break; + } } } closedir(D); } - D = opendir("."); if (D == 0) return _error->Errno("opendir","Unable to read %s",CD.c_str()); @@ -278,24 +280,27 @@ bool pkgCdrom::DropRepeats(vector &List,const char *Name) { // Get a list of all the inodes ino_t *Inodes = new ino_t[List.size()]; - for (unsigned int I = 0; I != List.size(); I++) + for (unsigned int I = 0; I != List.size(); ++I) { struct stat Buf; - std::vector types = APT::Configuration::getCompressionTypes(); - types.push_back(""); - for (std::vector::const_iterator t = types.begin(); - t != types.end(); ++t) + bool found = false; + + std::vector const compressor = APT::Configuration::getCompressors(); + for (std::vector::const_iterator c = compressor.begin(); + c != compressor.end(); ++c) { - std::string filename = List[I] + Name; - if ((*t).size() > 0) - filename.append("." + *t); + std::string filename = std::string(List[I]).append(Name).append(c->Extension); if (stat(filename.c_str(), &Buf) != 0) - _error->Errno("stat","Failed to stat %s%s",List[I].c_str(), - Name); - Inodes[I] = Buf.st_ino; + continue; + Inodes[I] = Buf.st_ino; + found = true; + break; } + + if (found == false) + _error->Errno("stat","Failed to stat %s%s",List[I].c_str(), Name); } - + if (_error->PendingError() == true) { delete[] Inodes; return false; -- cgit v1.2.3 From 4e86b003bad2e6146c9fe8be492bdc9d212bcd74 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 11 Dec 2011 00:41:50 +0100 Subject: strip the extension of the translation file before storing it in the list (regression from compression rewrite; found by Steve McIntyre, thanks!) --- apt-pkg/cdrom.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-pkg/cdrom.cc') diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index 2c40c731d..026094a6e 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -136,6 +136,7 @@ bool pkgCdrom::FindPackages(string CD, { if (_config->FindB("Debug::aptcdrom",false) == true) std::clog << "Found translation " << Dir->d_name << " in " << CD << "i18n/" << std::endl; + file.erase(file.size() - fileext.size()); TransList.push_back(CD + "i18n/" + file); break; } -- cgit v1.2.3 From 711078ae18df09ca4f0c371c071c59458fad3918 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 11 Dec 2011 00:58:35 +0100 Subject: use fileutl exists-functions instead of doing the stat'ing by hand --- apt-pkg/cdrom.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'apt-pkg/cdrom.cc') diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index 026094a6e..f5c19a4d6 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -58,15 +58,14 @@ bool pkgCdrom::FindPackages(string CD, return _error->Errno("chdir","Unable to change to %s",CD.c_str()); // Look for a .disk subdirectory - struct stat Buf; - if (stat(".disk",&Buf) == 0) + if (DirectoryExists(".disk") == true) { if (InfoDir.empty() == true) InfoDir = CD + ".disk/"; } // Don't look into directories that have been marked to ingore. - if (stat(".aptignr",&Buf) == 0) + if (RealFileExists(".aptignr") == true) return true; @@ -74,7 +73,7 @@ bool pkgCdrom::FindPackages(string CD, under a Packages/Source file are in control of that file and stops the scanning */ - if (stat("Release.gpg",&Buf) == 0) + if (RealFileExists("Release.gpg") == true) { SigList.push_back(CD); } @@ -86,7 +85,7 @@ bool pkgCdrom::FindPackages(string CD, for (std::vector::const_iterator c = compressor.begin(); c != compressor.end(); ++c) { - if (stat(std::string("Packages").append(c->Extension).c_str(), &Buf) != 0) + if (RealFileExists(std::string("Packages").append(c->Extension).c_str()) == false) continue; if (_config->FindB("Debug::aptcdrom",false) == true) @@ -101,7 +100,7 @@ bool pkgCdrom::FindPackages(string CD, for (std::vector::const_iterator c = compressor.begin(); c != compressor.end(); ++c) { - if (stat(std::string("Sources").append(c->Extension).c_str(), &Buf) != 0) + if (RealFileExists(std::string("Sources").append(c->Extension).c_str()) == false) continue; if (_config->FindB("Debug::aptcdrom",false) == true) -- cgit v1.2.3 From 212080b87daa25944259287a5a625e63dd696ff0 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 11 Dec 2011 01:30:45 +0100 Subject: * apt-pkg/cdrom.cc: - support InRelease files on cdrom --- apt-pkg/cdrom.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg/cdrom.cc') diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index f5c19a4d6..d9ecdf4f6 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -68,12 +68,11 @@ bool pkgCdrom::FindPackages(string CD, if (RealFileExists(".aptignr") == true) return true; - /* Check _first_ for a signature file as apt-cdrom assumes that all files under a Packages/Source file are in control of that file and stops the scanning */ - if (RealFileExists("Release.gpg") == true) + if (RealFileExists("Release.gpg") == true || RealFileExists("InRelease") == true) { SigList.push_back(CD); } @@ -718,6 +717,7 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/ DropRepeats(List,"Packages"); DropRepeats(SourceList,"Sources"); DropRepeats(SigList,"Release.gpg"); + DropRepeats(SigList,"InRelease"); DropRepeats(TransList,""); if(log != NULL) { msg.str(""); -- cgit v1.2.3 From 2c405a44a0e4ff4c6f40e2521a55811179c87ec3 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 11 Dec 2011 02:55:20 +0100 Subject: add a testcase for FindPackages() to better validate that cdrom should work. Unfortunately it's hard to do an automated integration test with cd, so we test this method in isolation which tries to find Indexes and dropping of duplications with DropRepeats() --- apt-pkg/cdrom.cc | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'apt-pkg/cdrom.cc') diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index d9ecdf4f6..4462d4e24 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -277,6 +277,7 @@ bool pkgCdrom::DropBinaryArch(vector &List) /* Here we go and stat every file that we found and strip dup inodes. */ bool pkgCdrom::DropRepeats(vector &List,const char *Name) { + bool couldFindAllFiles = true; // Get a list of all the inodes ino_t *Inodes = new ino_t[List.size()]; for (unsigned int I = 0; I != List.size(); ++I) @@ -297,21 +298,22 @@ bool pkgCdrom::DropRepeats(vector &List,const char *Name) } if (found == false) - _error->Errno("stat","Failed to stat %s%s",List[I].c_str(), Name); + { + _error->Errno("stat","Failed to stat %s%s",List[I].c_str(), Name); + couldFindAllFiles = false; + Inodes[I] = 0; + } } - if (_error->PendingError() == true) { - delete[] Inodes; - return false; - } - // Look for dups for (unsigned int I = 0; I != List.size(); I++) { + if (Inodes[I] == 0) + continue; for (unsigned int J = I+1; J < List.size(); J++) { // No match - if (Inodes[J] != Inodes[I]) + if (Inodes[J] == 0 || Inodes[J] != Inodes[I]) continue; // We score the two paths.. and erase one @@ -337,7 +339,7 @@ bool pkgCdrom::DropRepeats(vector &List,const char *Name) List.erase(List.begin()+I); } - return true; + return couldFindAllFiles; } /*}}}*/ // ReduceSourceList - Takes the path list and reduces it /*{{{*/ @@ -716,8 +718,13 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/ DropBinaryArch(List); DropRepeats(List,"Packages"); DropRepeats(SourceList,"Sources"); + // FIXME: We ignore stat() errors here as we usually have only one of those in use + // This has little potencial to drop 'valid' stat() errors as we know that one of these + // files need to exist, but it would be better if we would check it here + _error->PushToStack(); DropRepeats(SigList,"Release.gpg"); DropRepeats(SigList,"InRelease"); + _error->RevertToStack(); DropRepeats(TransList,""); if(log != NULL) { msg.str(""); -- cgit v1.2.3