From e0460235dbebb2c2940884125d877cedfbc560cb Mon Sep 17 00:00:00 2001 From: Padraic Fanning Date: Thu, 10 Feb 2022 21:40:08 -0500 Subject: [PATCH] Align test/support/os_helper with CPython 3.10 --- Lib/test/support/os_helper.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Lib/test/support/os_helper.py b/Lib/test/support/os_helper.py index b66f77d8d..69a9815bc 100644 --- a/Lib/test/support/os_helper.py +++ b/Lib/test/support/os_helper.py @@ -302,7 +302,7 @@ if sys.platform.startswith("win"): try: mode = os.lstat(fullname).st_mode except OSError as exc: - print("os_helper.rmtree(): os.lstat(%r) failed with %s" + print("support.rmtree(): os.lstat(%r) failed with %s" % (fullname, exc), file=sys.__stderr__) mode = 0 @@ -479,6 +479,17 @@ def create_empty_file(filename): os.close(fd) +@contextlib.contextmanager +def open_dir_fd(path): + """Open a file descriptor to a directory.""" + assert os.path.isdir(path) + dir_fd = os.open(path, os.O_RDONLY) + try: + yield dir_fd + finally: + os.close(dir_fd) + + def fs_is_case_insensitive(directory): """Detects if the file system for the specified directory is case-insensitive."""