Skip to content

Commit

Permalink
refactor: rename repository/locking classes/modules
Browse files Browse the repository at this point in the history
Repository -> LegacyRepository
RemoteRepository -> LegacyRemoteRepository
borg.repository -> borg.legacyrepository
borg.remote -> borg.legacyremote

Repository3 -> Repository
RemoteRepository3 -> RemoteRepository
borg.repository3 -> borg.repository
borg.remote3 -> borg.remote

borg.locking -> borg.fslocking
borg.locking3 -> borg.storelocking
  • Loading branch information
ThomasWaldmann committed Aug 23, 2024
1 parent 89268fe commit 6af66d4
Show file tree
Hide file tree
Showing 36 changed files with 3,634 additions and 3,636 deletions.
13 changes: 6 additions & 7 deletions src/borg/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@
from .patterns import PathPrefixPattern, FnmatchPattern, IECommand
from .item import Item, ArchiveItem, ItemDiff
from .platform import acl_get, acl_set, set_flags, get_flags, swidth, hostname
from .remote import cache_if_remote
from .remote3 import RemoteRepository3
from .repository3 import Repository3, LIST_SCAN_LIMIT, NoManifestError
from .remote import RemoteRepository, cache_if_remote
from .repository import Repository, LIST_SCAN_LIMIT, NoManifestError
from .repoobj import RepoObj

has_link = hasattr(os, "link")
Expand Down Expand Up @@ -1655,7 +1654,7 @@ def check(
self.repair = repair
self.repository = repository
self.init_chunks()
if not isinstance(repository, (Repository3, RemoteRepository3)) and not self.chunks:
if not isinstance(repository, (Repository, RemoteRepository)) and not self.chunks:
logger.error("Repository contains no apparent data at all, cannot continue check/repair.")
return False
self.key = self.make_key(repository)
Expand All @@ -1673,7 +1672,7 @@ def check(
except IntegrityErrorBase as exc:
logger.error("Repository manifest is corrupted: %s", exc)
self.error_found = True
if not isinstance(repository, (Repository3, RemoteRepository3)):
if not isinstance(repository, (Repository, RemoteRepository)):
del self.chunks[Manifest.MANIFEST_ID]
self.manifest = self.rebuild_manifest()
self.rebuild_refcounts(
Expand Down Expand Up @@ -1758,7 +1757,7 @@ def verify_data(self):
chunk_id = chunk_ids_revd.pop(-1) # better efficiency
try:
encrypted_data = next(chunk_data_iter)
except (Repository3.ObjectNotFound, IntegrityErrorBase) as err:
except (Repository.ObjectNotFound, IntegrityErrorBase) as err:
self.error_found = True
errors += 1
logger.error("chunk %s: %s", bin_to_hex(chunk_id), err)
Expand Down Expand Up @@ -1889,7 +1888,7 @@ def rebuild_refcounts(
Missing and/or incorrect data is repaired when detected
"""
# Exclude the manifest from chunks (manifest entry might be already deleted from self.chunks)
if not isinstance(self.repository, (Repository3, RemoteRepository3)):
if not isinstance(self.repository, (Repository, RemoteRepository)):
self.chunks.pop(Manifest.MANIFEST_ID, None)

def mark_as_possibly_superseded(id_):
Expand Down
6 changes: 3 additions & 3 deletions src/borg/archiver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from ..helpers import ErrorIgnoringTextIOWrapper
from ..helpers import msgpack
from ..helpers import sig_int
from ..remote3 import RemoteRepository3
from ..remote import RemoteRepository
from ..selftest import selftest
except BaseException:
# an unhandled exception in the try-block would cause the borg cli command to exit with rc 1 due to python's
Expand Down Expand Up @@ -546,7 +546,7 @@ def sig_trace_handler(sig_no, stack): # pragma: no cover

def format_tb(exc):
qualname = type(exc).__qualname__
remote = isinstance(exc, RemoteRepository3.RPCError)
remote = isinstance(exc, RemoteRepository.RPCError)
if remote:
prefix = "Borg server: "
trace_back = "\n".join(prefix + line for line in exc.exception_full.splitlines())
Expand Down Expand Up @@ -624,7 +624,7 @@ def main(): # pragma: no cover
tb_log_level = logging.ERROR if e.traceback else logging.DEBUG
tb = format_tb(e)
exit_code = e.exit_code
except RemoteRepository3.RPCError as e:
except RemoteRepository.RPCError as e:
important = e.traceback
msg = e.exception_full if important else e.get_message()
msgid = e.exception_class
Expand Down
8 changes: 4 additions & 4 deletions src/borg/archiver/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
from ..helpers.nanorst import rst_to_terminal
from ..manifest import Manifest, AI_HUMAN_SORT_KEYS
from ..patterns import PatternMatcher
from ..legacyremote import LegacyRemoteRepository
from ..remote import RemoteRepository
from ..remote3 import RemoteRepository3
from ..legacyrepository import LegacyRepository
from ..repository import Repository
from ..repository3 import Repository3
from ..repoobj import RepoObj, RepoObj1
from ..patterns import (
ArgparsePatternAction,
Expand All @@ -34,7 +34,7 @@ def get_repository(
location, *, create, exclusive, lock_wait, lock, append_only, make_parent_dirs, storage_quota, args, v1_or_v2
):
if location.proto in ("ssh", "socket"):
RemoteRepoCls = RemoteRepository if v1_or_v2 else RemoteRepository3
RemoteRepoCls = LegacyRemoteRepository if v1_or_v2 else RemoteRepository
repository = RemoteRepoCls(
location,
create=create,
Expand All @@ -47,7 +47,7 @@ def get_repository(
)

else:
RepoCls = Repository if v1_or_v2 else Repository3
RepoCls = LegacyRepository if v1_or_v2 else Repository
repository = RepoCls(
location.path,
create=create,
Expand Down
6 changes: 3 additions & 3 deletions src/borg/archiver/compact_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from ..helpers import set_ec, EXIT_WARNING, EXIT_ERROR, format_file_size
from ..helpers import ProgressIndicatorPercent
from ..manifest import Manifest
from ..remote3 import RemoteRepository3
from ..repository3 import Repository3
from ..remote import RemoteRepository
from ..repository import Repository

from ..logger import create_logger

Expand All @@ -18,7 +18,7 @@
class ArchiveGarbageCollector:
def __init__(self, repository, manifest):
self.repository = repository
assert isinstance(repository, (Repository3, RemoteRepository3))
assert isinstance(repository, (Repository, RemoteRepository))
self.manifest = manifest
self.repository_chunks = None # what we have in the repository
self.used_chunks = None # what archives currently reference
Expand Down
5 changes: 2 additions & 3 deletions src/borg/archiver/debug_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
from ..helpers import CommandError, RTError
from ..manifest import Manifest
from ..platform import get_process_id
from ..repository import Repository
from ..repository3 import Repository3, LIST_SCAN_LIMIT
from ..repository import Repository, LIST_SCAN_LIMIT
from ..repoobj import RepoObj

from ._common import with_repository, Highlander
Expand Down Expand Up @@ -306,7 +305,7 @@ def do_debug_delete_obj(self, args, repository):
try:
repository.delete(id)
print("object %s deleted." % hex_id)
except Repository3.ObjectNotFound:
except Repository.ObjectNotFound:
print("object %s not found." % hex_id)
print("Done.")

Expand Down
6 changes: 3 additions & 3 deletions src/borg/archiver/rcompress_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from ..constants import * # NOQA
from ..compress import CompressionSpec, ObfuscateSize, Auto, COMPRESSOR_TABLE
from ..helpers import sig_int, ProgressIndicatorPercent, Error
from ..repository3 import Repository3
from ..remote3 import RemoteRepository3
from ..repository import Repository
from ..remote import RemoteRepository
from ..manifest import Manifest

from ..logger import create_logger
Expand Down Expand Up @@ -111,7 +111,7 @@ def get_csettings(c):
recompress_candidate_count = len(recompress_ids)
chunks_limit = min(1000, max(100, recompress_candidate_count // 1000))

if not isinstance(repository, (Repository3, RemoteRepository3)):
if not isinstance(repository, (Repository, RemoteRepository)):
# start a new transaction
data = repository.get_manifest()
repository.put_manifest(data)
Expand Down
2 changes: 1 addition & 1 deletion src/borg/archiver/serve_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ._common import Highlander
from ..constants import * # NOQA
from ..helpers import parse_storage_quota
from ..remote3 import RepositoryServer
from ..remote import RepositoryServer

from ..logger import create_logger

Expand Down
4 changes: 2 additions & 2 deletions src/borg/archiver/version_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .. import __version__
from ..constants import * # NOQA
from ..remote3 import RemoteRepository3
from ..remote import RemoteRepository

from ..logger import create_logger

Expand All @@ -16,7 +16,7 @@ def do_version(self, args):

client_version = parse_version(__version__)
if args.location.proto in ("ssh", "socket"):
with RemoteRepository3(args.location, lock=False, args=args) as repository:
with RemoteRepository(args.location, lock=False, args=args) as repository:
server_version = repository.server_version
else:
server_version = client_version
Expand Down
8 changes: 4 additions & 4 deletions src/borg/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
from .item import ChunkListEntry
from .crypto.key import PlaintextKey
from .crypto.file_integrity import IntegrityCheckedFile, FileIntegrityError
from .locking import Lock
from .fslocking import Lock
from .manifest import Manifest
from .platform import SaveFile
from .remote3 import RemoteRepository3
from .repository3 import LIST_SCAN_LIMIT, Repository3
from .remote import RemoteRepository
from .repository import LIST_SCAN_LIMIT, Repository

# note: cmtime might be either a ctime or a mtime timestamp, chunks is a list of ChunkListEntry
FileCacheEntry = namedtuple("FileCacheEntry", "age inode size cmtime chunks")
Expand Down Expand Up @@ -648,7 +648,7 @@ def _load_chunks_from_repo(self):
num_chunks += 1
chunks[id_] = init_entry
# Cache does not contain the manifest.
if not isinstance(self.repository, (Repository3, RemoteRepository3)):
if not isinstance(self.repository, (Repository, RemoteRepository)):
del chunks[self.manifest.MANIFEST_ID]
duration = perf_counter() - t0 or 0.01
logger.debug(
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/borg/fuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def async_wrapper(fn):
from .item import Item
from .platform import uid2user, gid2group
from .platformflags import is_darwin
from .remote3 import RemoteRepository3
from .remote import RemoteRepository


def fuse_main():
Expand Down Expand Up @@ -546,7 +546,7 @@ def pop_option(options, key, present, not_present, wanted_type, int_base=0):
self._create_filesystem()
llfuse.init(self, mountpoint, options)
if not foreground:
if isinstance(self.repository_uncached, RemoteRepository3):
if isinstance(self.repository_uncached, RemoteRepository):
daemonize()
else:
with daemonizing() as (old_id, new_id):
Expand Down
2 changes: 1 addition & 1 deletion src/borg/helpers/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def safe_unlink(path):
Use this when deleting potentially large files when recovering
from a VFS error such as ENOSPC. It can help a full file system
recover. Refer to the "File system interaction" section
in repository.py for further explanations.
in legacyrepository.py for further explanations.
"""
try:
os.unlink(path)
Expand Down
6 changes: 3 additions & 3 deletions src/borg/helpers/parseformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,14 +1163,14 @@ def ellipsis_truncate(msg, space):

class BorgJsonEncoder(json.JSONEncoder):
def default(self, o):
from ..legacyrepository import LegacyRepository
from ..repository import Repository
from ..repository3 import Repository3
from ..legacyremote import LegacyRemoteRepository
from ..remote import RemoteRepository
from ..remote3 import RemoteRepository3
from ..archive import Archive
from ..cache import AdHocCache, AdHocWithFilesCache

if isinstance(o, (Repository, RemoteRepository)) or isinstance(o, (Repository3, RemoteRepository3)):
if isinstance(o, (LegacyRepository, LegacyRemoteRepository)) or isinstance(o, (Repository, RemoteRepository)):
return {"id": bin_to_hex(o.id), "location": o._location.canonical_path()}
if isinstance(o, Archive):
return o.info()
Expand Down
Loading

0 comments on commit 6af66d4

Please sign in to comment.