2018-05-22 21:43:36 +02:00
|
|
|
// Copyright 2016-2018, Pulumi Corporation.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2018-04-23 23:12:13 +02:00
|
|
|
|
2018-09-04 21:38:58 +02:00
|
|
|
package filestate
|
2018-04-23 23:12:13 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/pulumi/pulumi/pkg/resource/deploy"
|
|
|
|
"github.com/pulumi/pulumi/pkg/tokens"
|
|
|
|
)
|
|
|
|
|
|
|
|
// localSnapshotManager is a simple SnapshotManager implementation that persists snapshots
|
|
|
|
// to disk on the local machine.
|
2018-04-26 02:20:08 +02:00
|
|
|
type localSnapshotPersister struct {
|
2018-04-23 23:12:13 +02:00
|
|
|
name tokens.QName
|
|
|
|
backend *localBackend
|
|
|
|
}
|
|
|
|
|
2018-04-26 02:20:08 +02:00
|
|
|
func (sm *localSnapshotPersister) Invalidate() error {
|
|
|
|
return nil
|
2018-04-23 23:12:13 +02:00
|
|
|
}
|
|
|
|
|
2018-04-26 02:20:08 +02:00
|
|
|
func (sm *localSnapshotPersister) Save(snapshot *deploy.Snapshot) error {
|
2018-05-18 20:15:35 +02:00
|
|
|
config, _, _, err := sm.backend.getStack(sm.name)
|
2018-04-23 23:12:13 +02:00
|
|
|
if err != nil && !os.IsNotExist(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-18 20:15:35 +02:00
|
|
|
_, err = sm.backend.saveStack(sm.name, config, snapshot)
|
2018-04-23 23:12:13 +02:00
|
|
|
return err
|
|
|
|
|
2018-04-26 02:20:08 +02:00
|
|
|
}
|
2018-04-23 23:12:13 +02:00
|
|
|
|
2018-04-26 02:20:08 +02:00
|
|
|
func (b *localBackend) newSnapshotPersister(stackName tokens.QName) *localSnapshotPersister {
|
|
|
|
return &localSnapshotPersister{name: stackName, backend: b}
|
2018-04-23 23:12:13 +02:00
|
|
|
}
|