(ctx context.Context, rep repo.Repository)
| 55 | } |
| 56 | |
| 57 | func (c *commandMount) run(ctx context.Context, rep repo.Repository) error { |
| 58 | var entry fs.Directory |
| 59 | |
| 60 | if c.mountObjectID == "all" { |
| 61 | entry = snapshotfs.AllSourcesEntry(rep) |
| 62 | } else { |
| 63 | var err error |
| 64 | |
| 65 | entry, err = snapshotfs.FilesystemDirectoryFromIDWithPath(ctx, rep, c.mountObjectID, false) |
| 66 | if err != nil { |
| 67 | return errors.Wrapf(err, "unable to get directory entry for %v", c.mountObjectID) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | if c.mountTraceFS { |
| 72 | //nolint:forcetypeassert |
| 73 | entry = loggingfs.Wrap(entry, log(ctx).Debugf).(fs.Directory) |
| 74 | } |
| 75 | |
| 76 | //nolint:forcetypeassert |
| 77 | entry = cachefs.Wrap(entry, c.newFSCache()).(fs.Directory) |
| 78 | |
| 79 | ctrl, mountErr := mount.Directory(ctx, entry, c.mountPoint, |
| 80 | mount.Options{ |
| 81 | FuseAllowOther: c.mountFuseAllowOther, |
| 82 | FuseAllowNonEmptyMount: c.mountFuseAllowNonEmptyMount, |
| 83 | PreferWebDAV: c.mountPreferWebDAV, |
| 84 | }) |
| 85 | if mountErr != nil { |
| 86 | return errors.Wrap(mountErr, "mount error") |
| 87 | } |
| 88 | |
| 89 | log(ctx).Infof("Mounted '%v' on %v", c.mountObjectID, ctrl.MountPath()) |
| 90 | |
| 91 | if c.mountPoint == "*" && !c.mountPointBrowse { |
| 92 | log(ctx).Info("HINT: Pass --browse to automatically open file browser.") |
| 93 | } |
| 94 | |
| 95 | log(ctx).Info("Press Ctrl-C to unmount.") |
| 96 | |
| 97 | if c.mountPointBrowse { |
| 98 | if err := open.Start(ctrl.MountPath()); err != nil { |
| 99 | log(ctx).Errorf("unable to browse %v", err) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // Wait until ctrl-c pressed or until the directory is unmounted. |
| 104 | ctrlCPressed := make(chan bool) |
| 105 | |
| 106 | c.svc.onTerminate(func() { |
| 107 | close(ctrlCPressed) |
| 108 | }) |
| 109 | |
| 110 | select { |
| 111 | case <-ctrlCPressed: |
| 112 | log(ctx).Info("Unmounting...") |
| 113 | // TODO: Consider lazy unmounting (-z) and polling till the filesystem is unmounted instead of failing with: |
| 114 | // "unmount error: exit status 1: fusermount: failed to unmount /tmp/kopia-mount719819963: Device or resource busy, try --help" |
nothing calls this directly
no test coverage detected