mirror of
https://github.com/kopia/kopia.git
synced 2026-01-24 06:18:02 -05:00
55 lines
1.0 KiB
Go
55 lines
1.0 KiB
Go
// +build !windows
|
|
|
|
package cli
|
|
|
|
import (
|
|
"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(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.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
|
|
}
|