]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Drop microsecond resolution for datetime.now()
authorAlberto Planas <aplanas@suse.com>
Wed, 6 Aug 2025 10:58:55 +0000 (12:58 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 7 Aug 2025 11:06:50 +0000 (12:06 +0100)
The RPM INSTALLTIME attribute is an integer represetantion of the
installation time of the package, and datetime.now is a date
representation of a float timestamp.  This can produce some rounding
errors is powerful build servers.

For example, if the variable `_init_timestamp` has a value XXXXX.1 but
in the same sub-second the package gets installed, the registered
installation time will be the integer representation (XXXXX), making the
comparison done for exclusion of the package to be `True`.

This patch will remove the microsecond granularity of the datetime,
converting the timestamp on its integer representation, instead of the
default float one.  The comparison is still done in the datetime data
type.

Signed-off-by: Alberto Planas <aplanas@suse.com>
mkosi/manifest.py

index 56bdd16d82adb576c7db2ef26a4d401bfc8e6f43..9ef6aed96398191d706074c46699f68a93af254a 100644 (file)
@@ -69,7 +69,9 @@ class Manifest:
     packages: list[PackageManifest] = dataclasses.field(default_factory=list)
     source_packages: dict[str, SourcePackageManifest] = dataclasses.field(default_factory=dict)
 
-    _init_timestamp: datetime.datetime = dataclasses.field(init=False, default_factory=datetime.datetime.now)
+    _init_timestamp: datetime.datetime = dataclasses.field(
+        init=False, default_factory=lambda: datetime.datetime.now().replace(microsecond=0)
+    )
 
     def need_source_info(self) -> bool:
         return ManifestFormat.changelog in self.context.config.manifest_format