Skip to content

Commit

Permalink
Flip SCons st_mtime usage back to tuple index
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mwichmann committed Dec 15, 2024
1 parent 70e8cf9 commit 3f6be17
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion SCons/Node/FS.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions SCons/Node/FSTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 3f6be17

Please sign in to comment.