MCPcopy Index your code
hub / github.com/borgbackup/borg / __init__

Method __init__

src/borg/legacyremote.py:250–347  ·  view source on GitHub ↗
(self, location, create=False, exclusive=False, lock_wait=None, lock=True, args=None)

Source from the content-addressed store, hash-verified

248 return self.args[1]
249
250 def __init__(self, location, create=False, exclusive=False, lock_wait=None, lock=True, args=None):
251 self.location = self._location = location
252 self.preload_ids = []
253 self.msgid = 0
254 self.rx_bytes = 0
255 self.tx_bytes = 0
256 self.to_send = EfficientCollectionQueue(1024 * 1024, bytes)
257 self.stdin_fd = self.stdout_fd = self.stderr_fd = None
258 self.stderr_received = b"" # incomplete stderr line bytes received (no \n yet)
259 self.chunkid_to_msgids = {}
260 self.ignore_responses = set()
261 self.responses = {}
262 self.async_responses = {}
263 self.shutdown_time = None
264 self.ratelimit = SleepingBandwidthLimiter(args.upload_ratelimit * 1024 if args and args.upload_ratelimit else 0)
265 self.upload_buffer_size_limit = args.upload_buffer * 1024 * 1024 if args and args.upload_buffer else 0
266 self.unpacker = get_limited_unpacker("client")
267 self.server_version = None # we update this after server sends its version
268 self.p = self.sock = None
269 self._args = args
270 if self.location.proto == "ssh":
271 testing = location.host == "__testsuite__"
272 # when testing, we invoke and talk to a borg process directly (no ssh).
273 # when not testing, we invoke the system-installed ssh binary to talk to a remote borg.
274 env = prepare_subprocess_env(system=not testing)
275 borg_cmd = self.borg_cmd(args, testing)
276 if not testing:
277 borg_cmd = self.ssh_cmd(location) + borg_cmd
278 logger.debug("SSH command line: %s", borg_cmd)
279 # we do not want the ssh getting killed by Ctrl-C/SIGINT because it is needed for clean shutdown of borg.
280 self.p = Popen(
281 borg_cmd,
282 bufsize=0,
283 stdin=PIPE,
284 stdout=PIPE,
285 stderr=PIPE,
286 env=env,
287 preexec_fn=None if is_win32 else ignore_sigint,
288 ) # nosec B603
289 self.stdin_fd = self.p.stdin.fileno()
290 self.stdout_fd = self.p.stdout.fileno()
291 self.stderr_fd = self.p.stderr.fileno()
292 self.r_fds = [self.stdout_fd, self.stderr_fd]
293 self.x_fds = [self.stdin_fd, self.stdout_fd, self.stderr_fd]
294 elif self.location.proto == "socket":
295 if args.use_socket is False or args.use_socket is True: # nothing or --socket
296 socket_path = get_socket_filename()
297 else: # --socket=/some/path
298 socket_path = args.use_socket
299 self.sock = socket.socket(family=socket.AF_UNIX, type=socket.SOCK_STREAM)
300 try:
301 self.sock.connect(socket_path) # note: socket_path length is rather limited.
302 except FileNotFoundError:
303 self.sock = None
304 raise Error(f"The socket file {socket_path} does not exist.")
305 except ConnectionRefusedError:
306 self.sock = None
307 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