mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Clean up directories on failure. Closes #58.
This commit is contained in:
parent
443b62d56a
commit
bcb00726a1
8 changed files with 103 additions and 38 deletions
|
|
@ -1,6 +1,9 @@
|
|||
|
||||
import contextlib
|
||||
import functools
|
||||
import os
|
||||
import os.path
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
|
||||
|
|
@ -49,3 +52,14 @@ def entry(func):
|
|||
argv = sys.argv[1:]
|
||||
return func(argv)
|
||||
return wrapper
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def clean_path_on_failure(path):
|
||||
"""Cleans up the directory on an exceptional failure."""
|
||||
try:
|
||||
yield
|
||||
except BaseException:
|
||||
if os.path.exists(path):
|
||||
shutil.rmtree(path)
|
||||
raise
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue