[3.12] gh-117127: glob tests: Reopen dir_fd to pick up directory changes (GH-117128) (GH-117150)

gh-117127: glob tests: Reopen dir_fd to pick up directory changes (GH-117128)
(cherry picked from commit 42ae924d27)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-03-22 11:24:06 +01:00 committed by GitHub
parent ad0ff86034
commit d99ffc5a4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -40,6 +40,11 @@ class GlobTests(unittest.TestCase):
os.symlink(self.norm('broken'), self.norm('sym1')) os.symlink(self.norm('broken'), self.norm('sym1'))
os.symlink('broken', self.norm('sym2')) os.symlink('broken', self.norm('sym2'))
os.symlink(os.path.join('a', 'bcd'), self.norm('sym3')) 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: 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) self.dir_fd = os.open(self.tempdir, os.O_RDONLY | os.O_DIRECTORY)
else: else:
@ -349,6 +354,10 @@ class GlobTests(unittest.TestCase):
def test_glob_named_pipe(self): def test_glob_named_pipe(self):
path = os.path.join(self.tempdir, 'mypipe') path = os.path.join(self.tempdir, 'mypipe')
os.mkfifo(path) 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*'), [path]) self.assertEqual(self.rglob('mypipe*'), [path])
self.assertEqual(self.rglob('mypipe', ''), []) self.assertEqual(self.rglob('mypipe', ''), [])