bytecodealliance / bytecodealliance/wasmtime-py

WASI preopen_dir holds on to Windows resource

Open
#132 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
539
Forks
69
Avg merge
13m
Merged PRs (30d)
1

Description

The preopen_dir WASI support seems to hold onto Windows directory resources, which prevents removal of the directory, etc.

This is demonstrated by #131 , which will result in:

```
C:\Users\matth\mambaforge\envs\itk-wasm\lib\tempfile.py:843: PermissionError

During handling of the above exception, another exception occurred:

path = 'C:\\Users\\matth\\AppData\\Local\\Temp\\tmp2w27_daj'
onerror = .onerror at 0x0000024D29A84EE0>

def _rmtree_unsafe(path, onerror):
try:
with os.scandir(path) as scandir_it:
entries = list(scandir_it)
except OSError:
onerror(os.scandir, path, sys.exc_info())
entries = []
for entry in entries:
fullname = entry.path
if _rmtree_isdir(entry):
try:
if entry.is_symlink():
# This can only happen if someone replaces
# a directory with a symlink after the call to
# os.scandir or entry.is_dir above.
raise OSError("Cannot call rmtree on a symbolic link")
except OSError:
onerror(os.path.islink, fullname, sys.exc_info())
continue
_rmtree_unsafe(fullname, onerror)
else:
try:
os.unlink(fullname)
except OSError:
onerror(os.unlink, fullname, sys.exc_info())
try:
> os.rmdir(path)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.