Skip to content

Commit fd265e0

Browse files
committed
RPM: workaround timezone bug in spec parsing
The RPM library change the timezone when parsing spec file but old versions of this library (<4.19) miss to restore the timezone properly. This has the side effect to change the timezone for the end of Rift execution, which could lead to weird behavior when parsing or manipulating dates and times. In order to workaround this, Rift now saves and restores the timezone itself, just to make sure everything is in order after parsing the spec file.
1 parent a8f35df commit fd265e0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/rift/RPM.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import shutil
4141
from subprocess import Popen, PIPE, STDOUT, run, CalledProcessError
4242
import time
43+
import datetime
4344

4445
import rpm
4546

@@ -261,7 +262,16 @@ def load(self):
261262
try:
262263
rpm.reloadConfig()
263264
self._set_macros()
265+
# Get current timezone, so it can be restored after parsing the spec
266+
# file.
267+
current_timezone = str(datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo)
264268
spec = rpm.TransactionSet().parseSpec(self.filepath)
269+
# As a workaround RPM library bug
270+
# https://github.com/rpm-software-management/rpm/issues/1821,
271+
# restore timezone after it has been changed to parse changelog.
272+
# Note this is fixed in RPM >= 4.19.
273+
os.environ['TZ'] = str(current_timezone)
274+
time.tzset()
265275
except ValueError as exp:
266276
raise RiftError(f"{self.filepath}: {exp}") from exp
267277
self.pkgnames = [_header_values(pkg.header['name']) for pkg in spec.packages]

0 commit comments

Comments
 (0)