]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117127: glob tests: Reopen dir_fd to pick up directory changes (GH-117128)
authorPetr Viktorin <encukou@gmail.com>
Fri, 22 Mar 2024 09:42:18 +0000 (10:42 +0100)
committerGitHub <noreply@github.com>
Fri, 22 Mar 2024 09:42:18 +0000 (10:42 +0100)
Lib/test/test_glob.py

index 2de997501039adeaa52e0cdbda855ff6ba909b69..6719bdbb0cc9b1fda78171395706ee2864f5e865 100644 (file)
@@ -41,6 +41,11 @@ class GlobTests(unittest.TestCase):
             os.symlink(self.norm('broken'), self.norm('sym1'))
             os.symlink('broken', self.norm('sym2'))
             os.symlink(os.path.join('a', 'bcd'), self.norm('sym3'))
+        self.open_dirfd()
+
+    def open_dirfd(self):
+        if self.dir_fd is not None:
+            os.close(self.dir_fd)
         if {os.open, os.stat} <= os.supports_dir_fd and os.scandir in os.supports_fd:
             self.dir_fd = os.open(self.tempdir, os.O_RDONLY | os.O_DIRECTORY)
         else:
@@ -350,6 +355,10 @@ class GlobTests(unittest.TestCase):
     def test_glob_named_pipe(self):
         path = os.path.join(self.tempdir, 'mypipe')
         os.mkfifo(path)
+
+        # gh-117127: Reopen self.dir_fd to pick up directory changes
+        self.open_dirfd()
+
         self.assertEqual(self.rglob('mypipe'), [path])
         self.assertEqual(self.rglob('mypipe*'), [path])
         self.assertEqual(self.rglob('mypipe', ''), [])