From: Joel Rosdahl Date: Tue, 20 Sep 2022 17:02:18 +0000 (+0200) Subject: feat: Use subsecond resolution timestamps in manifest files X-Git-Tag: v4.7~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2dbf9b5c3d0f1fc6b968597957d4138a507417eb;p=thirdparty%2Fccache.git feat: Use subsecond resolution timestamps in manifest files This improves accuracy in with "file_stat_matches" sloppiness. --- diff --git a/src/core/Manifest.cpp b/src/core/Manifest.cpp index cf4f4fccd..19093c029 100644 --- a/src/core/Manifest.cpp +++ b/src/core/Manifest.cpp @@ -46,8 +46,8 @@ // ::= uint32_t // ::= Digest::size() bytes // ::= uint64_t ; file size -// ::= int64_t ; modification time -// ::= int64_t ; status change time +// ::= int64_t ; modification time (ns), 0 = not recorded +// ::= int64_t ; status change time (ns), 0 = not recorded // ::= * // ::= uint32_t // ::= * @@ -76,6 +76,12 @@ template<> struct hash namespace core { +// Format version history: +// +// Version 0: +// - First version. +// Version 1: +// - mtime and ctime are now stored with nanoseconds resolution. const uint8_t Manifest::k_format_version = 1; void @@ -107,8 +113,8 @@ Manifest::read(nonstd::span data) reader.read_int(entry.index); reader.read_and_copy_bytes({entry.digest.bytes(), Digest::size()}); reader.read_int(entry.fsize); - entry.mtime.set_sec(reader.read_int()); - entry.ctime.set_sec(reader.read_int()); + entry.mtime.set_nsec(reader.read_int()); + entry.ctime.set_nsec(reader.read_int()); } const auto result_count = reader.read_int(); @@ -264,8 +270,8 @@ Manifest::serialize(util::Bytes& output) writer.write_int(file_info.index); writer.write_bytes({file_info.digest.bytes(), Digest::size()}); writer.write_int(file_info.fsize); - writer.write_int(file_info.mtime.sec()); - writer.write_int(file_info.ctime.sec()); + writer.write_int(file_info.mtime.nsec()); + writer.write_int(file_info.ctime.nsec()); } writer.write_int(m_results.size()); @@ -430,15 +436,21 @@ Manifest::inspect(FILE* const stream) const PRINT(stream, " Path index: {}\n", m_file_infos[i].index); PRINT(stream, " Hash: {}\n", m_file_infos[i].digest.to_string()); PRINT(stream, " File size: {}\n", m_file_infos[i].fsize); - if (m_file_infos[i].mtime == util::TimePoint(-1)) { + if (m_file_infos[i].mtime == util::TimePoint()) { PRINT_RAW(stream, " Mtime: -\n"); } else { - PRINT(stream, " Mtime: {}\n", m_file_infos[i].mtime.sec()); + PRINT(stream, + " Mtime: {}.{:09}\n", + m_file_infos[i].mtime.sec(), + m_file_infos[i].mtime.nsec_decimal_part()); } - if (m_file_infos[i].ctime == util::TimePoint(-1)) { + if (m_file_infos[i].ctime == util::TimePoint()) { PRINT_RAW(stream, " Ctime: -\n"); } else { - PRINT(stream, " Ctime: {}\n", m_file_infos[i].ctime.sec()); + PRINT(stream, + " Ctime: {}.{:09}\n", + m_file_infos[i].ctime.sec(), + m_file_infos[i].ctime.nsec_decimal_part()); } }