Cache: fix exception handling in __init__, release lock, fixes #610

This commit is contained in:
Thomas Waldmann 2016-02-04 23:19:35 +01:00
parent 4355150efa
commit 4843719f72
1 changed files with 20 additions and 16 deletions

View File

@ -58,6 +58,7 @@ class Cache:
raise self.CacheInitAbortedError()
self.create()
self.open(lock_wait=lock_wait)
try:
# Warn user before sending data to a relocated repository
if self.previous_location and self.previous_location != repository._location.canonical_path():
msg = ("Warning: The repository at location {} was previously located at {}".format(repository._location.canonical_path(), self.previous_location) +
@ -75,6 +76,9 @@ class Cache:
raise self.EncryptionMethodMismatch()
self.sync()
self.commit()
except:
self.close()
raise
def __enter__(self):
return self