From 8b49c4d2df743600ada3fc06fcb6f6927ae3df30 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Mon, 29 Jul 2019 15:15:27 +0200 Subject: [PATCH] Repository.check_can_create_repository: use stat() to check similar issue as #4695. (cherry picked from commit 4911720fafbd45bbcb9db1b56fc968352160d24c) --- src/borg/repository.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/borg/repository.py b/src/borg/repository.py index f2cbdb116..53b512781 100644 --- a/src/borg/repository.py +++ b/src/borg/repository.py @@ -234,11 +234,17 @@ class Repository: repository, user's can only use the quota'd repository, when their --restrict-to-path points at the user's repository. """ - if os.path.exists(path): + try: + st = os.stat(path) + except FileNotFoundError: + pass # nothing there! + else: + # there is something already there! if self.is_repository(path): raise self.AlreadyExists(path) - if not os.path.isdir(path) or os.listdir(path): + if not stat.S_ISDIR(st.st_mode) or os.listdir(path): raise self.PathAlreadyExists(path) + # an empty directory is acceptable for us. while True: # Check all parent directories for Borg's repository README