Commit 33af263d authored by Éric Araujo's avatar Éric Araujo

Fix incorrect mtime comparison in distutils (#11933).

This is a regression introduced in 9211a5d7d0b4, when uses of ST_MTIME
constants were changed to uses of st_mtime attributes.  As diagnosed in
the bug report, this change is not merely stylistic: st_mtime is a
float but ST_MTIME’s resolution is rounded to the seconds, so there was
a mismatch between the values seen by file_util and dep_util which
caused an sdist to be unnecessarily created a second time on an ext4
filesystem.

This patch has been tested by John S. Gruber, who reported the bug.
As this is a simple code revert, I think it’s okay to commit without a
unit test.
parent 0db7f72c
...@@ -7,6 +7,7 @@ timestamp dependency analysis.""" ...@@ -7,6 +7,7 @@ timestamp dependency analysis."""
__revision__ = "$Id$" __revision__ = "$Id$"
import os import os
from stat import ST_MTIME
from distutils.errors import DistutilsFileError from distutils.errors import DistutilsFileError
def newer(source, target): def newer(source, target):
...@@ -27,7 +28,7 @@ def newer(source, target): ...@@ -27,7 +28,7 @@ def newer(source, target):
if not os.path.exists(target): if not os.path.exists(target):
return True return True
return os.stat(source).st_mtime > os.stat(target).st_mtime return os.stat(source)[ST_MTIME] > os.stat(target)[ST_MTIME]
def newer_pairwise(sources, targets): def newer_pairwise(sources, targets):
"""Walk two filename lists in parallel, testing if each source is newer """Walk two filename lists in parallel, testing if each source is newer
...@@ -71,7 +72,7 @@ def newer_group(sources, target, missing='error'): ...@@ -71,7 +72,7 @@ def newer_group(sources, target, missing='error'):
# is more recent than 'target', then 'target' is out-of-date and # is more recent than 'target', then 'target' is out-of-date and
# we can immediately return true. If we fall through to the end # we can immediately return true. If we fall through to the end
# of the loop, then 'target' is up-to-date and we return false. # of the loop, then 'target' is up-to-date and we return false.
target_mtime = os.stat(target).st_mtime target_mtime = os.stat(target)[ST_MTIME]
for source in sources: for source in sources:
if not os.path.exists(source): if not os.path.exists(source):
...@@ -82,7 +83,7 @@ def newer_group(sources, target, missing='error'): ...@@ -82,7 +83,7 @@ def newer_group(sources, target, missing='error'):
elif missing == 'newer': # missing source means target is elif missing == 'newer': # missing source means target is
return True # out-of-date return True # out-of-date
if os.stat(source).st_mtime > target_mtime: if os.stat(source)[ST_MTIME] > target_mtime:
return True return True
return False return False
...@@ -309,6 +309,7 @@ Hans de Graaff ...@@ -309,6 +309,7 @@ Hans de Graaff
Eddy De Greef Eddy De Greef
Duncan Grisby Duncan Grisby
Fabian Groffen Fabian Groffen
John S. Gruber
Dag Gruneau Dag Gruneau
Filip Gruszczyński Filip Gruszczyński
Michael Guravage Michael Guravage
......
...@@ -37,6 +37,8 @@ Core and Builtins ...@@ -37,6 +37,8 @@ Core and Builtins
Library Library
------- -------
- Issue #11933: Fix incorrect mtime comparison in distutils.
- Issues #11104, #8688: Fix the behavior of distutils' sdist command with - Issues #11104, #8688: Fix the behavior of distutils' sdist command with
manually-maintained MANIFEST files. manually-maintained MANIFEST files.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment