-
Notifications
You must be signed in to change notification settings - Fork 293
/
io.go
40 lines (32 loc) · 863 Bytes
/
io.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
package cloud
import (
"context"
"io"
"os"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/tilt-dev/tilt/internal/store"
"github.com/tilt-dev/tilt/pkg/logger"
)
func WriteSnapshot(ctx context.Context, store *store.Store, path string) {
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
logger.Get(ctx).Errorf("Writing snapshot to file: %v", err)
}
state := store.RLockState()
defer store.RUnlockState()
err = WriteSnapshotTo(ctx, state, f)
if err != nil {
logger.Get(ctx).Errorf("Writing snapshot to file: %v", err)
}
}
func WriteSnapshotTo(ctx context.Context, state store.EngineState, w io.Writer) error {
snapshot, err := ToSnapshot(state)
if err != nil {
return err
}
jsEncoder := &runtime.JSONPb{
OrigName: false,
Indent: " ",
}
return jsEncoder.NewEncoder(w).Encode(snapshot)
}