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
|
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fs
import (
"io/ioutil"
"net/http"
"os"
"path/filepath"
"github.com/mattermost/rsc/appfs/proto"
)
type context struct{}
type cacheKey struct{}
func newContext(req *http.Request) *Context {
return &Context{}
}
func (*context) cacheRead(ckey CacheKey, path string) (CacheKey, []byte, bool) {
return ckey, nil, false
}
func (*context) cacheWrite(ckey CacheKey, data []byte) {
}
func (*context) read(path string) ([]byte, *proto.FileInfo, error) {
p := filepath.Join(Root, path)
dir, err := os.Stat(p)
if err != nil {
return nil, nil, err
}
fi := &proto.FileInfo{
Name: dir.Name(),
ModTime: dir.ModTime(),
Size: dir.Size(),
IsDir: dir.IsDir(),
}
data, err := ioutil.ReadFile(p)
return data, fi, err
}
func (*context) write(path string, data []byte) error {
p := filepath.Join(Root, path)
return ioutil.WriteFile(p, data, 0666)
}
func (*context) remove(path string) error {
p := filepath.Join(Root, path)
return os.Remove(p)
}
func (*context) mkdir(path string) error {
p := filepath.Join(Root, path)
fi, err := os.Stat(p)
if err == nil && fi.IsDir() {
return nil
}
return os.Mkdir(p, 0777)
}
func (*context) readdir(path string) ([]proto.FileInfo, error) {
p := filepath.Join(Root, path)
dirs, err := ioutil.ReadDir(p)
if err != nil {
return nil, err
}
var out []proto.FileInfo
for _, dir := range dirs {
out = append(out, proto.FileInfo{
Name: dir.Name(),
ModTime: dir.ModTime(),
Size: dir.Size(),
IsDir: dir.IsDir(),
})
}
return out, nil
}
|