@@ -941,19 +941,22 @@ namespace vix::commands::RunCommand::detail
941941 // ===========================================================================
942942
943943 /* *
944- * @brief Return the file modification time as Unix nanoseconds .
944+ * @brief Return a stable, order-preserving file modification timestamp .
945945 *
946- * std::filesystem::file_time_type may use a clock whose epoch differs from
947- * std::chrono::system_clock. Converting file_time_type::time_since_epoch()
948- * directly to an unsigned Unix timestamp is therefore not portable and can
949- * yield negative values for perfectly valid files.
946+ * std::filesystem::file_time_type may use an implementation-defined epoch,
947+ * so its timestamp must not be interpreted directly as a Unix timestamp.
950948 *
951- * This helper translates the filesystem clock to system_clock before
952- * producing a nanosecond timestamp.
949+ * For cache fingerprints we need the value to be stable across repeated
950+ * reads of the same file. For timestamp comparisons we also need the encoded
951+ * unsigned value to preserve the ordering of the underlying signed
952+ * filesystem-clock timestamp.
953+ *
954+ * Flipping the sign bit maps the signed nanosecond representation into an
955+ * unsigned value while preserving chronological ordering.
953956 *
954957 * @param p File whose modification time should be queried.
955958 * @param ec Receives any filesystem error.
956- * @return Modification time in Unix nanoseconds , or 0 on failure.
959+ * @return Stable encoded modification timestamp , or 0 on failure.
957960 */
958961 inline std::uint64_t file_mtime_ns (
959962 const fs::path &p,
@@ -971,26 +974,16 @@ namespace vix::commands::RunCommand::detail
971974
972975 using namespace std ::chrono;
973976
974- const auto fileNow =
975- fs::file_time_type::clock::now ();
976-
977- const auto systemNow =
978- system_clock::now ();
979-
980- const auto systemTime =
981- systemNow +
982- duration_cast<system_clock::duration>(
983- fileTime - fileNow);
984-
985977 const auto ns =
986978 duration_cast<nanoseconds>(
987- systemTime .time_since_epoch ())
979+ fileTime .time_since_epoch ())
988980 .count ();
989981
990- if (ns <= 0 )
991- return 0 ;
982+ const auto signedNs =
983+ static_cast <std:: int64_t >(ns) ;
992984
993- return static_cast <std::uint64_t >(ns);
985+ return static_cast <std::uint64_t >(signedNs) ^
986+ (std::uint64_t {1 } << 63 );
994987 }
995988
996989 /* *
0 commit comments