Skip to content

WASI preopen_dir holds on to Windows resource #132

Open
@thewtex

Description

@thewtex

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions