mesonbuild / mesonwrap

Meson wraps service and tools, please use https://github.com/mesonbuild/wrapdb for wraps issues
https://wrapdb.mesonbuild.com
Apache License 2.0
26 stars 7 forks source link

wrapcreator should use windows_proof_rmtree from meson for deleting #64

Closed nirbheek closed 5 years ago

nirbheek commented 6 years ago

Else we get a traceback:

Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\mesonwrap-0.0.6-py3.6.egg\mesonwrap\wrapcreator.py", line 45, in create
    return self.create_internal(workdir)
  File "C:\Python36\lib\site-packages\mesonwrap-0.0.6-py3.6.egg\mesonwrap\wrapcreator.py", line 60, in create_internal
    upstream_content = open(upstream_file).read()
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\2\\tmpwpymideg\\upstream.wrap'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python36\Scripts\mesonwrap-script.py", line 11, in <module>
    load_entry_point('mesonwrap==0.0.6', 'console_scripts', 'mesonwrap')()
  File "C:\Python36\lib\site-packages\mesonwrap-0.0.6-py3.6.egg\mesonwrap\cli.py", line 26, in __init__
    getattr(self, self.CMD_PREFIX + command)()
  File "C:\Python36\lib\site-packages\mesonwrap-0.0.6-py3.6.egg\mesonwrap\cli.py", line 80, in command_wrapupdate
    wrapupdater.main(*self.args())
  File "C:\Python36\lib\site-packages\mesonwrap-0.0.6-py3.6.egg\mesonwrap\wrapupdater.py", line 47, in main
    m.update_db(args.project, args.repo_url, args.branch)
  File "C:\Python36\lib\site-packages\mesonwrap-0.0.6-py3.6.egg\mesonwrap\wrapupdater.py", line 35, in update_db
    (wrap_contents, zip_contents, revision_id) = creator.create()
  File "C:\Python36\lib\site-packages\mesonwrap-0.0.6-py3.6.egg\mesonwrap\wrapcreator.py", line 45, in create
    return self.create_internal(workdir)
  File "C:\Python36\lib\tempfile.py", line 809, in __exit__
    self.cleanup()
  File "C:\Python36\lib\tempfile.py", line 813, in cleanup
    _shutil.rmtree(self.name)
  File "C:\Python36\lib\shutil.py", line 494, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "C:\Python36\lib\shutil.py", line 384, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Python36\lib\shutil.py", line 384, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Python36\lib\shutil.py", line 384, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Python36\lib\shutil.py", line 389, in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Python36\lib\shutil.py", line 387, in _rmtree_unsafe
    os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\2\\tmpwpymideg\\.git\\objects\\05\\9497b4258ab434d43f71a6ab4765d34be325ea'
sarum9in commented 6 years ago

Note for myself: https://github.com/mesonbuild/meson/blob/master/mesonbuild/mesonlib.py#L1002

def _make_tree_writable(topdir):
    # Ensure all files and directories under topdir are writable
    # (and readable) by owner.
    for d, _, files in os.walk(topdir):
        os.chmod(d, os.stat(d).st_mode | stat.S_IWRITE | stat.S_IREAD)
        for fname in files:
            fpath = os.path.join(d, fname)
            if os.path.isfile(fpath):
                os.chmod(fpath, os.stat(fpath).st_mode | stat.S_IWRITE | stat.S_IREAD)

def windows_proof_rmtree(f):
    # On Windows if anyone is holding a file open you can't
    # delete it. As an example an anti virus scanner might
    # be scanning files you are trying to delete. The only
    # way to fix this is to try again and again.
    delays = [0.1, 0.1, 0.2, 0.2, 0.2, 0.5, 0.5, 1, 1, 1, 1, 2]
    # Start by making the tree wriable.
    _make_tree_writable(f)
    for d in delays:
        try:
            shutil.rmtree(f)
            return
        except FileNotFoundError:
            return
        except (OSError, PermissionError):
            time.sleep(d)
    # Try one last time and throw if it fails.
    shutil.rmtree(f)
sarum9in commented 6 years ago

Another note: this will require reimplementing tempfile.TemporaryDirectory(). Probably not going to happen but this makes me think that this project is the wrong place to fix this issue, though probably worth it.