From 57b8cd59bdf8cb5262ec12f8cdf48a7b9a5a4346 Mon Sep 17 00:00:00 2001 From: roland Date: Tue, 20 Feb 2024 16:25:58 +0100 Subject: [PATCH] Something that might work. --- src/idpyoidc/storage/listfile.py | 11 ++++------- tests/test_14_read_only_list_file.py | 2 ++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/idpyoidc/storage/listfile.py b/src/idpyoidc/storage/listfile.py index 859f4858..2c390350 100644 --- a/src/idpyoidc/storage/listfile.py +++ b/src/idpyoidc/storage/listfile.py @@ -40,17 +40,14 @@ def get_mtime(fname): :param fname: File name :return: The last time the file was modified. """ + p = Path(fname) try: - target = Path(fname) - mtime = target.stat().st_mtime - # mtime = os.stat(fname).st_mtime_ns + mtime = p.stat().st_mtime except OSError: - # The file might be right in the middle of being written to + # The file might be right in the middle of being created # so sleep time.sleep(1) - target = Path(fname) - mtime = target.stat().st_mtime - # mtime = os.stat(fname).st_mtime_ns + mtime = p.stat().st_mtime return mtime diff --git a/tests/test_14_read_only_list_file.py b/tests/test_14_read_only_list_file.py index d81d9e37..3eda4e1c 100644 --- a/tests/test_14_read_only_list_file.py +++ b/tests/test_14_read_only_list_file.py @@ -1,4 +1,5 @@ import os +from time import sleep from idpyoidc.storage.listfile import ReadOnlyListFile @@ -22,6 +23,7 @@ def test_read_only_list_file(): for line in ["one", "two", "three"]: fp.write(line + '\n') + sleep(1) assert len(_read_only) == 3 assert set(_read_only) == {"one", "two", "three"} assert _read_only[-1] == "three" \ No newline at end of file