Skip to content

Commit

Permalink
libfuse:- create mountdir if it does not exist on linux
Browse files Browse the repository at this point in the history
Move creation logic out of kbfsfuse/main.
See
- keybase/kbfs#1669
- keybase/kbfs#1655
  • Loading branch information
heronhaye authored and heronhaye committed Jan 14, 2019
1 parent 0501af1 commit 0ae9ccc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
18 changes: 3 additions & 15 deletions go/kbfs/kbfsfuse/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"flag"
"fmt"
"os"
"runtime"

"bazil.org/fuse"

Expand Down Expand Up @@ -76,27 +75,16 @@ func start() *libfs.Error {
if err != nil {
return libfs.InitError(err.Error())
}
// If a mountdir was not set by keybase config set mountdir,
// the service returns a default value which may or may not
// exist yet.
if len(mountDir) == 0 {
fmt.Print(getUsageString(ctx))
return libfs.InitError("no mount specified")
}
} else {
mountDir = flag.Arg(0)
}
err := os.MkdirAll(mountDir, os.ModePerm)
if err != nil {
fmt.Println(err)
switch os := runtime.GOOS; os {
case "linux":
fmt.Println("failed to create mount directory")
case "darwin":
// If the user did not override the defaults this isn't expected to work.
// The default is in a directory only writable by root.
fmt.Println("mount directory does not exist and should have been created by system service")
case "windows":
fmt.Println("I honestly have no idea what to say here, maybe someone can tell me what is supposed to create this on Windows")
}
}

if len(flag.Args()) > 1 {
fmt.Print(getUsageString(ctx))
Expand Down
13 changes: 13 additions & 0 deletions go/kbfs/libfuse/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import (

"bazil.org/fuse"
"github.com/keybase/client/go/kbconst"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/logger"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
)

type mounter struct {
Expand Down Expand Up @@ -52,6 +54,17 @@ func (m *mounter) Mount() (err error) {
}

func fuseMountDir(dir string, platformParams PlatformParams) (*fuse.Conn, error) {
// Create mountdir directory on Linux
switch libkb.RuntimeGroup() {
case keybase1.RuntimeGroup_UNIXLIKE:
// Inherit permissions from containing directory and umask
err := os.MkdirAll(dir, os.ModeDir|os.ModePerm)
if err != nil {
return nil, err
}
default:
}

fi, err := os.Stat(dir)
if err != nil {
return nil, err
Expand Down

0 comments on commit 0ae9ccc

Please sign in to comment.