diff options
author | Jim MacArthur <jim.macarthur@codethink.co.uk> | 2018-07-27 11:56:36 +0100 |
---|---|---|
committer | Jim MacArthur <jim.macarthur@codethink.co.uk> | 2018-08-01 13:07:32 +0100 |
commit | 1d3af84d312b5c252630637d01502c4625416348 (patch) | |
tree | 841c8f2b370fe80d292013ebe301a23aa16ec726 | |
parent | 6aedc57be2b7ba704e69a58dfd9922f8c0c6e771 (diff) | |
download | buildstream-1d3af84d312b5c252630637d01502c4625416348.tar.gz |
utils.py: add getmtime() and magic_timestamp
magic_timestamp is moved into file scope so other classes
can use it.
-rw-r--r-- | buildstream/utils.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/buildstream/utils.py b/buildstream/utils.py index 68f99b9a3..93ab6fb0e 100644 --- a/buildstream/utils.py +++ b/buildstream/utils.py @@ -41,6 +41,9 @@ import psutil from . import _signals from ._exceptions import BstError, ErrorDomain +# The magic number for timestamps: 2011-11-11 11:11:11 +_magic_timestamp = calendar.timegm([2011, 11, 11, 11, 11, 11]) + # The separator we use for user specified aliases _ALIAS_SEPARATOR = ':' @@ -909,9 +912,6 @@ def _set_deterministic_user(directory): # directory (str): The directory to recursively set the mtime on # def _set_deterministic_mtime(directory): - # The magic number for timestamps: 2011-11-11 11:11:11 - magic_timestamp = calendar.timegm([2011, 11, 11, 11, 11, 11]) - for dirname, _, filenames in os.walk(directory.encode("utf-8"), topdown=False): for filename in filenames: pathname = os.path.join(dirname, filename) @@ -930,9 +930,9 @@ def _set_deterministic_mtime(directory): # However, nowadays it is possible at least on gnuish systems # with with the lutimes glibc function. if not os.path.islink(pathname): - os.utime(pathname, (magic_timestamp, magic_timestamp)) + os.utime(pathname, (_magic_timestamp, _magic_timestamp)) - os.utime(dirname, (magic_timestamp, magic_timestamp)) + os.utime(dirname, (_magic_timestamp, _magic_timestamp)) # _tempdir() @@ -1159,3 +1159,11 @@ def _deduplicate(iterable, key=None): if k not in seen: seen_add(k) yield element + + +# Like os.path.getmtime(), but returns the mtime of a link rather than +# the target, if the filesystem supports that. +# +def _get_link_mtime(path): + path_stat = os.lstat(path) + return path_stat.st_mtime |