]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39567: Add audit for os.walk(), os.fwalk(), Path.glob() and Path.rglob(). (GH...
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 12 Feb 2020 10:11:34 +0000 (12:11 +0200)
committerGitHub <noreply@github.com>
Wed, 12 Feb 2020 10:11:34 +0000 (12:11 +0200)
Lib/os.py
Lib/pathlib.py
Misc/NEWS.d/next/Library/2020-02-06-10-23-32.bpo-39567.VpFBxt.rst [new file with mode: 0644]

index 7ae102617e8b1f344e0f19a263301c98f7b53849..ab75b94d4fe45fe2d101a7c6b134b997424b95cf 100644 (file)
--- 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
index a5f3313902e1b88529e14b2182d37db6f4e7ae57..cfa574af6e8babbde8756e732b613537a54296dd 100644 (file)
@@ -1134,6 +1134,7 @@ class Path(PurePath):
         """Iterate over this subtree and yield all existing files (of any
         kind, including directories) matching the given relative pattern.
         """
+        sys.audit("pathlib.Path.glob", self, pattern)
         if not pattern:
             raise ValueError("Unacceptable pattern: {!r}".format(pattern))
         drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
@@ -1148,6 +1149,7 @@ class Path(PurePath):
         directories) matching the given relative pattern, anywhere in
         this subtree.
         """
+        sys.audit("pathlib.Path.rglob", self, pattern)
         drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
         if drv or root:
             raise NotImplementedError("Non-relative patterns are unsupported")
diff --git a/Misc/NEWS.d/next/Library/2020-02-06-10-23-32.bpo-39567.VpFBxt.rst b/Misc/NEWS.d/next/Library/2020-02-06-10-23-32.bpo-39567.VpFBxt.rst
new file mode 100644 (file)
index 0000000..3c4700f
--- /dev/null
@@ -0,0 +1,2 @@
+Added audit for :func:`os.walk`, :func:`os.fwalk`, :meth:`pathlib.Path.glob`
+and :meth:`pathlib.Path.rglob`.