]> git.saurik.com Git - apt.git/blobdiff - ftparchive/writer.cc
apply various suggestions made by cppcheck
[apt.git] / ftparchive / writer.cc
index 82049836a2f98ea3b89845602f09a7a80695ef12..c0223a74cd3371375d2faf579e24b1b93c645a50 100644 (file)
@@ -56,7 +56,7 @@ FTWScanner *FTWScanner::Owner;
 // ConfigToDoHashes - which hashes to generate                         /*{{{*/
 static void SingleConfigToDoHashes(unsigned int &DoHashes, std::string const &Conf, unsigned int const Flag)
 {
-   if (_config->FindB(Conf, true) == true)
+   if (_config->FindB(Conf, (DoHashes & Flag) == Flag) == true)
       DoHashes |= Flag;
    else
       DoHashes &= ~Flag;
@@ -71,7 +71,8 @@ static void ConfigToDoHashes(unsigned int &DoHashes, std::string const &Conf)
                                                                        /*}}}*/
 
 // FTWScanner::FTWScanner - Constructor                                        /*{{{*/
-FTWScanner::FTWScanner(FileFd * const GivenOutput, string const &Arch): Arch(Arch), DoHashes(~0)
+FTWScanner::FTWScanner(FileFd * const GivenOutput, string const &Arch, bool const IncludeArchAll)
+   : Arch(Arch), IncludeArchAll(IncludeArchAll), DoHashes(~0)
 {
    if (GivenOutput == NULL)
    {
@@ -301,9 +302,7 @@ bool FTWScanner::Delink(string &FileName,const char *OriginalPath,
               _error->Errno("readlink",_("Failed to readlink %s"),OriginalPath);
            else
            {
-              if (unlink(OriginalPath) != 0)
-                 _error->Errno("unlink",_("Failed to unlink %s"),OriginalPath);
-              else
+              if (RemoveFile("FTWScanner::Delink", OriginalPath))
               {
                  if (link(FileName.c_str(),OriginalPath) != 0)
                  {
@@ -326,6 +325,32 @@ bool FTWScanner::Delink(string &FileName,const char *OriginalPath,
       FileName = OriginalPath;
    }
    
+   return true;
+}
+                                                                       /*}}}*/
+// FTWScanner::SetExts - Set extensions to support                      /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool FTWScanner::SetExts(string const &Vals)
+{
+   ClearPatterns();
+   string::size_type Start = 0;
+   while (Start <= Vals.length()-1)
+   {
+      string::size_type const Space = Vals.find(' ',Start);
+      string::size_type const Length = ((Space == string::npos) ? Vals.length() : Space) - Start;
+      if ( Arch.empty() == false )
+      {
+        AddPattern(string("*_") + Arch + Vals.substr(Start, Length));
+        if (IncludeArchAll == true && Arch != "all")
+           AddPattern(string("*_all") + Vals.substr(Start, Length));
+      }
+      else
+        AddPattern(string("*") + Vals.substr(Start, Length));
+
+      Start += Length + 1;
+   }
+
    return true;
 }
                                                                        /*}}}*/
@@ -335,8 +360,8 @@ bool FTWScanner::Delink(string &FileName,const char *OriginalPath,
 /* */
 PackagesWriter::PackagesWriter(FileFd * const GivenOutput, TranslationWriter * const transWriter,
       string const &DB,string const &Overrides,string const &ExtOverrides,
-      string const &Arch) :
-   FTWScanner(GivenOutput, Arch), Db(DB), Stats(Db.Stats), TransWriter(transWriter)
+      string const &Arch, bool const IncludeArchAll) :
+   FTWScanner(GivenOutput, Arch, IncludeArchAll), Db(DB), Stats(Db.Stats), TransWriter(transWriter)
 {
    SetExts(".deb .udeb");
    DeLinkLimit = 0;
@@ -363,31 +388,6 @@ PackagesWriter::PackagesWriter(FileFd * const GivenOutput, TranslationWriter * c
    _error->DumpErrors();
 }
                                                                         /*}}}*/
-// FTWScanner::SetExts - Set extensions to support                      /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool FTWScanner::SetExts(string const &Vals)
-{
-   ClearPatterns();
-   string::size_type Start = 0;
-   while (Start <= Vals.length()-1)
-   {
-      string::size_type const Space = Vals.find(' ',Start);
-      string::size_type const Length = ((Space == string::npos) ? Vals.length() : Space) - Start;
-      if ( Arch.empty() == false )
-      {
-        AddPattern(string("*_") + Arch + Vals.substr(Start, Length));
-        AddPattern(string("*_all") + Vals.substr(Start, Length));
-      }
-      else
-        AddPattern(string("*") + Vals.substr(Start, Length));
-
-      Start += Length + 1;
-   }
-
-   return true;
-}
-                                                                       /*}}}*/
 // PackagesWriter::DoPackage - Process a single package                        /*{{{*/
 // ---------------------------------------------------------------------
 /* This method takes a package and gets its control information and 
@@ -879,8 +879,9 @@ bool SourcesWriter::DoPackage(string FileName)
 // ContentsWriter::ContentsWriter - Constructor                                /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-ContentsWriter::ContentsWriter(FileFd * const GivenOutput, string const &DB, string const &Arch) :
-                   FTWScanner(GivenOutput, Arch), Db(DB), Stats(Db.Stats)
+ContentsWriter::ContentsWriter(FileFd * const GivenOutput, string const &DB,
+      string const &Arch, bool const IncludeArchAll) :
+                   FTWScanner(GivenOutput, Arch, IncludeArchAll), Db(DB), Stats(Db.Stats)
 
 {
    SetExts(".deb");
@@ -1020,7 +1021,7 @@ ReleaseWriter::ReleaseWriter(FileFd * const GivenOutput, string const &/*DB*/) :
    Fields["Architectures"] = "";
    Fields["Components"] = "";
    Fields["Description"] = "";
-   if (_config->FindB("APT::FTPArchive::DoByHash", true) == true)
+   if (_config->FindB("APT::FTPArchive::DoByHash", false) == true)
       Fields["Acquire-By-Hash"] = "true";
    
    for(map<string,string>::const_iterator I = Fields.begin();
@@ -1076,7 +1077,7 @@ bool ReleaseWriter::DoPackage(string FileName)
 
    // FIXME: wrong layer in the code(?)
    // FIXME2: symlink instead of create a copy
-   if (_config->FindB("APT::FTPArchive::DoByHash", true) == true)
+   if (_config->FindB("APT::FTPArchive::DoByHash", false) == true)
    {
       std::string Input = FileName;
       HashStringList hsl = hs.GetHashStringList();
@@ -1085,8 +1086,10 @@ bool ReleaseWriter::DoPackage(string FileName)
       {
          if (!h->usable())
             continue;
-         std::string ByHashOutputFile = GenByHashFilename(Input, *h);
+         if (flNotDir(FileName) == "Release" || flNotDir(FileName) == "InRelease")
+            continue;
 
+         std::string ByHashOutputFile = GenByHashFilename(Input, *h);
          std::string ByHashOutputDir = flNotFile(ByHashOutputFile);
          if(!CreateDirectory(flNotFile(Input), ByHashOutputDir))
             return _error->Warning("can not create dir %s", flNotFile(ByHashOutputFile).c_str());
@@ -1139,7 +1142,7 @@ void ReleaseWriter::Finish()
 
    // go by-hash cleanup
    map<string,ReleaseWriter::CheckSum>::const_iterator prev = CheckSums.begin();
-   if (_config->FindB("APT::FTPArchive::DoByHash", true) == true)
+   if (_config->FindB("APT::FTPArchive::DoByHash", false) == true)
    {
       for(map<string,ReleaseWriter::CheckSum>::const_iterator I = CheckSums.begin();
         I != CheckSums.end(); ++I)