Skip to content

Commit

Permalink
composefs-from-json: Store mtimes in UTC
Browse files Browse the repository at this point in the history
The time as stored in json includes a timzeone, but for the
erofs value we want to store the time in UTC. Unfortunately the
time apis are kind of lame here, timegm() always assumes the
data in the struct tm is in gmt time. So we have to extract the
gmt offset from the initial strptime call and apply it manually.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
  • Loading branch information
alexlarsson committed Jun 7, 2023
1 parent 169295b commit e062b81
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tools/composefs-from-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,16 @@ static struct lcfs_node_s *get_node(struct lcfs_node_s *root, const char *what)
static void parse_time(const char *time, struct timespec *ts)
{
struct tm tm;
time_t t;
long gmtoff;

memset(&tm, 0, sizeof(tm));
strptime(time, "%Y-%m-%dT%H:%M:%S%z", &tm);
gmtoff = tm.tm_gmtoff;

ts->tv_sec = mktime(&tm);
tm.tm_isdst = -1;
t = timegm(&tm);
ts->tv_sec = t - gmtoff;
ts->tv_nsec = 0;
}

Expand Down Expand Up @@ -667,6 +673,8 @@ int main(int argc, char **argv)
cleanup_free FILE **input_files = NULL;
bool no_sandbox = false;

tzset();

while ((opt = getopt_long(argc, argv, ":CR", longopts, NULL)) != -1) {
switch (opt) {
case OPT_OUT:
Expand Down

0 comments on commit e062b81

Please sign in to comment.