forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
114 lines (94 loc) · 2.97 KB
/
main.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// 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.
// Keybase file system
package main
import (
"flag"
"fmt"
"os"
"github.com/keybase/client/go/libkb"
"github.com/keybase/kbfs/dokan"
"github.com/keybase/kbfs/env"
"github.com/keybase/kbfs/libdokan"
"github.com/keybase/kbfs/libfs"
"github.com/keybase/kbfs/libkbfs"
)
var runtimeDir = flag.String("runtime-dir", os.Getenv("KEYBASE_RUNTIME_DIR"), "runtime directory")
var label = flag.String("label", os.Getenv("KEYBASE_LABEL"), "label to help identify if running as a service")
var mountType = flag.String("mount-type", defaultMountType, "mount type: default, force, none")
var version = flag.Bool("version", false, "Print version")
var mountFlags = flag.Int64("mount-flags", int64(libdokan.DefaultMountFlags), "Dokan mount flags")
var dokandll = flag.String("dokan-dll", "", "Absolute path of dokan dll to load")
var servicemount = flag.Bool("mount-from-service", false, "get mount path from service")
const usageFormatStr = `Usage:
kbfsdokan -version
To run against remote KBFS servers:
kbfsdokan
[-runtime-dir=path/to/dir] [-label=label] [-mount-type=force]
[-mount-flags=n] [-dokan-dll=path/to/dokan.dll]
%s
-mount-from-service | /path/to/mountpoint
To run in a local testing environment:
kbfsdokan
[-runtime-dir=path/to/dir] [-label=label] [-mount-type=force]
[-mount-flags=n] [-dokan-dll=path/to/dokan.dll]
%s
-mount-from-service | /path/to/mountpoint
Defaults:
%s
`
func getUsageString(ctx libkbfs.Context) string {
remoteUsageStr := libkbfs.GetRemoteUsageString()
localUsageStr := libkbfs.GetLocalUsageString()
defaultUsageStr := libkbfs.GetDefaultsUsageString(ctx)
return fmt.Sprintf(usageFormatStr, remoteUsageStr,
localUsageStr, defaultUsageStr)
}
func start() *libfs.Error {
err := libkb.SaferDLLLoading()
if err != nil {
fmt.Printf("SaferDLLLoading failed: %v\n", err)
}
ctx := env.NewContext()
kbfsParams := libkbfs.AddFlags(flag.CommandLine, ctx)
flag.Parse()
if *version {
fmt.Printf("%s\n", libkbfs.VersionString())
return nil
}
var mountpoint string
if len(flag.Args()) < 1 {
if !*servicemount {
fmt.Print(getUsageString(ctx))
return libfs.InitError("no mount specified")
}
} else {
mountpoint = flag.Arg(0)
}
if len(flag.Args()) > 1 {
fmt.Print(getUsageString(ctx))
return libfs.InitError("extra arguments specified (flags go before the first argument)")
}
options := libdokan.StartOptions{
KbfsParams: *kbfsParams,
RuntimeDir: *runtimeDir,
Label: *label,
DokanConfig: dokan.Config{
MountFlags: dokan.MountFlag(*mountFlags),
DllPath: *dokandll,
},
ForceMount: *mountType == "force",
SkipMount: *mountType == "none",
MountPoint: mountpoint,
}
return libdokan.Start(options, ctx)
}
func main() {
err := start()
if err != nil {
fmt.Fprintf(os.Stderr, "kbfsdokan error: (%d) %s\n", err.Code, err.Message)
os.Exit(err.Code)
}
os.Exit(0)
}