summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/rsc/appfs/fs/local.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-05-12 23:56:07 -0400
committerChristopher Speller <crspeller@gmail.com>2016-05-12 23:56:07 -0400
commit38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8 (patch)
treea4fde09672192b97d453ad605b030bd5a10c5a45 /vendor/github.com/mattermost/rsc/appfs/fs/local.go
parent84d2482ddbff9564c9ad75b2d30af66e3ddfd44d (diff)
downloadchat-38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8.tar.gz
chat-38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8.tar.bz2
chat-38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8.zip
Moving to glide
Diffstat (limited to 'vendor/github.com/mattermost/rsc/appfs/fs/local.go')
-rw-r--r--vendor/github.com/mattermost/rsc/appfs/fs/local.go82
1 files changed, 82 insertions, 0 deletions
diff --git a/vendor/github.com/mattermost/rsc/appfs/fs/local.go b/vendor/github.com/mattermost/rsc/appfs/fs/local.go
new file mode 100644
index 000000000..c78b35b64
--- /dev/null
+++ b/vendor/github.com/mattermost/rsc/appfs/fs/local.go
@@ -0,0 +1,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
+}