]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-90473: WASI requires proper open(2) flags (GH-93529)
authorChristian Heimes <christian@python.org>
Mon, 6 Jun 2022 10:08:07 +0000 (12:08 +0200)
committerGitHub <noreply@github.com>
Mon, 6 Jun 2022 10:08:07 +0000 (12:08 +0200)
Lib/test/support/os_helper.py
Lib/test/test_os.py
Tools/wasm/README.md

index 5d787f16b69dd24aa2118a407a2f8482ca13b758..a6ec1cfa25ebe03ae5179e5dbd41db5c90e56200 100644 (file)
@@ -463,7 +463,10 @@ def create_empty_file(filename):
 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)
+    flags = os.O_RDONLY
+    if hasattr(os, "O_DIRECTORY"):
+        flags |= os.O_DIRECTORY
+    dir_fd = os.open(path, flags)
     try:
         yield dir_fd
     finally:
index f304c5e01e5fa1a13919ef9f001936f6c954b7ef..c0321dcdcc071a20e12de2201e57bd26e38560e6 100644 (file)
@@ -3993,7 +3993,7 @@ class PathTConverterTests(unittest.TestCase):
         ('access', False, (os.F_OK,), None),
         ('chflags', False, (0,), None),
         ('lchflags', False, (0,), None),
-        ('open', False, (0,), getattr(os, 'close', None)),
+        ('open', False, (os.O_RDONLY,), getattr(os, 'close', None)),
     ]
 
     def test_path_t_converter(self):
@@ -4365,6 +4365,7 @@ class TestScandir(unittest.TestCase):
                     st = os.stat(entry.name, dir_fd=fd, follow_symlinks=False)
                     self.assertEqual(entry.stat(follow_symlinks=False), st)
 
+    @unittest.skipIf(support.is_wasi, "WASI maps '' to cwd")
     def test_empty_path(self):
         self.assertRaises(FileNotFoundError, os.scandir, '')
 
index 6bb9bd9978402b0de45df5238013df1f1b97c7f3..3b7a7aecc33eae74a2ebe335a10899a1021e7733 100644 (file)
@@ -235,6 +235,9 @@ are:
   call read/write/accept on a file descriptor that is passed into the process.
 - ``socket.gethostname()`` and host name resolution APIs like
   ``socket.gethostbyname()`` are not implemented and always fail.
+- ``open(2)`` checks flags more strictly. Caller must pass either
+  ``O_RDONLY``, ``O_RDWR``, or ``O_WDONLY`` to ``os.open``. Directory file
+  descriptors must be created with flags ``O_RDONLY | O_DIRECTORY``.
 - ``chmod(2)`` is not available. It's not possible to modify file permissions,
   yet. A future version of WASI may provide a limited ``set_permissions`` API.
 - User/group related features like ``os.chown()``, ``os.getuid``, etc. are