1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-03-08 21:05:23 +00:00

check_can_create_repository: deal with PermissionErrors, see #7016

borg init calls this. If there is a PermissionError, it is
usually fs permission issue at path or its parent directory.

Don't give a traceback, but rather an error msg and a specific exit code.
This commit is contained in:
Thomas Waldmann 2024-01-19 18:13:53 +01:00
parent 266c9f6e8f
commit 45f65f7c57
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01
3 changed files with 20 additions and 2 deletions

View file

@ -587,6 +587,8 @@ Errors
There is already something at {}. There is already something at {}.
Repository.StorageQuotaExceeded rc: 20 traceback: no Repository.StorageQuotaExceeded rc: 20 traceback: no
The storage quota ({}) has been exceeded ({}). Try deleting some archives. The storage quota ({}) has been exceeded ({}). Try deleting some archives.
Repository.PathPermissionDenied rc: 21 traceback: no
Permission denied to {}.
MandatoryFeatureUnsupported rc: 25 traceback: no MandatoryFeatureUnsupported rc: 25 traceback: no
Unsupported repository feature(s) {}. A newer version of borg is required to access this repository. Unsupported repository feature(s) {}. A newer version of borg is required to access this repository.

View file

@ -772,6 +772,8 @@ This problem will go away as soon as the server has been upgraded to 1.0.7+.
raise PathNotAllowed('(unknown)') raise PathNotAllowed('(unknown)')
else: else:
raise PathNotAllowed(args[0].decode()) raise PathNotAllowed(args[0].decode())
elif error == 'PathPermissionDenied':
raise Repository.PathPermissionDenied(args[0].decode())
elif error == 'ParentPathDoesNotExist': elif error == 'ParentPathDoesNotExist':
raise Repository.ParentPathDoesNotExist(args[0].decode()) raise Repository.ParentPathDoesNotExist(args[0].decode())
elif error == 'ObjectNotFound': elif error == 'ObjectNotFound':

View file

@ -168,6 +168,10 @@ class Repository:
"""The storage quota ({}) has been exceeded ({}). Try deleting some archives.""" """The storage quota ({}) has been exceeded ({}). Try deleting some archives."""
exit_mcode = 20 exit_mcode = 20
class PathPermissionDenied(Error):
"""Permission denied to {}."""
exit_mcode = 21
def __init__(self, path, create=False, exclusive=False, lock_wait=None, lock=True, def __init__(self, path, create=False, exclusive=False, lock_wait=None, lock=True,
append_only=False, storage_quota=None, check_segment_magic=True, append_only=False, storage_quota=None, check_segment_magic=True,
make_parent_dirs=False): make_parent_dirs=False):
@ -261,13 +265,23 @@ class Repository:
st = os.stat(path) st = os.stat(path)
except FileNotFoundError: except FileNotFoundError:
pass # nothing there! pass # nothing there!
except PermissionError:
raise self.PathPermissionDenied(path) from None
else: else:
# there is something already there! # there is something already there!
if self.is_repository(path): if self.is_repository(path):
raise self.AlreadyExists(path) raise self.AlreadyExists(path)
if not stat.S_ISDIR(st.st_mode) or os.listdir(path): if not stat.S_ISDIR(st.st_mode):
raise self.PathAlreadyExists(path) raise self.PathAlreadyExists(path)
# an empty directory is acceptable for us. try:
files = os.listdir(path)
except PermissionError:
raise self.PathPermissionDenied(path) from None
else:
if files: # a dir, but not empty
raise self.PathAlreadyExists(path)
else: # an empty directory is acceptable for us.
pass
while True: while True:
# Check all parent directories for Borg's repository README # Check all parent directories for Borg's repository README