diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2020-08-30 11:22:53 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2020-08-30 11:22:53 +0000 |
commit | 6cfa8e0963e9a518a25528a248932fcf41b4f969 (patch) | |
tree | 6882a2a7a3214ef85d7a946f2506e9ed2c3f60f5 /pre_commit/store.py | |
parent | Adding upstream version 2.6.0. (diff) | |
download | pre-commit-6cfa8e0963e9a518a25528a248932fcf41b4f969.tar.xz pre-commit-6cfa8e0963e9a518a25528a248932fcf41b4f969.zip |
Adding upstream version 2.7.1.upstream/2.7.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/store.py')
-rw-r--r-- | pre_commit/store.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/pre_commit/store.py b/pre_commit/store.py index 6d8c40a..e5522ec 100644 --- a/pre_commit/store.py +++ b/pre_commit/store.py @@ -43,6 +43,10 @@ class Store: def __init__(self, directory: Optional[str] = None) -> None: self.directory = directory or Store.get_default_directory() self.db_path = os.path.join(self.directory, 'db.db') + self.readonly = ( + os.path.exists(self.directory) and + not os.access(self.directory, os.W_OK) + ) if not os.path.exists(self.directory): os.makedirs(self.directory, exist_ok=True) @@ -75,7 +79,7 @@ class Store: self._create_config_table(db) # Atomic file move - os.rename(tmpfile, self.db_path) + os.replace(tmpfile, self.db_path) @contextlib.contextmanager def exclusive_lock(self) -> Generator[None, None, None]: @@ -218,6 +222,8 @@ class Store: ) def mark_config_used(self, path: str) -> None: + if self.readonly: # pragma: win32 no cover + return path = os.path.realpath(path) # don't insert config files that do not exist if not os.path.exists(path): |