summaryrefslogtreecommitdiffstats
path: root/Lib/os.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-02-12 10:11:34 (GMT)
committerGitHub <noreply@github.com>2020-02-12 10:11:34 (GMT)
commitf4f445b69306c68a2ba8ce8eb8c6cb3064db5fe7 (patch)
treead5200e0984a2832e67870b7f95165998570f772 /Lib/os.py
parent95905ce0f41fd42eb1ef60ddb83f057401c3d52f (diff)
downloadcpython-f4f445b69306c68a2ba8ce8eb8c6cb3064db5fe7.zip
cpython-f4f445b69306c68a2ba8ce8eb8c6cb3064db5fe7.tar.gz
cpython-f4f445b69306c68a2ba8ce8eb8c6cb3064db5fe7.tar.bz2
bpo-39567: Add audit for os.walk(), os.fwalk(), Path.glob() and Path.rglob(). (GH-18372)
Diffstat (limited to 'Lib/os.py')
-rw-r--r--Lib/os.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/os.py b/Lib/os.py
index 7ae1026..ab75b94 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -336,7 +336,10 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
dirs.remove('CVS') # don't visit CVS directories
"""
- top = fspath(top)
+ sys.audit("os.walk", top, topdown, onerror, followlinks)
+ return _walk(fspath(top), topdown, onerror, followlinks)
+
+def _walk(top, topdown, onerror, followlinks):
dirs = []
nondirs = []
walk_dirs = []
@@ -410,11 +413,11 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
# the caller can replace the directory entry during the "yield"
# above.
if followlinks or not islink(new_path):
- yield from walk(new_path, topdown, onerror, followlinks)
+ yield from _walk(new_path, topdown, onerror, followlinks)
else:
# Recurse into sub-directories
for new_path in walk_dirs:
- yield from walk(new_path, topdown, onerror, followlinks)
+ yield from _walk(new_path, topdown, onerror, followlinks)
# Yield after recursion if going bottom up
yield top, dirs, nondirs
@@ -455,6 +458,7 @@ if {open, stat} <= supports_dir_fd and {scandir, stat} <= supports_fd:
if 'CVS' in dirs:
dirs.remove('CVS') # don't visit CVS directories
"""
+ sys.audit("os.fwalk", top, topdown, onerror, follow_symlinks, dir_fd)
if not isinstance(top, int) or not hasattr(top, '__index__'):
top = fspath(top)
# Note: To guard against symlink races, we use the standard