forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.go
78 lines (64 loc) · 1.91 KB
/
start.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
package libdokan
import (
"os"
"path"
"github.com/keybase/client/go/libkb"
"github.com/keybase/kbfs/dokan"
"github.com/keybase/kbfs/libfs"
"github.com/keybase/kbfs/libkbfs"
"golang.org/x/net/context"
)
// StartOptions are options for starting up
type StartOptions struct {
KbfsParams libkbfs.InitParams
RuntimeDir string
Label string
DokanConfig dokan.Config
}
// Start the filesystem
func Start(mounter Mounter, options StartOptions, kbCtx libkbfs.Context) *libfs.Error {
log, err := libkbfs.InitLog(options.KbfsParams, kbCtx)
if err != nil {
return libfs.InitError(err.Error())
}
onInterruptFn := func() {
mounter.Unmount()
}
config, err := libkbfs.Init(kbCtx, options.KbfsParams, nil, onInterruptFn, log)
if err != nil {
return libfs.InitError(err.Error())
}
defer libkbfs.Shutdown()
if options.RuntimeDir != "" {
info := libkb.NewServiceInfo(libkbfs.Version, libkbfs.PrereleaseBuild, options.Label, os.Getpid())
err = info.WriteFile(path.Join(options.RuntimeDir, "kbfs.info"))
if err != nil {
return libfs.InitError(err.Error())
}
}
if options.KbfsParams.Debug {
// Turn on debugging. TODO: allow a proper log file and
// style to be specified.
log.Configure("", true, "")
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
fs, err := NewFS(ctx, config, log)
if err != nil {
return libfs.InitError(err.Error())
}
options.DokanConfig.FileSystem = fs
options.DokanConfig.Path = mounter.Dir()
if newFolderNameErr != nil {
log.CWarningf(ctx, "Error guessing new folder name: %v", newFolderNameErr)
}
log.CDebugf(ctx, "New folder name guess: %q %q", newFolderName, newFolderAltName)
err = mounter.Mount(&options.DokanConfig, log)
if err != nil {
return libfs.MountError(err.Error())
}
return nil
}