NiklasRosenstein / flux-ci

Flux is your own private & lightweight CI server.
MIT License
26 stars 10 forks source link

Windows error removing .git directory #48

Closed NiklasRosenstein closed 6 years ago

NiklasRosenstein commented 6 years ago
[2018-06-08 12:16:15,584 - ERROR]: [WinError 5] Access is denied: 'C:\\Users\\niklas\\Repositories\\NiklasRosenstein\\flux\\builds\\NiklasRosenstein\\nodepy\\0\\.git\\objects\\pack\\pack-34ab47d5b2cc3439270bc535724bb399c2e0f01b.idx'
Traceback (most recent call last):
  File "C:\Users\niklas\Repositories\NiklasRosenstein\flux\flux\build.py", line 154, in do_build
    if do_build_(build, build_path, override_path, logger, logfile, terminate_event):
  File "C:\Users\niklas\Repositories\NiklasRosenstein\flux\flux\build.py", line 241, in do_build_
    shutil.rmtree(os.path.join(build_path, '.git'))
  File "C:\Users\niklas\Repositories\NiklasRosenstein\flux\.venv\lib\shutil.py", line 494, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "C:\Users\niklas\Repositories\NiklasRosenstein\flux\.venv\lib\shutil.py", line 384, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\niklas\Repositories\NiklasRosenstein\flux\.venv\lib\shutil.py", line 384, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\niklas\Repositories\NiklasRosenstein\flux\.venv\lib\shutil.py", line 389, in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Users\niklas\Repositories\NiklasRosenstein\flux\.venv\lib\shutil.py", line 387, in _rmtree_unsafe
    os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\niklas\\Repositories\\NiklasRosenstein\\flux\\builds\\NiklasRosenstein\\nodepy\\0\\.git\\objects\\pack\\pack-34ab47d5b2cc3439270bc535724bb399c2e0f01b.idx'

Git write-protects the object files on Windows (for whatever reason ..) which prevents removing the .git directory recursively with shutil.rmtree(). On the command-line, you'd have to use rm -rf to delete the directory.

NiklasRosenstein commented 6 years ago

This same error can prevent a build from finishing because it is updated only after shutil.rmtree(build_path) is called.

https://github.com/NiklasRosenstein/flux-ci/blob/879d036f5ab3c047a5d2abe3d481f4c13ea7383f/flux/build.py#L167-L178

To do list