Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-90473: WASI requires proper open(2) flags #93529

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Lib/test/support/os_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -4365,6 +4365,7 @@ def test_fd(self):
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, '')

Expand Down
3 changes: 3 additions & 0 deletions Tools/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down