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

Method mount

src/borg/fuse.py:516–611  ·  view source on GitHub ↗

Mount filesystem on *mountpoint* with *mount_options*.

(self, mountpoint, mount_options, foreground=False, show_rc=False)

Source from the content-addressed store, hash-verified

514 self.decrypted_repository.log_instrumentation()
515
516 def mount(self, mountpoint, mount_options, foreground=False, show_rc=False):
517 """Mount filesystem on *mountpoint* with *mount_options*."""
518
519 def pop_option(options, key, present, not_present, wanted_type, int_base=0):
520 assert isinstance(options, list) # we mutate this
521 for idx, option in enumerate(options):
522 if option == key:
523 options.pop(idx)
524 return present
525 if option.startswith(key + "="):
526 options.pop(idx)
527 value = option.split("=", 1)[1]
528 if wanted_type is bool:
529 v = value.lower()
530 if v in ("y", "yes", "true", "1"):
531 return True
532 if v in ("n", "no", "false", "0"):
533 return False
534 raise ValueError("unsupported value in option: %s" % option)
535 if wanted_type is int:
536 try:
537 return int(value, base=int_base)
538 except ValueError:
539 raise ValueError("unsupported value in option: %s" % option) from None
540 try:
541 return wanted_type(value)
542 except ValueError:
543 raise ValueError("unsupported value in option: %s" % option) from None
544 else:
545 return not_present
546
547 # default_permissions enables permission checking by the kernel. Without
548 # this, any umask (or uid/gid) would not have an effect and this could
549 # cause security issues if used with allow_other mount option.
550 # When not using allow_other or allow_root, access is limited to the
551 # mounting user anyway.
552 options = ["fsname=borgfs", "ro", "default_permissions"]
553 if mount_options:
554 options.extend(mount_options.split(","))
555 if is_darwin:
556 # macFUSE supports a volname mount option to give what finder displays on desktop / in directory list.
557 volname = pop_option(options, "volname", "", "", str)
558 # if the user did not specify it, we make something up,
559 # because otherwise it would be "macFUSE Volume 0 (Python)", #7690.
560 volname = volname or f"{os.path.basename(mountpoint)} (borgfs)"
561 options.append(f"volname={volname}")
562 ignore_permissions = pop_option(options, "ignore_permissions", True, False, bool)
563 if ignore_permissions:
564 # in case users have a use-case that requires NOT giving "default_permissions",
565 # this is enabled by the custom "ignore_permissions" mount option which just
566 # removes "default_permissions" again:
567 pop_option(options, "default_permissions", True, False, bool)
568 self.allow_damaged_files = pop_option(options, "allow_damaged_files", True, False, bool)
569 self.versions = pop_option(options, "versions", True, False, bool)
570 self.uid_forced = pop_option(options, "uid", None, None, int)
571 self.gid_forced = pop_option(options, "gid", None, None, int)
572 self.umask = pop_option(options, "umask", 0, 0, int, int_base=8) # umask is octal, e.g. 222 or 0222
573 dir_uid = self.uid_forced if self.uid_forced is not None else self.default_uid

Callers 1

_do_mountMethod · 0.95

Calls 11

uid2userFunction · 0.85
gid2groupFunction · 0.85
daemonizeFunction · 0.85
daemonizingFunction · 0.85
signal_handlerFunction · 0.85
fuse_mainFunction · 0.85
warningMethod · 0.80
debugMethod · 0.80
_create_filesystemMethod · 0.45
migrate_lockMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected