pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathandbossart@gmail.com>
To: pgsql-hackers@postgresql.org
Subject: thinko in basic_archive.c
Date: Thu, 13 Oct 2022 21:41:06 -0700
Message-ID: <20221014044106.GA1673343@nathanxps13> (raw)

Hi hackers,

I intended for the temporary file name generated by basic_archive.c to
include the current timestamp so that the name was "sufficiently unique."
Of course, this could also be used to determine the creation time, but you
can just as easily use stat(1) for that.  In any case, I forgot to divide
the microseconds field by 1000 to obtain the current timestamp in
milliseconds, so while the value is unique, it's also basically garbage.
I've attached a small patch that fixes this so that the temporary file name
includes the timestamp in milliseconds for when it was created.

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

Attachments:

fix_basic_archive_timestamp.patch (text/x-diff, 665B) download diff --git a/contrib/basic_archive/basic_archive.c b/contrib/basic_archive/basic_archive.c index 776a386e35..a02708fc12 100644 --- a/contrib/basic_archive/basic_archive.c +++ b/contrib/basic_archive/basic_archive.c @@ -265,7 +265,7 @@ basic_archive_file_internal(const char *file, const char *path) */ gettimeofday(&tv, NULL); if (pg_mul_u64_overflow((uint64) 1000, (uint64) tv.tv_sec, &epoch) || - pg_add_u64_overflow(epoch, (uint64) tv.tv_usec, &epoch)) + pg_add_u64_overflow(epoch, (uint64) tv.tv_usec / 1000, &epoch)) elog(ERROR, "could not generate temporary file name for archiving"); snprintf(temp, sizeof(temp), "%s/%s.%s.%d." UINT64_FORMAT,

view thread (21+ messages)  latest in thread

Message-ID: <20221014044106.GA1673343@nathanxps13>
Permalink:  ../20221014044106.GA1673343@nathanxps13/
Also on:    postgresql.org/message-id/20221014044106.GA1673343@nathanxps13

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: nathandbossart@gmail.com
  Subject: Re: thinko in basic_archive.c
  In-Reply-To: <20221014044106.GA1673343@nathanxps13>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox