Skip to content

Commit e21eae3

Browse files
authored
Merge pull request ceph#55644 from linuxbox2/wip-rgw-dtexpire
rgw_lc: replace strftime w/fmt and chrono:calendar Reviewed-by: Daniel Gryniewicz <[email protected]>
2 parents a29b00d + 96a5cbb commit e21eae3

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/rgw/rgw_lc.cc

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
22
// vim: ts=8 sw=2 smarttab ft=cpp
33

4+
#include <fmt/chrono.h>
45
#include <string.h>
56
#include <iostream>
67
#include <map>
@@ -2821,18 +2822,11 @@ std::string s3_expiration_header(
28212822

28222823
// cond format header
28232824
if (expiration_date && rule_id) {
2824-
// Fri, 23 Dec 2012 00:00:00 GMT
2825-
char exp_buf[100];
2826-
time_t exp = ceph::real_clock::to_time_t(*expiration_date);
2827-
if (std::strftime(exp_buf, sizeof(exp_buf),
2828-
"%a, %d %b %Y %T %Z", std::gmtime(&exp))) {
2829-
hdr = fmt::format("expiry-date=\"{0}\", rule-id=\"{1}\"", exp_buf,
2830-
*rule_id);
2831-
} else {
2832-
ldpp_dout(dpp, 0) << __func__ <<
2833-
"() strftime of life cycle expiration header failed"
2834-
<< dendl;
2835-
}
2825+
auto exp = ceph::real_clock::to_time_t(*expiration_date);
2826+
// Fri, 21 Dec 2012 00:00:00 GMT
2827+
auto exp_str = fmt::format("{:%a, %d %b %Y %T %Z}", fmt::gmtime(exp));
2828+
hdr = fmt::format("expiry-date=\"{0}\", rule-id=\"{1}\"", exp_str,
2829+
*rule_id);
28362830
}
28372831

28382832
return hdr;

src/test/rgw/test_rgw_lc.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <gtest/gtest.h>
88
#include <string>
99
#include <vector>
10+
#include <chrono>
1011
#include <stdexcept>
1112

1213
static const char* xmldoc_1 =
@@ -107,6 +108,17 @@ TEST(TestLCFilterInvalidAnd, XMLDoc3)
107108
ASSERT_EQ(filter.get_flags(), uint32_t(LCFlagType::none));
108109
}
109110

111+
TEST(ExpHdr, ReplaceStrftime)
112+
{
113+
using namespace std::chrono;
114+
115+
constexpr auto dec21 = year(2012)/12/21;
116+
auto exp = sys_days(dec21) + 9h + 13min + 7s ;
117+
auto exp_str = fmt::format("{:%a, %d %b %Y %T %Z}", fmt::gmtime(exp));
118+
std::cout << "exp_str: " << exp_str << std::endl;
119+
ASSERT_EQ(exp_str, "Fri, 21 Dec 2012 09:13:07 GMT");
120+
}
121+
110122
struct LCWorkTimeTests : ::testing::Test
111123
{
112124
CephContext* cct;

0 commit comments

Comments
 (0)