MCPcopy
hub / github.com/borgbackup/borg / __init__

Method __init__

src/borg/remote.py:556–648  ·  view source on GitHub ↗
(self, location, create=False, exclusive=False, lock_wait=1.0, lock=True, args=None)

Source from the content-addressed store, hash-verified

554 return self.args[1]
555
556 def __init__(self, location, create=False, exclusive=False, lock_wait=1.0, lock=True, args=None):
557 self.location = self._location = location
558 self.preload_ids = []
559 self.msgid = 0
560 self.rx_bytes = 0
561 self.tx_bytes = 0
562 self.to_send = EfficientCollectionQueue(1024 * 1024, bytes)
563 self.stdin_fd = self.stdout_fd = self.stderr_fd = None
564 self.stderr_received = b"" # incomplete stderr line bytes received (no \n yet)
565 self.chunkid_to_msgids = {}
566 self.ignore_responses = set()
567 self.responses = {}
568 self.async_responses = {}
569 self.shutdown_time = None
570 self.ratelimit = SleepingBandwidthLimiter(args.upload_ratelimit * 1024 if args and args.upload_ratelimit else 0)
571 self.upload_buffer_size_limit = args.upload_buffer * 1024 * 1024 if args and args.upload_buffer else 0
572 self.unpacker = get_limited_unpacker("client")
573 self.server_version = None # we update this after server sends its version
574 self.p = self.sock = None
575 self._args = args
576 if self.location.proto == "ssh":
577 testing = location.host == "__testsuite__"
578 # when testing, we invoke and talk to a borg process directly (no ssh).
579 # when not testing, we invoke the system-installed ssh binary to talk to a remote borg.
580 env = prepare_subprocess_env(system=not testing)
581 borg_cmd = self.borg_cmd(args, testing)
582 if not testing:
583 borg_cmd = self.ssh_cmd(location) + borg_cmd
584 logger.debug("SSH command line: %s", borg_cmd)
585 # we do not want the ssh getting killed by Ctrl-C/SIGINT because it is needed for clean shutdown of borg.
586 self.p = Popen(
587 borg_cmd,
588 bufsize=0,
589 stdin=PIPE,
590 stdout=PIPE,
591 stderr=PIPE,
592 env=env,
593 preexec_fn=None if is_win32 else ignore_sigint,
594 ) # nosec B603
595 self.stdin_fd = self.p.stdin.fileno()
596 self.stdout_fd = self.p.stdout.fileno()
597 self.stderr_fd = self.p.stderr.fileno()
598 self.r_fds = [self.stdout_fd, self.stderr_fd]
599 self.x_fds = [self.stdin_fd, self.stdout_fd, self.stderr_fd]
600 elif self.location.proto == "socket":
601 if args.use_socket is False or args.use_socket is True: # nothing or --socket
602 socket_path = get_socket_filename()
603 else: # --socket=/some/path
604 socket_path = args.use_socket
605 self.sock = socket.socket(family=socket.AF_UNIX, type=socket.SOCK_STREAM)
606 try:
607 self.sock.connect(socket_path) # note: socket_path length is rather limited.
608 except FileNotFoundError:
609 self.sock = None
610 raise Error(f"The socket file {socket_path} does not exist.")
611 except ConnectionRefusedError:
612 self.sock = None
613 raise Error(f"There is no borg serve running for the socket file {socket_path}.")

Callers

nothing calls this directly

Calls 15

borg_cmdMethod · 0.95
ssh_cmdMethod · 0.95
callMethod · 0.95
openMethod · 0.95
infoMethod · 0.95
closeMethod · 0.95
get_limited_unpackerFunction · 0.85
prepare_subprocess_envFunction · 0.85
get_socket_filenameFunction · 0.85
ErrorClass · 0.85
debugMethod · 0.80

Tested by

no test coverage detected