summaryrefslogtreecommitdiff
path: root/ftparchive
diff options
context:
space:
mode:
Diffstat (limited to 'ftparchive')
-rw-r--r--ftparchive/apt-ftparchive.cc36
-rw-r--r--ftparchive/apt-ftparchive.h1
-rw-r--r--ftparchive/byhash.cc8
-rw-r--r--ftparchive/cachedb.cc14
-rw-r--r--ftparchive/cachedb.h6
-rw-r--r--ftparchive/contents.h2
-rw-r--r--ftparchive/multicompress.cc89
-rw-r--r--ftparchive/multicompress.h2
-rw-r--r--ftparchive/override.cc6
-rw-r--r--ftparchive/override.h2
-rw-r--r--ftparchive/sources.cc2
-rw-r--r--ftparchive/writer.cc24
-rw-r--r--ftparchive/writer.h10
13 files changed, 91 insertions, 111 deletions
diff --git a/ftparchive/apt-ftparchive.cc b/ftparchive/apt-ftparchive.cc
index ab6f48d61..196a0668c 100644
--- a/ftparchive/apt-ftparchive.cc
+++ b/ftparchive/apt-ftparchive.cc
@@ -12,33 +12,33 @@
// Include Files /*{{{*/
#include <config.h>
-#include <apt-pkg/error.h>
-#include <apt-pkg/configuration.h>
#include <apt-pkg/cmndline.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/init.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
+#include <apt-pkg/init.h>
+#include <apt-pkg/strutl.h>
#include <apt-private/private-cmndline.h>
-#include <apt-private/private-output.h>
#include <apt-private/private-main.h>
+#include <apt-private/private-output.h>
#include <algorithm>
#include <climits>
-#include <sys/time.h>
-#include <locale.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <time.h>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
+#include <locale.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <time.h>
-#include "cachedb.h"
-#include "override.h"
#include "apt-ftparchive.h"
+#include "cachedb.h"
#include "multicompress.h"
+#include "override.h"
#include "writer.h"
#include <apti18n.h>
@@ -1002,7 +1002,7 @@ static bool Clean(CommandLine &CmdL)
stable_sort(PkgList.begin(),PkgList.end(),PackageMap::SrcDBCompare());
string CacheDir = Setup.FindDir("Dir::CacheDir");
-
+
for (vector<PackageMap>::iterator I = PkgList.begin(); I != PkgList.end(); )
{
if(I->BinCacheDB != "")
@@ -1016,15 +1016,11 @@ static bool Clean(CommandLine &CmdL)
if (DB_SRC.Clean() == false)
_error->DumpErrors();
- string CacheDB = I->BinCacheDB;
- string SrcCacheDB = I->SrcCacheDB;
- while(I != PkgList.end() &&
- I->BinCacheDB == CacheDB &&
- I->SrcCacheDB == SrcCacheDB)
- ++I;
+ I = std::find_if(I, PkgList.end(),
+ [&](PackageMap const &PM) { return PM.BinCacheDB != I->BinCacheDB || PM.SrcCacheDB != I->SrcCacheDB;
+ });
}
-
return true;
}
/*}}}*/
diff --git a/ftparchive/apt-ftparchive.h b/ftparchive/apt-ftparchive.h
index 240cf9ba7..b1ce17545 100644
--- a/ftparchive/apt-ftparchive.h
+++ b/ftparchive/apt-ftparchive.h
@@ -13,7 +13,6 @@
#ifndef APT_FTPARCHIVE_H
#define APT_FTPARCHIVE_H
-
#include <fstream>
using std::ostream;
diff --git a/ftparchive/byhash.cc b/ftparchive/byhash.cc
index 354d089c3..b24f6158e 100644
--- a/ftparchive/byhash.cc
+++ b/ftparchive/byhash.cc
@@ -11,15 +11,15 @@
// Include Files /*{{{*/
#include <config.h>
-#include<algorithm>
-#include<string>
+#include <algorithm>
+#include <string>
-#include <unistd.h>
#include <sys/stat.h>
+#include <unistd.h>
+#include "byhash.h"
#include <apt-pkg/fileutl.h>
#include <apt-pkg/hashes.h>
-#include "byhash.h"
// Delete all files in a directory except the most recent N ones
void DeleteAllButMostRecent(std::string dir, int KeepFiles)
diff --git a/ftparchive/cachedb.cc b/ftparchive/cachedb.cc
index 868029abd..210ce6dc1 100644
--- a/ftparchive/cachedb.cc
+++ b/ftparchive/cachedb.cc
@@ -12,22 +12,22 @@
// Include Files /*{{{*/
#include <config.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/debfile.h>
#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/gpgv.h>
+#include <apt-pkg/hashes.h>
#include <apt-pkg/md5.h>
#include <apt-pkg/sha1.h>
#include <apt-pkg/sha2.h>
#include <apt-pkg/strutl.h>
-#include <apt-pkg/configuration.h>
-#include <apt-pkg/fileutl.h>
-#include <apt-pkg/debfile.h>
-#include <apt-pkg/gpgv.h>
-#include <apt-pkg/hashes.h>
-#include <netinet/in.h> // htonl, etc
#include <ctype.h>
+#include <netinet/in.h> // htonl, etc
#include <stddef.h>
-#include <sys/stat.h>
#include <strings.h>
+#include <sys/stat.h>
#include "cachedb.h"
diff --git a/ftparchive/cachedb.h b/ftparchive/cachedb.h
index 417c25a9f..117ba5a1b 100644
--- a/ftparchive/cachedb.h
+++ b/ftparchive/cachedb.h
@@ -12,15 +12,15 @@
#ifndef CACHEDB_H
#define CACHEDB_H
-#include <apt-pkg/hashes.h>
#include <apt-pkg/debfile.h>
+#include <apt-pkg/hashes.h>
#include <db.h>
-#include <errno.h>
#include <string>
-#include <string.h>
+#include <errno.h>
#include <stdint.h>
#include <stdio.h>
+#include <string.h>
#include "contents.h"
#include "sources.h"
diff --git a/ftparchive/contents.h b/ftparchive/contents.h
index bc691d473..8691b0e87 100644
--- a/ftparchive/contents.h
+++ b/ftparchive/contents.h
@@ -12,9 +12,9 @@
#include <apt-pkg/dirstream.h>
+#include <string>
#include <stddef.h>
#include <stdio.h>
-#include <string>
class debDebFile;
class FileFd;
diff --git a/ftparchive/multicompress.cc b/ftparchive/multicompress.cc
index 3ffc5266e..abb8c5906 100644
--- a/ftparchive/multicompress.cc
+++ b/ftparchive/multicompress.cc
@@ -16,26 +16,43 @@
// Include Files /*{{{*/
#include <config.h>
-#include <apt-pkg/fileutl.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/error.h>
-#include <apt-pkg/md5.h>
#include <apt-pkg/aptconfiguration.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
#include <apt-pkg/hashsum_template.h>
+#include <apt-pkg/md5.h>
+#include <apt-pkg/strutl.h>
#include <ctype.h>
-#include <vector>
-#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <sys/types.h>
#include <unistd.h>
+#include <algorithm>
+#include <vector>
+
#include "multicompress.h"
#include <apti18n.h>
/*}}}*/
using namespace std;
+static std::vector<APT::Configuration::Compressor>::const_iterator findMatchingCompressor(std::string::const_iterator &I,
+ std::string::const_iterator const &End, std::vector<APT::Configuration::Compressor> const &Compressors)
+{
+ // Grab a word (aka: a compressor name)
+ for (; I != End && isspace(*I); ++I);
+ string::const_iterator Start = I;
+ for (; I != End && !isspace(*I); ++I);
+
+ auto const Comp = std::find_if(Compressors.begin(), Compressors.end(),
+ [&](APT::Configuration::Compressor const &C) { return stringcmp(Start, I, C.Name.c_str()) == 0;
+ });
+ if (Comp == Compressors.end())
+ _error->Warning(_("Unknown compression algorithm '%s'"),string(Start,I).c_str());
+ return Comp;
+}
// MultiCompress::MultiCompress - Constructor /*{{{*/
// ---------------------------------------------------------------------
@@ -48,38 +65,21 @@ MultiCompress::MultiCompress(string const &Output,string const &Compress,
Outputter = -1;
UpdateMTime = 0;
- /* Parse the compression string, a space separated lists of compresison
- types */
- string::const_iterator I = Compress.begin();
- for (; I != Compress.end();)
+ auto const Compressors = APT::Configuration::getCompressors();
+ // Parse the compression string, a space separated lists of compression types
+ for (auto I = Compress.cbegin(); I != Compress.cend();)
{
- for (; I != Compress.end() && isspace(*I); ++I);
-
- // Grab a word
- string::const_iterator Start = I;
- for (; I != Compress.end() && !isspace(*I); ++I);
-
- // Find the matching compressor
- std::vector<APT::Configuration::Compressor> Compressors = APT::Configuration::getCompressors();
- std::vector<APT::Configuration::Compressor>::const_iterator Comp = Compressors.begin();
- for (; Comp != Compressors.end(); ++Comp)
- if (stringcmp(Start,I,Comp->Name.c_str()) == 0)
- break;
-
- // Hmm.. unknown.
+ auto const Comp = findMatchingCompressor(I, Compress.cend(), Compressors);
if (Comp == Compressors.end())
- {
- _error->Warning(_("Unknown compression algorithm '%s'"),string(Start,I).c_str());
continue;
- }
-
- // Create and link in a new output
+
+ // Create and link in a new output
Files *NewOut = new Files;
NewOut->Next = Outputs;
Outputs = NewOut;
NewOut->CompressProg = *Comp;
- NewOut->Output = Output+Comp->Extension;
-
+ NewOut->Output = Output + Comp->Extension;
+
struct stat St;
if (stat(NewOut->Output.c_str(),&St) == 0)
NewOut->OldMTime = St.st_mtime;
@@ -128,34 +128,21 @@ MultiCompress::~MultiCompress()
one or more of the files is missing. */
bool MultiCompress::GetStat(string const &Output,string const &Compress,struct stat &St)
{
- /* Parse the compression string, a space separated lists of compresison
- types */
- string::const_iterator I = Compress.begin();
+ auto const Compressors = APT::Configuration::getCompressors();
+
+ // Parse the compression string, a space separated lists of compression types
bool DidStat = false;
- for (; I != Compress.end();)
+ for (auto I = Compress.cbegin(); I != Compress.cend();)
{
- for (; I != Compress.end() && isspace(*I); ++I);
-
- // Grab a word
- string::const_iterator Start = I;
- for (; I != Compress.end() && !isspace(*I); ++I);
-
- // Find the matching compressor
- std::vector<APT::Configuration::Compressor> Compressors = APT::Configuration::getCompressors();
- std::vector<APT::Configuration::Compressor>::const_iterator Comp = Compressors.begin();
- for (; Comp != Compressors.end(); ++Comp)
- if (stringcmp(Start,I,Comp->Name.c_str()) == 0)
- break;
-
- // Hmm.. unknown.
+ auto const Comp = findMatchingCompressor(I, Compress.cend(), Compressors);
if (Comp == Compressors.end())
continue;
- string Name = Output+Comp->Extension;
+ string Name = Output + Comp->Extension;
if (stat(Name.c_str(),&St) != 0)
return false;
DidStat = true;
- }
+ }
return DidStat;
}
/*}}}*/
diff --git a/ftparchive/multicompress.h b/ftparchive/multicompress.h
index 161716b86..50453acab 100644
--- a/ftparchive/multicompress.h
+++ b/ftparchive/multicompress.h
@@ -16,8 +16,8 @@
#ifndef MULTICOMPRESS_H
#define MULTICOMPRESS_H
-#include <apt-pkg/fileutl.h>
#include <apt-pkg/aptconfiguration.h>
+#include <apt-pkg/fileutl.h>
#include <string>
#include <stdio.h>
diff --git a/ftparchive/override.cc b/ftparchive/override.cc
index 8a0c5bab1..26d629bfa 100644
--- a/ftparchive/override.cc
+++ b/ftparchive/override.cc
@@ -12,13 +12,13 @@
// Include Files /*{{{*/
#include <config.h>
-#include <apt-pkg/strutl.h>
#include <apt-pkg/error.h>
+#include <apt-pkg/strutl.h>
-#include <stdio.h>
+#include <utility>
#include <ctype.h>
+#include <stdio.h>
#include <string.h>
-#include <utility>
#include "override.h"
diff --git a/ftparchive/override.h b/ftparchive/override.h
index c5cacc2b4..74637404c 100644
--- a/ftparchive/override.h
+++ b/ftparchive/override.h
@@ -12,8 +12,6 @@
#ifndef OVERRIDE_H
#define OVERRIDE_H
-
-
#include <map>
#include <string>
diff --git a/ftparchive/sources.cc b/ftparchive/sources.cc
index ab976b490..60a86171f 100644
--- a/ftparchive/sources.cc
+++ b/ftparchive/sources.cc
@@ -1,5 +1,5 @@
-#include <string>
#include <sstream>
+#include <string>
// for memcpy
#include <cstring>
diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc
index cac1d943d..d5c9735e7 100644
--- a/ftparchive/writer.cc
+++ b/ftparchive/writer.cc
@@ -14,19 +14,26 @@
#include <config.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/debfile.h>
#include <apt-pkg/deblistparser.h>
#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/gpgv.h>
#include <apt-pkg/hashes.h>
#include <apt-pkg/md5.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/debfile.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/sha1.h>
#include <apt-pkg/sha2.h>
+#include <apt-pkg/strutl.h>
#include <apt-pkg/tagfile.h>
+#include <algorithm>
+#include <ctime>
+#include <iomanip>
+#include <iostream>
+#include <memory>
+#include <sstream>
+#include <utility>
#include <ctype.h>
#include <fnmatch.h>
#include <ftw.h>
@@ -35,19 +42,12 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
-#include <ctime>
-#include <iostream>
-#include <iomanip>
-#include <sstream>
-#include <memory>
-#include <utility>
-#include <algorithm>
#include "apt-ftparchive.h"
-#include "writer.h"
+#include "byhash.h"
#include "cachedb.h"
#include "multicompress.h"
-#include "byhash.h"
+#include "writer.h"
#include <apti18n.h>
/*}}}*/
@@ -417,7 +417,7 @@ bool PackagesWriter::DoPackage(string FileName)
string Architecture;
// if we generate a Packages file for a given arch, we use it to
// look for overrides. if we run in "simple" mode without the
- // "Architecures" variable in the config we use the architecure value
+ // "Architecures" variable in the config we use the architecture value
// from the deb file
if(Arch != "")
Architecture = Arch;
diff --git a/ftparchive/writer.h b/ftparchive/writer.h
index ea4c66da4..b2cef4f00 100644
--- a/ftparchive/writer.h
+++ b/ftparchive/writer.h
@@ -15,19 +15,19 @@
#include <apt-pkg/hashes.h>
-#include <string>
-#include <stdio.h>
#include <iostream>
-#include <vector>
#include <map>
#include <set>
+#include <string>
+#include <vector>
+#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
-#include "contents.h"
+#include "apt-ftparchive.h"
#include "cachedb.h"
+#include "contents.h"
#include "override.h"
-#include "apt-ftparchive.h"
using std::string;
using std::cout;