]> git.saurik.com Git - apt.git/blobdiff - ftparchive/writer.cc
get pdiff files from the same mirror as the index
[apt.git] / ftparchive / writer.cc
index 0bd2be566fa8a59916a202d6967b5f6bbbc20f6a..eb17521eb9938f55a40ebe615a72a243b656eda3 100644 (file)
@@ -37,6 +37,7 @@
 #include <unistd.h>
 #include <ctime>
 #include <iostream>
+#include <iomanip>
 #include <sstream>
 #include <memory>
 #include <utility>
@@ -302,9 +303,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)
                  {
@@ -625,12 +624,12 @@ SourcesWriter::SourcesWriter(FileFd * const GivenOutput, string const &DB, strin
 // SourcesWriter::DoPackage - Process a single package                 /*{{{*/
 static std::string getDscHash(unsigned int const DoHashes,
       Hashes::SupportedHashes const DoIt, pkgTagSection &Tags, char const * const FieldName,
-      HashString const * const Hash, unsigned long long Size, std::string FileName)
+      HashString const * const Hash, unsigned long long Size, std::string const &FileName)
 {
    if ((DoHashes & DoIt) != DoIt || Tags.Exists(FieldName) == false || Hash == NULL)
       return "";
    std::ostringstream out;
-   out << "\n " << Hash->HashValue() << " " << Size << " " << FileName
+   out << "\n " << Hash->HashValue() << " " << std::to_string(Size) << " " << FileName
       << "\n " << Tags.FindS(FieldName);
    return out.str();
 }
@@ -804,7 +803,7 @@ bool SourcesWriter::DoPackage(string FileName)
            if (Tags.Exists(fieldname) == true)
               continue;
            std::ostringstream streamout;
-           streamout << "\n " << hs->HashValue() << " " << Db.GetFileSize() << " " << ParseJnk;
+           streamout << "\n " << hs->HashValue() << " " << std::to_string(Db.GetFileSize()) << " " << ParseJnk;
            out->append(streamout.str());
         }
 
@@ -968,74 +967,83 @@ bool ContentsWriter::ReadFromPkgs(string const &PkgFile,string const &PkgCompres
 // ReleaseWriter::ReleaseWriter - Constructor                          /*{{{*/
 // ---------------------------------------------------------------------
 /* */
+static std::string formatUTCDateTime(time_t const now)
+{
+   bool const NumericTimezone = _config->FindB("APT::FTPArchive::Release::NumericTimezone", true);
+   // TimeRFC1123 uses GMT to satisfy HTTP/1.1
+   std::string datetime = TimeRFC1123(now, NumericTimezone);
+   if (NumericTimezone == false)
+   {
+      auto const lastspace = datetime.rfind(' ');
+      if (likely(lastspace != std::string::npos))
+        datetime.replace(lastspace + 1, 3, "UTC");
+   }
+   return datetime;
+}
 ReleaseWriter::ReleaseWriter(FileFd * const GivenOutput, string const &/*DB*/) : FTWScanner(GivenOutput)
 {
    if (_config->FindB("APT::FTPArchive::Release::Default-Patterns", true) == true)
    {
       AddPattern("Packages");
-      AddPattern("Packages.gz");
-      AddPattern("Packages.bz2");
-      AddPattern("Packages.lzma");
-      AddPattern("Packages.xz");
+      AddPattern("Packages.*");
       AddPattern("Translation-*");
       AddPattern("Sources");
-      AddPattern("Sources.gz");
-      AddPattern("Sources.bz2");
-      AddPattern("Sources.lzma");
-      AddPattern("Sources.xz");
+      AddPattern("Sources.*");
       AddPattern("Release");
       AddPattern("Contents-*");
       AddPattern("Index");
+      AddPattern("Index.*");
+      AddPattern("icons-*.tar");
+      AddPattern("icons-*.tar.*");
+      AddPattern("Components-*.yml");
+      AddPattern("Components-*.yml.*");
       AddPattern("md5sum.txt");
    }
    AddPatterns(_config->FindVector("APT::FTPArchive::Release::Patterns"));
 
    time_t const now = time(NULL);
-
-   setlocale(LC_TIME, "C");
-
-   char datestr[128];
-   if (strftime(datestr, sizeof(datestr), "%a, %d %b %Y %H:%M:%S UTC",
-                gmtime(&now)) == 0)
-   {
-      datestr[0] = '\0';
-   }
-
    time_t const validuntil = now + _config->FindI("APT::FTPArchive::Release::ValidTime", 0);
-   char validstr[128];
-   if (now == validuntil ||
-       strftime(validstr, sizeof(validstr), "%a, %d %b %Y %H:%M:%S UTC",
-                gmtime(&validuntil)) == 0)
-   {
-      validstr[0] = '\0';
-   }
-
-   setlocale(LC_TIME, "");
 
+   map<string,bool> BoolFields;
    map<string,string> Fields;
    Fields["Origin"] = "";
    Fields["Label"] = "";
    Fields["Suite"] = "";
    Fields["Version"] = "";
    Fields["Codename"] = "";
-   Fields["Date"] = datestr;
-   Fields["Valid-Until"] = validstr;
+   Fields["Date"] = formatUTCDateTime(now);
+   if (validuntil != now)
+      Fields["Valid-Until"] = formatUTCDateTime(validuntil);
    Fields["Architectures"] = "";
    Fields["Components"] = "";
    Fields["Description"] = "";
-   if (_config->FindB("APT::FTPArchive::DoByHash", false) == true)
-      Fields["Acquire-By-Hash"] = "true";
-   
-   for(map<string,string>::const_iterator I = Fields.begin();
-       I != Fields.end();
-       ++I)
+   Fields["Signed-By"] = "";
+   BoolFields["Acquire-By-Hash"] = _config->FindB("APT::FTPArchive::DoByHash", false);
+   BoolFields["NotAutomatic"] = false;
+   BoolFields["ButAutomaticUpgrades"] = false;
+
+   // Read configuration for string fields, but don't output them
+   for (auto &&I : Fields)
    {
-      string Config = string("APT::FTPArchive::Release::") + (*I).first;
-      string Value = _config->Find(Config, (*I).second.c_str());
-      if (Value == "")
-         continue;
+      string Config = string("APT::FTPArchive::Release::") + I.first;
+      I.second = _config->Find(Config, I.second);
+   }
 
-      std::string const out = I->first + ": " + Value + "\n";
+   // Read configuration for bool fields, and add them to Fields if true
+   for (auto &&I : BoolFields)
+   {
+      string Config = string("APT::FTPArchive::Release::") + I.first;
+      I.second = _config->FindB(Config, I.second);
+      if (I.second)
+         Fields[I.first] = "yes";
+   }
+
+   // All configuration read and stored in Fields; output
+   for (auto &&I : Fields)
+   {
+      if (I.second.empty())
+         continue;
+      std::string const out = I.first + ": " + I.second + "\n";
       Output->Write(out.c_str(), out.length());
    }