summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-29 09:25:00 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-03-29 09:25:00 (GMT)
commit73030df77f05426872cee7512dc4632ccb35bcc4 (patch)
treeff5c8ec748b3872349cf03ab4534716d479d5de3 /Lib
parent80ec58c49730cb5498a279ee796ff037e8bbb3a7 (diff)
downloadcpython-73030df77f05426872cee7512dc4632ccb35bcc4.zip
cpython-73030df77f05426872cee7512dc4632ccb35bcc4.tar.gz
cpython-73030df77f05426872cee7512dc4632ccb35bcc4.tar.bz2
Fix os._DummyDirEntry.is_symlink()
Issue #25911: Fix os._DummyDirEntry.is_symlink(), don't follow symbolic links: use os.stat(path, follow_symlinks=False).
Diffstat (limited to 'Lib')
-rw-r--r--Lib/os.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/Lib/os.py b/Lib/os.py
index c3ce05d..90646a0 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -452,22 +452,33 @@ class _DummyDirEntry:
# Mimick FindFirstFile/FindNextFile: we should get file attributes
# while iterating on a directory
self._stat = None
+ self._lstat = None
try:
- self.stat()
+ self.stat(follow_symlinks=False)
except OSError:
pass
- def stat(self):
- if self._stat is None:
- self._stat = stat(self.path)
- return self._stat
+ def stat(self, *, follow_symlinks=True):
+ if follow_symlinks:
+ if self._stat is None:
+ self._stat = stat(self.path)
+ return self._stat
+ else:
+ if self._lstat is None:
+ self._lstat = stat(self.path, follow_symlinks=False)
+ return self._lstat
def is_dir(self):
+ if self._lstat is not None and not self.is_symlink():
+ # use the cache lstat
+ stat = self.stat(follow_symlinks=False)
+ return st.S_ISDIR(stat.st_mode)
+
stat = self.stat()
return st.S_ISDIR(stat.st_mode)
def is_symlink(self):
- stat = self.stat()
+ stat = self.stat(follow_symlinks=False)
return st.S_ISLNK(stat.st_mode)
class _dummy_scandir: