File rpm-4.20-sde-mtime.patch of Package rpm
commit b91aec866c4be289c451fc4abeb29d3079f90703
Author: Bernhard M. Wiedemann <bwiedemann@suse.de>
Date: Mon Apr 21 17:01:01 2025 +0200
Add an option to use a different mtime
File mtimes are required to increase with new versions and releases
of an rpm with the same name, as rsync without --checksum and similar
tools would get confused if the content changes without newer mtime.
If SOURCE_DATE_EPOCH_MTIME is set, use it instead for file modification time
stamps. It is supposed to be newer. This can be used if we might want to
compare if the file content remains the same when a build dependency
changes while a build script embeds SOURCE_DATE_EPOCH in the file
content.
This can be used to support automatic rebuilds. Normally automatic
rebuilds work, but together with reproducible builds an undesirable
situation may occur. If a build embeds SOURCE_DATE_EPOCH in the
output, then the output changes every time such a rebuild happens, which
can be very often. This is to be avoided as updating packages without
necessity is too expensive.
Co-Authored-By: Jan Zerebecki <jan.suse@zerebecki.de>
diff --git a/build/files.cc b/build/files.cc
index 4e8960488..4427e2b8e 100644
--- build/files.c
+++ build/files.c
@@ -1022,8 +1022,20 @@ static void genCpioListAndHeader(FileList fl, rpmSpec spec, Package pkg, int isS
int override_date = 0;
time_t mtime_clamp = 0;
char *srcdate = getenv("SOURCE_DATE_EPOCH");
+ char *msrcdate = getenv("SOURCE_DATE_EPOCH_MTIME");
char *mtime_policy_str = rpmExpand("%{?build_mtime_policy}", NULL);
+ /* If SOURCE_DATE_EPOCH_MTIME is set, use it for file modification time
+ * stamps, it is supposed to be newer. This can be used if we might want to
+ * compare if the file content remains the same when a build dependency
+ * changes while a build script embeds SOURCE_DATE_EPOCH in the file
+ * content. mtimes are required to increase with new versions and releases
+ * of an rpm with the same name, as rsync without --checksum and similar
+ * tools would get confused if the content changes without newer mtime. */
+ if (msrcdate != NULL) {
+ srcdate = msrcdate;
+ }
+
/* backward compatibility */
if (!*mtime_policy_str) {
if (srcdate && rpmExpandNumeric("%{?clamp_mtime_to_source_date_epoch}")) {