aboutsummaryrefslogtreecommitdiff
path: root/storage
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2017-09-14 07:42:50 +0200
committerLaria Carolin Chabowski <laria@laria.me>2017-09-26 21:35:41 +0200
commitb2742dc28d1ff9001cd784455bbdf9cf29539c30 (patch)
tree2cac9dff572edbfc05588c33cce76a3dbb406d15 /storage
parent9ddda1c317dbeaab1380e46ebf48eba9566a90e2 (diff)
downloadpetrific-b2742dc28d1ff9001cd784455bbdf9cf29539c30.tar.gz
petrific-b2742dc28d1ff9001cd784455bbdf9cf29539c30.tar.bz2
petrific-b2742dc28d1ff9001cd784455bbdf9cf29539c30.zip
Implement remaining subcommands
Diffstat (limited to 'storage')
-rw-r--r--storage/storage.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/storage/storage.go b/storage/storage.go
index 7cffe9c..7d09a70 100644
--- a/storage/storage.go
+++ b/storage/storage.go
@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
+ "time"
)
var (
@@ -89,3 +90,39 @@ func GetObjectOfType(s Storage, id objects.ObjectId, t objects.ObjectType) (obje
return rawobj.Object()
}
+
+// FindLatestSnapshot finds the latest snapshot, optionally filtered by archive
+func FindLatestSnapshot(store Storage, archive string) (latestSnapshot *objects.Snapshot, err error) {
+ ids, err := store.List(objects.OTSnapshot)
+ if err != nil {
+ return nil, err
+ }
+
+ var earliestTime time.Time
+ found := false
+
+ for _, id := range ids {
+ _snapshot, err := GetObjectOfType(store, id, objects.OTSnapshot)
+ if err != nil {
+ return nil, err
+ }
+
+ snapshot := _snapshot.(*objects.Snapshot)
+
+ if archive != "" && snapshot.Archive != archive {
+ continue
+ }
+
+ if snapshot.Date.After(earliestTime) {
+ earliestTime = snapshot.Date
+ latestSnapshot = snapshot
+ found = true
+ }
+ }
+
+ if !found {
+ return latestSnapshot, ObjectNotFound
+ }
+
+ return latestSnapshot, nil
+}