Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement unix domain (ipc) socket support #7519

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/borg/archiver/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


def get_repository(location, *, create, exclusive, lock_wait, lock, append_only, make_parent_dirs, storage_quota, args):
if location.proto == "ssh":
if location.proto in ("ssh", "socket"):
repository = RemoteRepository(
location,
create=create,
Expand Down
8 changes: 8 additions & 0 deletions src/borg/archiver/serve_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def do_serve(self, args):
restrict_to_repositories=args.restrict_to_repositories,
append_only=args.append_only,
storage_quota=args.storage_quota,
socket_path=args.socket_path,
).serve()
return EXIT_SUCCESS

Expand Down Expand Up @@ -82,3 +83,10 @@ def build_parser_serve(self, subparsers, common_parser, mid_common_parser):
"When a new repository is initialized, sets the storage quota on the new "
"repository as well. Default: no quota.",
)
subparser.add_argument(
"--socket",
metavar="PATH",
dest="socket_path",
action=Highlander,
help="create a UNIX DOMAIN (IPC) socket at PATH and listen on it.",
)
19 changes: 16 additions & 3 deletions src/borg/helpers/parseformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ class Location:
# path must not contain :: (it ends at :: or string end), but may contain single colons.
# to avoid ambiguities with other regexes, it must also not start with ":" nor with "//" nor with "ssh://".
local_path_re = r"""
(?!(:|//|ssh://)) # not starting with ":" or // or ssh://
(?!(:|//|ssh://|socket://)) # not starting with ":" or // or ssh:// or socket://
(?P<path>([^:]|(:(?!:)))+) # any chars, but no "::"
"""

Expand Down Expand Up @@ -421,6 +421,14 @@ class Location:
re.VERBOSE,
) # path

socket_re = re.compile(
r"""
(?P<proto>socket):// # socket://
"""
+ abs_path_re,
re.VERBOSE,
) # path

file_re = re.compile(
r"""
(?P<proto>file):// # file://
Expand Down Expand Up @@ -485,6 +493,11 @@ def normpath_special(p):
self.path = normpath_special(m.group("path"))
return True
m = self.file_re.match(text)
if m:
self.proto = m.group("proto")
self.path = normpath_special(m.group("path"))
return True
m = self.socket_re.match(text)
if m:
self.proto = m.group("proto")
self.path = normpath_special(m.group("path"))
Expand All @@ -508,7 +521,7 @@ def __str__(self):

def to_key_filename(self):
name = re.sub(r"[^\w]", "_", self.path).strip("_")
if self.proto != "file":
if self.proto not in ("file", "socket"):
name = re.sub(r"[^\w]", "_", self.host) + "__" + name
if len(name) > 100:
# Limit file names to some reasonable length. Most file systems
Expand All @@ -527,7 +540,7 @@ def host(self):
return self._host.lstrip("[").rstrip("]")

def canonical_path(self):
if self.proto == "file":
if self.proto in ("file", "socket"):
return self.path
else:
if self.path and self.path.startswith("~"):
Expand Down
Loading