Files
kopia/cli/command_mount_fuse.go
Jarek Kowalski c8fcae93aa logging: refactored logging
This is mostly mechanical and changes how loggers are instantiated.

Logger is now associated with a context, passed around all methods,
(most methods had ctx, but had to add it in a few missing places).

By default Kopia does not produce any logs, but it can be overridden,
either locally for a nested context, by calling

ctx = logging.WithLogger(ctx, newLoggerFunc)

To override logs globally, call logging.SetDefaultLogger(newLoggerFunc)

This refactoring allowed removing dependency from Kopia repo
and go-logging library (the CLI still uses it, though).

It is now also possible to have all test methods emit logs using
t.Logf() so that they show up in failure reports, which should make
debugging of test failures suck less.
2020-02-25 17:24:44 -08:00

58 lines
1.1 KiB
Go

// +build !windows
package cli
import (
"context"
"bazil.org/fuse"
fusefs "bazil.org/fuse/fs"
"github.com/kopia/kopia/fs"
"github.com/kopia/kopia/internal/fusemount"
)
type root struct {
fusefs.Node
}
func (r *root) Root() (fusefs.Node, error) {
return r.Node, nil
}
var (
mountMode = mountCommand.Flag("mode", "Mount mode").Default("FUSE").Enum("WEBDAV", "FUSE")
)
func mountDirectoryFUSE(ctx context.Context, entry fs.Directory, mountPoint string) error {
rootNode := fusemount.NewDirectoryNode(entry)
fuseConnection, err := fuse.Mount(
mountPoint,
fuse.ReadOnly(),
fuse.FSName("kopia"),
fuse.Subtype("kopia"),
fuse.VolumeName("Kopia"),
)
if err != nil {
return err
}
defer fuseConnection.Close() //nolint:errcheck
onCtrlC(func() {
if unmounterr := fuse.Unmount(mountPoint); unmounterr != nil {
log(ctx).Warningf("unmount failed: %v", unmounterr)
}
})
err = fusefs.Serve(fuseConnection, &root{rootNode})
if err != nil {
return err
}
// wait for mount to stop.
<-fuseConnection.Ready
return fuseConnection.MountError
}