Browse Source

create: catch StoreBackendAlreadyExists

Don't show traceback if a repo at the given location already exists.
Thomas Waldmann 9 months ago
parent
commit
703c98dbc9
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/borg/repository.py

+ 6 - 1
src/borg/repository.py

@@ -5,6 +5,7 @@ from borgstore.store import Store
 from borgstore.store import ObjectNotFound as StoreObjectNotFound
 from borgstore.store import ObjectNotFound as StoreObjectNotFound
 from borgstore.backends.errors import BackendError as StoreBackendError
 from borgstore.backends.errors import BackendError as StoreBackendError
 from borgstore.backends.errors import BackendDoesNotExist as StoreBackendDoesNotExist
 from borgstore.backends.errors import BackendDoesNotExist as StoreBackendDoesNotExist
+from borgstore.backends.errors import BackendAlreadyExists as StoreBackendAlreadyExists
 
 
 from .checksums import xxh64
 from .checksums import xxh64
 from .constants import *  # NOQA
 from .constants import *  # NOQA
@@ -117,6 +118,7 @@ class Repository:
             url = "file://%s" % os.path.abspath(path_or_location)
             url = "file://%s" % os.path.abspath(path_or_location)
             location = Location(url)
             location = Location(url)
         self._location = location
         self._location = location
+        self.url = url
         # lots of stuff in data: use 2 levels by default (data/00/00/ .. data/ff/ff/ dirs)!
         # lots of stuff in data: use 2 levels by default (data/00/00/ .. data/ff/ff/ dirs)!
         data_levels = int(os.environ.get("BORG_STORE_DATA_LEVELS", "2"))
         data_levels = int(os.environ.get("BORG_STORE_DATA_LEVELS", "2"))
         levels_config = {
         levels_config = {
@@ -174,7 +176,10 @@ class Repository:
 
 
     def create(self):
     def create(self):
         """Create a new empty repository"""
         """Create a new empty repository"""
-        self.store.create()
+        try:
+            self.store.create()
+        except StoreBackendAlreadyExists:
+            raise self.AlreadyExists(self.url)
         self.store.open()
         self.store.open()
         try:
         try:
             self.store.store("config/readme", REPOSITORY_README.encode())
             self.store.store("config/readme", REPOSITORY_README.encode())