Commit baa4fb16 authored by Sebastian Stark's avatar Sebastian Stark

Make FindDangling return a SnapshotList instead of sending to a channel

  - trying to keep channels out of low level routines to make it easier
    to test them
  - also this makes the code easier to understand
parent f3986a06
......@@ -116,10 +116,12 @@ func subcmdRun() (ferr error) {
}()
Debugf("started snapshot creation goroutine")
// Usually the purger gets its input from the obsoleteQueue. But there
// Usually the purger gets its input only from prune(). But there
// could be snapshots left behind from a previously failed snaprd run, so
// we fill the obsoleteQueue once at the beginning.
FindDangling(obsoleteQueue, cl)
for _, sn := range FindDangling(cl) {
obsoleteQueue <- sn
}
// Purger loop
go func() {
......
......@@ -292,16 +292,18 @@ func (sl SnapshotList) state(include, exclude SnapshotState) SnapshotList {
return slNew
}
// FindDangling enqueues obsolete/purged snapshots into q.
func FindDangling(q chan *Snapshot, cl Clock) {
// FindDangling returns a list of obsolete or purged snapshots.
func FindDangling(cl Clock) SnapshotList {
snapshots, err := FindSnapshots(cl)
if err != nil {
log.Println(err)
}
slNew := make(SnapshotList, 0, len(snapshots))
for _, sn := range snapshots.state(STATE_OBSOLETE+STATE_PURGING, STATE_COMPLETE) {
Debugf("found dangling snapshot: %s", sn)
q <- sn
slNew = append(slNew, sn)
}
return slNew
}
// LastGoodFromDisk lists the snapshots in the repository and returns a pointer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment