added SaveSnapshot() to snapshot.Manifest

This commit is contained in:
Jarek Kowalski
2017-01-29 11:57:49 -08:00
parent 4b89c95721
commit fc6c29b4e4
3 changed files with 11 additions and 19 deletions

View File

@@ -119,7 +119,7 @@ func runBackupCommand(c *kingpin.ParseContext) error {
manifest.Handle = handleID
manifest.Description = *backupDescription
err = saveBackupManifest(conn.Vault, fileID, manifest)
err = conn.SnapshotManager.SaveSnapshot(fileID, manifest)
if err != nil {
return fmt.Errorf("cannot save manifest: %v", err)
}

View File

@@ -1,18 +0,0 @@
package main
import (
"encoding/json"
"fmt"
"github.com/kopia/kopia/snapshot"
"github.com/kopia/kopia/vault"
)
func saveBackupManifest(vlt *vault.Vault, manifestID string, m *snapshot.Manifest) error {
b, err := json.Marshal(m)
if err != nil {
return fmt.Errorf("cannot marshal backup manifest to JSON: %v", err)
}
return vlt.Put(manifestID, b)
}

View File

@@ -74,6 +74,16 @@ func (m *Manager) LoadSnapshot(manifestID string) (*Manifest, error) {
return &s, nil
}
// SaveSnapshot persists given snapshot manifest with a given ID.
func (m *Manager) SaveSnapshot(manifestID string, manifest *Manifest) error {
b, err := json.Marshal(manifest)
if err != nil {
return fmt.Errorf("cannot marshal backup manifest to JSON: %v", err)
}
return m.vault.Put(manifestID, b)
}
// LoadSnapshots efficiently loads and parses a given list of snapshot IDs.
func (m *Manager) LoadSnapshots(names []string) ([]*Manifest, error) {
result := make([]*Manifest, len(names))