You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:30:22 UTC

[buildstream] 01/02: Adding have_subsecond_mtime() Backport of d164ae319fced1e41ce5978a90c2bd64983cb54e

This is an automated email from the ASF dual-hosted git repository.

not-in-ldap pushed a commit to branch nanonyme/fix-tests
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 5019673d1d7eea79d44f9e906e88943f7f5367d5
Author: Seppo Yli-Olli <se...@gmail.com>
AuthorDate: Mon Nov 2 17:46:39 2020 +0200

    Adding have_subsecond_mtime()
    Backport of d164ae319fced1e41ce5978a90c2bd64983cb54e
---
 tests/testutils/site.py | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/tests/testutils/site.py b/tests/testutils/site.py
index 7dc01a6..bf3ae8d 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