move PathNotAllowed to helpers/errors.py

PathNotAllowed lived in borg.legacy.remote, but borg serve --rest
(non-legacy) now also raises it via check_rest_restrictions, which made
non-legacy code import from the legacy package just for an exception.

It is a generic "repository path not allowed" error, so move it next to
the other cross-cutting Error subclasses in helpers/errors.py and
re-export it from helpers. Pure relocation; exit code stays 83.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Thomas Waldmann 2026-06-08 20:47:56 +02:00
parent 2741265463
commit 17aecfef6e
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01
5 changed files with 11 additions and 12 deletions

View file

@ -1,7 +1,7 @@
import os
from ..constants import * # NOQA
from ..helpers import Error
from ..helpers import Error, PathNotAllowed
from ..legacy.remote import RepositoryServer
from ..logger import create_logger
@ -38,8 +38,6 @@ class ServeMixIn:
@staticmethod
def check_rest_restrictions(backend, restrict_to_paths, restrict_to_repositories):
from ..legacy.remote import PathNotAllowed
if not (restrict_to_paths or restrict_to_repositories):
return
if not backend.startswith("FILE:"):

View file

@ -13,7 +13,7 @@ from ..constants import * # NOQA
from .datastruct import StableDict, Buffer, EfficientCollectionQueue
from .errors import Error, ErrorWithTraceback, IntegrityError, DecompressionError, CancelledByUser, CommandError
from .errors import RTError, modern_ec
from .errors import RTError, PathNotAllowed, modern_ec
from .errors import BorgWarning, FileChangedWarning, BackupWarning, IncludePatternNeverMatchedWarning
from .errors import BackupError, BackupOSError, BackupRaceConditionError, BackupItemExcluded
from .errors import BackupPermissionError, BackupIOError, BackupFileNotFoundError

View file

@ -76,6 +76,12 @@ class CommandError(Error):
exit_mcode = 4
class PathNotAllowed(Error):
"""Repository path not allowed: {}."""
exit_mcode = 83
class BorgWarning:
"""Warning: {}"""

View file

@ -16,7 +16,7 @@ from subprocess import Popen, PIPE
import borg.logger
from .. import __version__
from ..constants import * # NOQA
from ..helpers import Error, ErrorWithTraceback, IntegrityError
from ..helpers import Error, ErrorWithTraceback, IntegrityError, PathNotAllowed
from ..helpers import bin_to_hex
from ..helpers import get_limited_unpacker
from ..helpers import replace_placeholders
@ -55,12 +55,6 @@ class ConnectionClosedWithHint(ConnectionClosed):
exit_mcode = 81
class PathNotAllowed(Error):
"""Repository path not allowed: {}."""
exit_mcode = 83
class InvalidRPCMethod(Error):
"""RPC method {} is not valid."""

View file

@ -8,10 +8,11 @@ import pytest
from ..legacy.hashindex import NSIndex1
from ..helpers import Location
from ..helpers import IntegrityError
from ..helpers import PathNotAllowed
from ..helpers import msgpack
from ..fslocking import Lock, LockFailed
from ..platformflags import is_win32
from ..legacy.remote import LegacyRemoteRepository, InvalidRPCMethod, PathNotAllowed
from ..legacy.remote import LegacyRemoteRepository, InvalidRPCMethod
from ..legacy.repository import LegacyRepository, LoggedIO
from ..legacy.repository import MAGIC, MAX_DATA_SIZE, TAG_DELETE, TAG_PUT, TAG_COMMIT
from ..compress import CNONE