cpython: 3b7230997425 (original) (raw)

--- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1750,14 +1750,10 @@ Files and Directories The dir_fd argument. -.. function:: remove(path, *, dir_fd=None, rmdir=False) -

.. function:: removedirs(path) @@ -1872,14 +1870,25 @@ Files and Directories .. versionadded:: 3.3 -.. function:: rmdir(path) +.. function:: rmdir(path, *, dir_fd=None) Remove (delete) the directory path. Only works when the directory is empty, otherwise, :exc:OSError is raised. In order to remove whole directory trees, :func:shutil.rmtree can be used.

+ .. data:: XATTR_SIZE_MAX @@ -2235,9 +2244,9 @@ Files and Directories .. versionadded:: 3.3 -.. function:: unlink(path, *, dir_fd=None, rmdir=False) -

.. function:: utime(path, times=None, *, ns=None, dir_fd=None, follow_symlinks=True)

--- a/Lib/os.py +++ b/Lib/os.py @@ -157,6 +157,7 @@ if _exists("_have_functions"): _add("HAVE_RENAMEAT", "rename") _add("HAVE_SYMLINKAT", "symlink") _add("HAVE_UNLINKAT", "unlink")

- del _set del _have_functions del _globals

--- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -785,7 +785,10 @@ class FwalkTests(WalkTests): os.unlink(name, dir_fd=rootfd) for name in dirs: st = os.stat(name, dir_fd=rootfd, follow_symlinks=False)

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -47,6 +47,9 @@ Core and Builtins Library ------- +- Issue #15154: Add "dir_fd" parameter to os.rmdir, remove "rmdir"

--- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4084,17 +4084,62 @@ posix_replace(PyObject *self, PyObject * } PyDoc_STRVAR(posix_rmdir__doc__, -"rmdir(path)\n\n[](#l5.7) -Remove a directory."); - -static PyObject * -posix_rmdir(PyObject *self, PyObject *args) -{ +"rmdir(path, *, dir_fd=None)\n\n[](#l5.13) +Remove a directory.\n[](#l5.14) +\n[](#l5.15) +If dir_fd is not None, it should be a file descriptor open to a directory,\n[](#l5.16)

+

+#ifdef HAVE_UNLINKAT

+#else

+#endif

+

#ifdef MS_WINDOWS

-#else

-#endif

+#else +#ifdef HAVE_UNLINKAT

+#endif

+#endif

+

+

+ +exit:

} @@ -4186,68 +4231,54 @@ BOOL WINAPI Py_DeleteFileW(LPCWSTR lpFil #endif /* MS_WINDOWS */ PyDoc_STRVAR(posix_unlink__doc__, -"unlink(path, *, dir_fd=None, rmdir=False)\n\n[](#l5.80) +"unlink(path, *, dir_fd=None)\n\n[](#l5.81) Remove a file (same as remove()).\n[](#l5.82) \n[](#l5.83) If dir_fd is not None, it should be a file descriptor open to a directory,\n[](#l5.84) and path should be relative; path will then be relative to that directory.\n[](#l5.85) dir_fd may not be implemented on your platform.\n[](#l5.86)

#ifdef HAVE_UNLINKAT

-#else

-#endif

+#else

+#endif

Py_BEGIN_ALLOW_THREADS #ifdef MS_WINDOWS

#else

#ifdef HAVE_UNLINKAT if (dir_fd != DEFAULT_DIR_FD)

#endif /* HAVE_UNLINKAT */ result = unlink(path.narrow); @@ -10806,7 +10837,9 @@ static PyMethodDef posix_methods[] = { {"replace", (PyCFunction)posix_replace, METH_VARARGS | METH_KEYWORDS, posix_replace__doc__},