From 3f6be17927839c2cf0a94216929911a4136a833b Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Sun, 15 Dec 2024 14:47:01 -0700 Subject: [PATCH] Flip SCons st_mtime usage back to tuple index A previous change proposed flipping all of the Python stat references from the older tuple index style (st[stat.ST_XXX]) to the more modern stat structure references (st.st_xxx). This change rolls back the one place in the actual SCons code (in Node/FS) that used the stat mtime attribute. There's a small chance that switching scons versions back and forth could cause some time comparison issues, since st_mtime is a float, but for backwards compatibility reasons with ancient Python 2 versions Python retained the integer behavior of the index form. While problems from this seem a low probability, avoid the issue for now. Signed-off-by: Mats Wichmann --- SCons/Node/FS.py | 4 +++- SCons/Node/FSTests.py | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/SCons/Node/FS.py b/SCons/Node/FS.py index ec0a69a7b..694ff9f87 100644 --- a/SCons/Node/FS.py +++ b/SCons/Node/FS.py @@ -762,7 +762,9 @@ def getmtime(self): st = self.stat() if st: - return st.st_mtime + # TODO: switch to st.st_mtime, however this changes granularity + # (ST_MTIME is an int for backwards compat, st_mtime is float) + return st[stat.ST_MTIME] else: return None diff --git a/SCons/Node/FSTests.py b/SCons/Node/FSTests.py index ae98bc5a5..1b3704da9 100644 --- a/SCons/Node/FSTests.py +++ b/SCons/Node/FSTests.py @@ -774,7 +774,8 @@ def test_update(self) -> None: ni.update(fff) - mtime = st.st_mtime + # TODO: flip this to st.st_mtime when Node/FS.py does + mtime = st[stat.ST_MTIME] assert ni.timestamp == mtime, (ni.timestamp, mtime) size = st.st_size assert ni.size == size, (ni.size, size) @@ -786,7 +787,8 @@ def test_update(self) -> None: st = os.stat('fff') - mtime = st.st_mtime + # TODO: flip this to st.st_mtime when Node/FS.py does + mtime = st[stat.ST_MTIME] assert ni.timestamp != mtime, (ni.timestamp, mtime) size = st.st_size assert ni.size != size, (ni.size, size)