Skip to content

Commit be34f33

Browse files
committed
Be resilient to missing drive letters or root subdirectories.
Since Wasmtime 20, it is now an error to preopen a directory that is not accessible by Wasmtime. In Wasmtime 20, the error would happen in the store initialization code, which made it hard to work around, but since Wasmtime 21, this happens at the preopen_dir() call. This was changed in response to bytecodealliance/wasmtime#8552. Preopens for relative paths are unaffected because if one of parents of your cwd can't be opened by you you should probably do something about it. This may be reconsidered in the future (perhaps with a warning) if there are enough broken systems configured in this way to outweigh the risk of ending up with certain paths that you can open being not possible to use with YoWASP tools. (E.g. a -r+x directory is going to be rejected by Wasmtime, but you could ordinarily use a path that traverses it.)
1 parent 8b99237 commit be34f33

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

dependencies.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
importlib_resources; python_version < "3.9"
22
platformdirs<5,>=3.0
3-
wasmtime<23,>=1.0
3+
wasmtime<23,>=21.0.0

yowasp_runtime/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@ def run_wasm(__package__, wasm_filename, *, resources=[], argv):
6262
for drive_index in range(26):
6363
if drive_mask & (1 << drive_index):
6464
drive_letter = "abcdefghijklmnopqrstuvwxyz"[drive_index]
65-
wasi_cfg.preopen_dir(drive_letter + ":\\", drive_letter + ":")
66-
drive_letter = drive_letter.upper()
67-
wasi_cfg.preopen_dir(drive_letter + ":\\", drive_letter + ":")
65+
try:
66+
wasi_cfg.preopen_dir(drive_letter + ":\\", drive_letter + ":")
67+
drive_letter = drive_letter.upper()
68+
wasi_cfg.preopen_dir(drive_letter + ":\\", drive_letter + ":")
69+
except wasmtime.WasmtimeError:
70+
# drive letter present, but not accessible for some reason; ignore it
71+
continue
6872
else:
6973
# can't do this for files, but no one's going to use yowasp on files in / anyway
7074
for path in os.listdir("/"):

0 commit comments

Comments
 (0)