Commit d43b0c89 authored by Petr Špaček's avatar Petr Špaček
Browse files

Merge branch 'libfaketime-fix-file-sync' into 'master'

libfaketime: fix problem with TIMESTAMP_FILE synchronization

See merge request !81
parents 79f47cbf fe40f349
Pipeline #18560 passed with stage
in 1 minute and 32 seconds
......@@ -712,15 +712,16 @@ class Step:
def __time_passes(self):
""" Modify system time. """
time_file = open(os.environ["FAKETIME_TIMESTAMP_FILE"], 'r')
line = time_file.readline().strip()
time_file.close()
file_old = os.environ["FAKETIME_TIMESTAMP_FILE"]
file_next = os.environ["FAKETIME_TIMESTAMP_FILE"] + ".next"
with open(file_old, 'r') as time_file:
line = time_file.readline().strip()
t = time.mktime(datetime.strptime(line, '@%Y-%m-%d %H:%M:%S').timetuple())
t += self.delay
time_file = open(os.environ["FAKETIME_TIMESTAMP_FILE"], 'w')
time_file.write(datetime.fromtimestamp(t).strftime('@%Y-%m-%d %H:%M:%S') + "\n")
time_file.flush()
time_file.close()
with open(file_next, 'w') as time_file:
time_file.write(datetime.fromtimestamp(t).strftime('@%Y-%m-%d %H:%M:%S') + "\n")
time_file.flush()
os.replace(file_next, file_old)
# def __assert(self, ctx):
# """ Assert that a passed expression evaluates to True. """
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment