Skip to content

Commit

Permalink
Merge pull request #8054 from ThomasWaldmann/more-errors-msgids-1.4
Browse files Browse the repository at this point in the history
more specific errors / msgids (1.4-maint)
  • Loading branch information
ThomasWaldmann committed Jan 20, 2024
2 parents 266c9f6 + 5d956b9 commit a423092
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/internals/frontends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ Errors
There is already something at {}.
Repository.StorageQuotaExceeded rc: 20 traceback: no
The storage quota ({}) has been exceeded ({}). Try deleting some archives.
Repository.PathPermissionDenied rc: 21 traceback: no
Permission denied to {}.

MandatoryFeatureUnsupported rc: 25 traceback: no
Unsupported repository feature(s) {}. A newer version of borg is required to access this repository.
Expand Down Expand Up @@ -669,6 +671,8 @@ Errors
UnexpectedRPCDataFormatFromServer rc: 86 traceback: no
Got unexpected RPC data format from server:
{}
ConnectionBrokenWithHint rc: 87 traceback: no
Connection to remote host is broken. {}

IntegrityError rc: 90 traceback: yes
Data integrity error: {}
Expand Down
12 changes: 11 additions & 1 deletion src/borg/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ def __init__(self, data):
super().__init__(data)


class ConnectionBrokenWithHint(Error):
"""Connection to remote host is broken. {}"""
exit_mcode = 87


# Protocol compatibility:
# In general the server is responsible for rejecting too old clients and the client it responsible for rejecting
# too old servers. This ensures that the knowledge what is compatible is always held by the newer component.
Expand Down Expand Up @@ -421,7 +426,10 @@ def write(self, fd, to_send):
self.ratelimit_last = time.monotonic()
if len(to_send) > self.ratelimit_quota:
to_send = to_send[:self.ratelimit_quota]
written = os.write(fd, to_send)
try:
written = os.write(fd, to_send)
except BrokenPipeError:
raise ConnectionBrokenWithHint("Broken Pipe") from None
if self.ratelimit:
self.ratelimit_quota -= written
return written
Expand Down Expand Up @@ -772,6 +780,8 @@ def handle_error(unpacked):
raise PathNotAllowed('(unknown)')
else:
raise PathNotAllowed(args[0].decode())
elif error == 'PathPermissionDenied':
raise Repository.PathPermissionDenied(args[0].decode())
elif error == 'ParentPathDoesNotExist':
raise Repository.ParentPathDoesNotExist(args[0].decode())
elif error == 'ObjectNotFound':
Expand Down
18 changes: 16 additions & 2 deletions src/borg/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ class StorageQuotaExceeded(Error):
"""The storage quota ({}) has been exceeded ({}). Try deleting some archives."""
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,
append_only=False, storage_quota=None, check_segment_magic=True,
make_parent_dirs=False):
Expand Down Expand Up @@ -261,13 +265,23 @@ def check_can_create_repository(self, path):
st = os.stat(path)
except FileNotFoundError:
pass # nothing there!
except PermissionError:
raise self.PathPermissionDenied(path) from None
else:
# there is something already there!
if self.is_repository(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)
# 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:
# Check all parent directories for Borg's repository README
Expand Down

0 comments on commit a423092

Please sign in to comment.