wasmtime-py icon indicating copy to clipboard operation
wasmtime-py copied to clipboard

WASI preopen_dir holds on to Windows resource

Open thewtex opened this issue 1 year ago • 7 comments

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 = <function TemporaryDirectory._rmtree.<locals>.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)

thewtex avatar Feb 27 '23 14:02 thewtex