diff options
author | Seppo Yli-Olli <seppo.yliolli@gmail.com> | 2020-11-02 17:46:39 +0200 |
---|---|---|
committer | Seppo Yli-Olli <seppo.yliolli@gmail.com> | 2020-11-02 18:48:59 +0200 |
commit | 5019673d1d7eea79d44f9e906e88943f7f5367d5 (patch) | |
tree | 6b38dedb6f2dedc95f947a1961ea215ac1c5febf | |
parent | de9e152a01748c8360b84235ff715bf6469e261d (diff) | |
download | buildstream-5019673d1d7eea79d44f9e906e88943f7f5367d5.tar.gz |
Adding have_subsecond_mtime()
Backport of d164ae319fced1e41ce5978a90c2bd64983cb54e
-rw-r--r-- | tests/testutils/site.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/testutils/site.py b/tests/testutils/site.py index 7dc01a613..bf3ae8db5 100644 --- a/tests/testutils/site.py +++ b/tests/testutils/site.py @@ -3,6 +3,7 @@ # import os import sys +import tempfile from buildstream import utils, ProgramNotFoundError @@ -49,3 +50,34 @@ except ImportError: HAVE_ARPY = False IS_LINUX = os.getenv('BST_FORCE_BACKEND', sys.platform).startswith('linux') + + +# Check if we have subsecond mtime support on the +# filesystem where @directory is located. +# +def have_subsecond_mtime(directory): + + try: + test_file, test_filename = tempfile.mkstemp(dir=directory) + os.close(test_file) + except OSError: + # If we can't create a temp file, lets just say this is False + return False + + try: + os.utime(test_filename, times=None, ns=(int(12345), int(12345))) + except OSError: + # If we can't set the mtime, lets just say this is False + os.unlink(test_filename) + return False + + try: + stat_result = os.stat(test_filename) + except OSError: + # If we can't stat the file, lets just say this is False + os.unlink(test_filename) + return False + + os.unlink(test_filename) + + return stat_result.st_mtime_ns == 12345 |