Skip to content

Commit

Permalink
Improvements to UX for mounting directories (both CLI and KopiaUI) (#573
Browse files Browse the repository at this point in the history
)

* cli: simplified mount command

See https://youtu.be/1Nt_HIl-NWQ

It will always use WebDAV on Windows and FUSE on Unix. Removed
confusing options.

New usage:

$ kopia mount [--browse]
    Mounts all snapshots in a temporary filesystem directory
    (both Unix and Windows).

$ kopia mount <object> [--browse]
    Mounts given object in a temporary filesystem directory
    (both Unix and Windows).

$ kopia mount <object> z: [--browse]
    Mounts given object as a given drive letter in Windows (using
    temporary WebDAV mount).

$ kopia mount <object> * [--browse]
    Mounts given object as a random drive letter in Windows.

$ kopia mount <object> /mount/path [--browse]
    Mounts given object in given path in Unix.

<object> can be the ID of a directory 'k<hash>' or 'all'

Optional --browse automatically opens OS-native file browser.

* htmlui: added UI for mounting directories

See https://youtu.be/T-9SshVa1d8 for a quick demo.

Also replaced some UI text with icons.

* lint: windows-specific fix
  • Loading branch information
jkowalski committed Sep 4, 2020
1 parent 90a9cf1 commit a5838ff
Show file tree
Hide file tree
Showing 20 changed files with 660 additions and 261 deletions.
50 changes: 40 additions & 10 deletions cli/command_mount.go
Expand Up @@ -4,20 +4,23 @@ import (
"context"

"github.com/pkg/errors"
"github.com/skratchdot/open-golang/open"

"github.com/kopia/kopia/fs"
"github.com/kopia/kopia/fs/cachefs"
"github.com/kopia/kopia/fs/loggingfs"
"github.com/kopia/kopia/internal/mount"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/snapshot/snapshotfs"
)

var (
mountCommand = app.Command("mount", "Mount repository object as a local filesystem.")

mountObjectID = mountCommand.Arg("path", "Identifier of the directory to mount.").Required().String()
mountPoint = mountCommand.Arg("mountPoint", "Mount point").Required().String()
mountTraceFS = mountCommand.Flag("trace-fs", "Trace filesystem operations").Bool()
mountObjectID = mountCommand.Arg("path", "Identifier of the directory to mount.").Default("all").String()
mountPoint = mountCommand.Arg("mountPoint", "Mount point").Default("*").String()
mountPointBrowse = mountCommand.Flag("browse", "Open file browser").Bool()
mountTraceFS = mountCommand.Flag("trace-fs", "Trace filesystem operations").Bool()
)

func runMountCommand(ctx context.Context, rep repo.Repository) error {
Expand All @@ -39,13 +42,40 @@ func runMountCommand(ctx context.Context, rep repo.Repository) error {

entry = cachefs.Wrap(entry, newFSCache()).(fs.Directory)

switch *mountMode {
case "FUSE":
return mountDirectoryFUSE(ctx, entry, *mountPoint)
case "WEBDAV":
return mountDirectoryWebDAV(ctx, entry, *mountPoint)
default:
return errors.Errorf("unsupported mode: %q", *mountMode)
ctrl, mountErr := mount.Directory(ctx, entry, *mountPoint)

if mountErr != nil {
return errors.Wrap(mountErr, "mount error")
}

printStderr("Mounted '%v' on %v\n", *mountObjectID, ctrl.MountPath())

if *mountPoint == "*" && !*mountPointBrowse {
printStderr("HINT: Pass --browse to automatically open file browser.\n")
}

printStderr("Press Ctrl-C to unmount.\n")

if *mountPointBrowse {
if err := open.Start(ctrl.MountPath()); err != nil {
log(ctx).Warningf("unable to browse %v", err)
}
}

// Wait until ctrl-c pressed or until the directory is unmounted.
ctrlCPressed := make(chan bool)

onCtrlC(func() {
close(ctrlCPressed)
})
select {
case <-ctrlCPressed:
printStderr("Unmounting...\n")
return ctrl.Unmount(ctx)

case <-ctrl.Done():
printStderr("Unmounted.\n")
return nil
}
}

Expand Down
78 changes: 0 additions & 78 deletions cli/command_mount_browse.go

This file was deleted.

54 changes: 0 additions & 54 deletions cli/command_mount_fuse.go

This file was deleted.

17 changes: 0 additions & 17 deletions cli/command_mount_nofuse.go

This file was deleted.

75 changes: 0 additions & 75 deletions cli/command_mount_webdav.go

This file was deleted.

13 changes: 0 additions & 13 deletions cli/config.go
Expand Up @@ -46,19 +46,6 @@ func onCtrlC(f func()) {
}()
}

func waitForCtrlC() {
// Wait until ctrl-c pressed
done := make(chan bool)

onCtrlC(func() {
if done != nil {
close(done)
done = nil
}
})
<-done
}

func openRepository(ctx context.Context, opts *repo.Options, required bool) (repo.Repository, error) {
if _, err := os.Stat(repositoryConfigFileName()); os.IsNotExist(err) && !required {
return nil, nil
Expand Down
2 changes: 1 addition & 1 deletion htmlui/env.sh
@@ -1 +1 @@
PATH=$(pwd)/../tools/.tools/node-12.16.1/node/bin:$PATH
PATH=$(pwd)/../tools/.tools/node-12.18.3/node/bin:$PATH
37 changes: 37 additions & 0 deletions htmlui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions htmlui/package.json
Expand Up @@ -3,6 +3,10 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.30",
"@fortawesome/free-regular-svg-icons": "^5.14.0",
"@fortawesome/free-solid-svg-icons": "^5.14.0",
"@fortawesome/react-fontawesome": "^0.1.11",
"@testing-library/jest-dom": "^5.1.1",
"@testing-library/react": "^9.5.0",
"axios": "^0.19.2",
Expand Down
11 changes: 10 additions & 1 deletion htmlui/src/App.css
Expand Up @@ -59,4 +59,13 @@ div.tab-body {
padding-left: 10px;
color: #aaa;
font-size: 80%;
}
}

#mountedPath {
color: #444;
width: 30em;
background-color: #ccc;
font-size: 12pt;
padding: 4px;
border: 1px solid #aaa;
}

0 comments on commit a5838ff

Please sign in to comment.