mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-05-11 19:10:22 -05:00
Clean up directories on failure. Closes #58.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user