mirror of
https://github.com/kopia/kopia.git
synced 2026-10-27 16:48:59 -04:00
whenever two blocks in index have identical times, prefer the non-deleted one
This commit is contained in:
1 parent
f6dcd3c155
commit
438fa4a587
2 files changed
+29
-5
No files matched your search
@@ -31,14 +31,13 @@ func (m Merged) EntryCount() int {
|
||||
// GetInfo returns information about a single block. If a block is not found, returns (nil,nil)
|
||||
func (m Merged) GetInfo(contentID string) (*Info, error) {
|
||||
var best *Info
|
||||
|
||||
for _, ndx := range m {
|
||||
i, err := ndx.GetInfo(contentID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if i != nil {
|
||||
if best == nil || i.TimestampSeconds > best.TimestampSeconds {
|
||||
if best == nil || i.TimestampSeconds > best.TimestampSeconds || (i.TimestampSeconds == best.TimestampSeconds && !i.Deleted) {
|
||||
best = i
|
||||
}
|
||||
}
|
||||
@@ -53,9 +52,20 @@ type nextInfo struct {
|
||||
|
||||
type nextInfoHeap []*nextInfo
|
||||
|
||||
func (h nextInfoHeap) Len() int { return len(h) }
|
||||
func (h nextInfoHeap) Less(i, j int) bool { return h[i].it.BlockID < h[j].it.BlockID }
|
||||
func (h nextInfoHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
|
||||
func (h nextInfoHeap) Len() int { return len(h) }
|
||||
func (h nextInfoHeap) Less(i, j int) bool {
|
||||
if a, b := h[i].it.BlockID, h[j].it.BlockID; a != b {
|
||||
return a < b
|
||||
}
|
||||
|
||||
if a, b := h[i].it.TimestampSeconds, h[j].it.TimestampSeconds; a != b {
|
||||
return a < b
|
||||
}
|
||||
|
||||
return !h[i].it.Deleted
|
||||
}
|
||||
|
||||
func (h nextInfoHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
|
||||
func (h *nextInfoHeap) Push(x interface{}) {
|
||||
*h = append(*h, x.(*nextInfo))
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ func TestMerged(t *testing.T) {
|
||||
packindex.Info{BlockID: "aabbcc", TimestampSeconds: 1, PackBlockID: "xx", PackOffset: 11},
|
||||
packindex.Info{BlockID: "ddeeff", TimestampSeconds: 1, PackBlockID: "xx", PackOffset: 111},
|
||||
packindex.Info{BlockID: "z010203", TimestampSeconds: 1, PackBlockID: "xx", PackOffset: 111},
|
||||
packindex.Info{BlockID: "de1e1e", TimestampSeconds: 4, PackBlockID: "xx", PackOffset: 111},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("can't create index: %v", err)
|
||||
@@ -21,6 +22,7 @@ func TestMerged(t *testing.T) {
|
||||
i2, err := indexWithItems(
|
||||
packindex.Info{BlockID: "aabbcc", TimestampSeconds: 3, PackBlockID: "yy", PackOffset: 33},
|
||||
packindex.Info{BlockID: "xaabbcc", TimestampSeconds: 1, PackBlockID: "xx", PackOffset: 111},
|
||||
packindex.Info{BlockID: "de1e1e", TimestampSeconds: 4, PackBlockID: "xx", PackOffset: 222, Deleted: true},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("can't create index: %v", err)
|
||||
@@ -47,12 +49,24 @@ func TestMerged(t *testing.T) {
|
||||
var inOrder []string
|
||||
m.Iterate("", func(i packindex.Info) error {
|
||||
inOrder = append(inOrder, i.BlockID)
|
||||
if i.BlockID == "de1e1e" {
|
||||
if i.Deleted {
|
||||
t.Errorf("iteration preferred deleted block over non-deleted")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if i, err := m.GetInfo("de1e1e"); err != nil {
|
||||
t.Errorf("error getting deleted block info: %v", err)
|
||||
} else if i.Deleted {
|
||||
t.Errorf("GetInfo preferred deleted block over non-deleted")
|
||||
}
|
||||
|
||||
expectedInOrder := []string{
|
||||
"aabbcc",
|
||||
"ddeeff",
|
||||
"de1e1e",
|
||||
"k010203",
|
||||
"k020304",
|
||||
"xaabbcc",
|
||||
|
||||
Reference in new issue
Block a user