X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/e0b01a85bd8395449a88e1806ea4a4e3acdbac33..0b23d3c0a7a116a19c14ae63b6281464ba1382a4:/ftparchive/writer.cc diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index 1036ce0b8..eb17521eb 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -967,6 +967,19 @@ 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) @@ -979,6 +992,7 @@ ReleaseWriter::ReleaseWriter(FileFd * const GivenOutput, string const &/*DB*/) : AddPattern("Release"); AddPattern("Contents-*"); AddPattern("Index"); + AddPattern("Index.*"); AddPattern("icons-*.tar"); AddPattern("icons-*.tar.*"); AddPattern("Components-*.yml"); @@ -988,46 +1002,48 @@ ReleaseWriter::ReleaseWriter(FileFd * const GivenOutput, string const &/*DB*/) : AddPatterns(_config->FindVector("APT::FTPArchive::Release::Patterns")); time_t const now = time(NULL); - auto const posix = std::locale("C.UTF-8"); - - // 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); - std::ostringstream validstr; - if (validuntil != now) - { - datestr.imbue(posix); - validstr << std::put_time(gmtime(&validuntil), "%a, %d %b %Y %H:%M:%S UTC"); - } + map BoolFields; map Fields; Fields["Origin"] = ""; Fields["Label"] = ""; Fields["Suite"] = ""; Fields["Version"] = ""; Fields["Codename"] = ""; - Fields["Date"] = datestr.str(); - Fields["Valid-Until"] = validstr.str(); + Fields["Date"] = formatUTCDateTime(now); + if (validuntil != now) + Fields["Valid-Until"] = formatUTCDateTime(validuntil); Fields["Architectures"] = ""; Fields["Components"] = ""; Fields["Description"] = ""; Fields["Signed-By"] = ""; - if (_config->FindB("APT::FTPArchive::DoByHash", false) == true) - Fields["Acquire-By-Hash"] = "true"; - - for(map::const_iterator I = Fields.begin(); - I != Fields.end(); - ++I) + 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()); }