/
flags.go
74 lines (63 loc) · 1.32 KB
/
flags.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
package fs
import (
"mime"
"os"
"strings"
"time"
"github.com/arvinsg/cess-fuse/pkg/utils"
)
var (
log = utils.GetLogger("main")
fuseLog = utils.GetLogger("fuse")
)
type Flags struct {
// File system
MountOptions map[string]string
MountPoint string
MountPointArg string
MountPointCreated string
Cache []string
DirMode os.FileMode
FileMode os.FileMode
Uid uint32
Gid uint32
// Common Backend Flags
UseContentType bool
Endpoint string
// Tuning
ExplicitDir bool
StatCacheTTL time.Duration
TypeCacheTTL time.Duration
HTTPTimeout time.Duration
// Debugging
DebugFuse bool
Foreground bool
}
func (c *Flags) GetMimeType(fileName string) (retMime *string) {
if !c.UseContentType {
return nil
}
dotPosition := strings.LastIndex(fileName, ".")
if dotPosition == -1 {
return nil
}
mimeType := mime.TypeByExtension(fileName[dotPosition:])
if mimeType == "" {
return nil
}
semicolonPosition := strings.LastIndex(mimeType, ";")
if semicolonPosition == -1 {
return &mimeType
}
s := mimeType[:semicolonPosition]
retMime = &s
return retMime
}
func (c *Flags) Cleanup() {
if c.MountPointCreated != "" && c.MountPointCreated != c.MountPointArg {
err := os.Remove(c.MountPointCreated)
if err != nil {
log.Errorf("rmdir %v = %v", c.MountPointCreated, err)
}
}
}