mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-16 12:08:04 +00:00
Search snapshots by source repo.
This commit is contained in:
Vendored
+13
@@ -6,6 +6,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/database"
|
"github.com/smira/aptly/database"
|
||||||
|
"github.com/smira/aptly/utils"
|
||||||
"github.com/ugorji/go/codec"
|
"github.com/ugorji/go/codec"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
@@ -194,6 +195,18 @@ func (collection *SnapshotCollection) ByUUID(uuid string) (*Snapshot, error) {
|
|||||||
return nil, fmt.Errorf("snapshot with uuid %s not found", uuid)
|
return nil, fmt.Errorf("snapshot with uuid %s not found", uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ByRemoteRepoSource looks up snapshots that have specified RepoteRepo as a source
|
||||||
|
func (collection *SnapshotCollection) ByRemoteRepoSource(repo *RemoteRepo) []*Snapshot {
|
||||||
|
result := make([]*Snapshot, 0)
|
||||||
|
|
||||||
|
for _, s := range collection.list {
|
||||||
|
if s.SourceKind == "repo" && utils.StrSliceHasItem(s.SourceIDs, repo.UUID) {
|
||||||
|
result = append(result, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// ForEach runs method for each snapshot
|
// ForEach runs method for each snapshot
|
||||||
func (collection *SnapshotCollection) ForEach(handler func(*Snapshot) error) error {
|
func (collection *SnapshotCollection) ForEach(handler func(*Snapshot) error) error {
|
||||||
var err error
|
var err error
|
||||||
|
|||||||
Vendored
+12
@@ -158,3 +158,15 @@ func (s *SnapshotCollectionSuite) TestForEachAndLen(c *C) {
|
|||||||
})
|
})
|
||||||
c.Assert(err, Equals, e)
|
c.Assert(err, Equals, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SnapshotCollectionSuite) TestFindByRemoteRepoSource(c *C) {
|
||||||
|
c.Assert(s.collection.Add(s.snapshot1), IsNil)
|
||||||
|
c.Assert(s.collection.Add(s.snapshot2), IsNil)
|
||||||
|
|
||||||
|
c.Check(s.collection.ByRemoteRepoSource(s.repo1), DeepEquals, []*Snapshot{s.snapshot1})
|
||||||
|
c.Check(s.collection.ByRemoteRepoSource(s.repo2), DeepEquals, []*Snapshot{s.snapshot2})
|
||||||
|
|
||||||
|
repo3, _ := NewRemoteRepo("other", "http://mirror.yandex.ru/debian/", "lenny", []string{"main"}, []string{})
|
||||||
|
|
||||||
|
c.Check(s.collection.ByRemoteRepoSource(repo3), DeepEquals, []*Snapshot{})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user