-
Notifications
You must be signed in to change notification settings - Fork 5
/
local.go
52 lines (45 loc) · 973 Bytes
/
local.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
package main
import (
"io"
"os"
"path/filepath"
"github.com/drone/drone-cache-lib/storage"
)
type localCache struct {
}
func (s *localCache) Get(path string, dst io.Writer) error {
src, err := os.Open(path)
if err != nil {
return err
}
defer src.Close()
_, err = io.Copy(dst, src)
return err
}
func (s *localCache) Put(path string, src io.Reader) error {
dst, err := os.Create(path)
if err != nil {
return err
}
defer dst.Close()
_, err = io.Copy(dst, src)
return err
}
func (s *localCache) List(path string) ([]storage.FileEntry, error) {
var files []storage.FileEntry
walker := func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
files = append(files, storage.FileEntry{
Path: path,
Size: info.Size(),
LastModified: info.ModTime(),
})
}
return nil
}
_ = filepath.Walk(path, walker)
return files, nil
}
func (s *localCache) Delete(path string) error {
return os.Remove(path)
}