]> git.saurik.com Git - apt.git/commitdiff
avoid changing the global LC_TIME for Release writing
authorDavid Kalnischkies <david@kalnischkies.de>
Sat, 28 May 2016 10:41:12 +0000 (12:41 +0200)
committerJulian Andres Klode <jak@debian.org>
Mon, 14 Nov 2016 14:10:03 +0000 (15:10 +0100)
Using C++ here avoids calling setlocale here which never really was that
ideal, but needed to avoid locale specific weekday/month names.

(cherry picked from commit e0b01a85bd8395449a88e1806ea4a4e3acdbac33)

ftparchive/writer.cc

index 674a8f516ac7da9aec05b3c7b7c5cf4549a77c17..5488a7be26f36bf665428ada301c1fb529e03223 100644 (file)
@@ -37,6 +37,7 @@
 #include <unistd.h>
 #include <ctime>
 #include <iostream>
 #include <unistd.h>
 #include <ctime>
 #include <iostream>
+#include <iomanip>
 #include <sstream>
 #include <memory>
 #include <utility>
 #include <sstream>
 #include <memory>
 #include <utility>
@@ -983,35 +984,29 @@ ReleaseWriter::ReleaseWriter(FileFd * const GivenOutput, string const &/*DB*/) :
    AddPatterns(_config->FindVector("APT::FTPArchive::Release::Patterns"));
 
    time_t const now = time(NULL);
    AddPatterns(_config->FindVector("APT::FTPArchive::Release::Patterns"));
 
    time_t const now = time(NULL);
+   auto const posix = std::locale("C.UTF-8");
 
 
-   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';
-   }
+   // FIXME: use TimeRFC1123 here? But that uses GMT to satisfy HTTP/1.1
+   std::ostringstream datestr;
+   datestr.imbue(posix);
+   datestr << std::put_time(gmtime(&now), "%a, %d %b %Y %H:%M:%S UTC");
 
    time_t const validuntil = now + _config->FindI("APT::FTPArchive::Release::ValidTime", 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)
+   std::ostringstream validstr;
+   if (validuntil != now)
    {
    {
-      validstr[0] = '\0';
+      datestr.imbue(posix);
+      validstr << std::put_time(gmtime(&validuntil), "%a, %d %b %Y %H:%M:%S UTC");
    }
 
    }
 
-   setlocale(LC_TIME, "");
-
    map<string,string> Fields;
    Fields["Origin"] = "";
    Fields["Label"] = "";
    Fields["Suite"] = "";
    Fields["Version"] = "";
    Fields["Codename"] = "";
    map<string,string> Fields;
    Fields["Origin"] = "";
    Fields["Label"] = "";
    Fields["Suite"] = "";
    Fields["Version"] = "";
    Fields["Codename"] = "";
-   Fields["Date"] = datestr;
-   Fields["Valid-Until"] = validstr;
+   Fields["Date"] = datestr.str();
+   Fields["Valid-Until"] = validstr.str();
    Fields["Architectures"] = "";
    Fields["Components"] = "";
    Fields["Description"] = "";
    Fields["Architectures"] = "";
    Fields["Components"] = "";
    Fields["Description"] = "";