-
Notifications
You must be signed in to change notification settings - Fork 117
/
repos.go
80 lines (63 loc) · 1.55 KB
/
repos.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
package runtime
import (
"context"
"io"
"time"
)
func (r *Runtime) ListFiles(ctx context.Context, instanceID, glob string) ([]string, error) {
repo, err := r.Repo(ctx, instanceID)
if err != nil {
return nil, err
}
return repo.ListRecursive(ctx, instanceID, glob)
}
func (r *Runtime) GetFile(ctx context.Context, instanceID, path string) (string, time.Time, error) {
repo, err := r.Repo(ctx, instanceID)
if err != nil {
return "", time.Time{}, err
}
blob, err := repo.Get(ctx, instanceID, path)
if err != nil {
return "", time.Time{}, err
}
// TODO: Could we return Stat as part of Get?
stat, err := repo.Stat(ctx, instanceID, path)
if err != nil {
return "", time.Time{}, err
}
return blob, stat.LastUpdated, nil
}
func (r *Runtime) PutFile(ctx context.Context, instanceID, path string, blob io.Reader, create, createOnly bool) error {
repo, err := r.Repo(ctx, instanceID)
if err != nil {
return err
}
// TODO: Handle create, createOnly
err = repo.Put(ctx, instanceID, path, blob)
if err != nil {
return err
}
return nil
}
func (r *Runtime) DeleteFile(ctx context.Context, instanceID, path string) error {
repo, err := r.Repo(ctx, instanceID)
if err != nil {
return err
}
err = repo.Delete(ctx, instanceID, path)
if err != nil {
return err
}
return nil
}
func (r *Runtime) RenameFile(ctx context.Context, instanceID, fromPath, toPath string) error {
repo, err := r.Repo(ctx, instanceID)
if err != nil {
return err
}
err = repo.Rename(ctx, instanceID, fromPath, toPath)
if err != nil {
return err
}
return nil
}