diff options
author | Cody Maloney <cmaloney@users.noreply.github.com> | 2024-11-01 21:50:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-01 21:50:49 (GMT) |
commit | 72dd4714f944e5927656aa25f5cd9bdcd3b00a76 (patch) | |
tree | 965ced6971f92758a31d3f37e6625d7048861d62 /Lib/_pyio.py | |
parent | c84a136511c673f495f466887716b55c13b7e3ac (diff) | |
download | cpython-72dd4714f944e5927656aa25f5cd9bdcd3b00a76.zip cpython-72dd4714f944e5927656aa25f5cd9bdcd3b00a76.tar.gz cpython-72dd4714f944e5927656aa25f5cd9bdcd3b00a76.tar.bz2 |
gh-120754: _io Ensure stat cache is cleared on fd change (#125166)
Performed an audit of `fileio.c` and `_pyio` and made sure anytime the
fd changes the stat result, if set, is also cleared/changed.
There's one case where it's not cleared, if code would clear it in
__init__, keep the memory allocated and just do another fstat with the
existing memory.
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r-- | Lib/_pyio.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 7b6d10c..42b0aea 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -1480,6 +1480,7 @@ class FileIO(RawIOBase): """ if self._fd >= 0: # Have to close the existing file first. + self._stat_atopen = None try: if self._closefd: os.close(self._fd) @@ -1583,6 +1584,7 @@ class FileIO(RawIOBase): if e.errno != errno.ESPIPE: raise except: + self._stat_atopen = None if owned_fd is not None: os.close(owned_fd) raise @@ -1756,6 +1758,7 @@ class FileIO(RawIOBase): called more than once without error. """ if not self.closed: + self._stat_atopen = None try: if self._closefd: os.close(self._fd) |