-
Notifications
You must be signed in to change notification settings - Fork 348
/
inventory_entry_iterator.go
72 lines (59 loc) · 1.37 KB
/
inventory_entry_iterator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package onboard
import (
"errors"
"github.com/treeverse/lakefs/pkg/catalog"
"github.com/treeverse/lakefs/pkg/cmdutils"
"google.golang.org/protobuf/types/known/timestamppb"
)
type inventoryEntryIterator struct {
it *InventoryIterator
value *catalog.EntryRecord
err error
progress *cmdutils.Progress
}
func NewValueToEntryIterator(it *InventoryIterator, progress *cmdutils.Progress) catalog.EntryIterator {
return &inventoryEntryIterator{
it: it,
progress: progress,
}
}
var (
ErrIteratorNotSeekable = errors.New("can't seek on inventory iterator")
)
func (e *inventoryEntryIterator) Next() bool {
if e.err != nil {
return false
}
if !e.it.Next() {
e.value = nil
e.err = e.it.Err()
return false
}
v := e.it.Get()
e.value = &catalog.EntryRecord{
Path: catalog.Path(v.Obj.Key),
Entry: &catalog.Entry{
Address: v.Obj.PhysicalAddress,
Size: v.Obj.Size,
ETag: v.Obj.Checksum,
},
}
if v.Obj.LastModified != nil {
e.value.LastModified = timestamppb.New(*v.Obj.LastModified)
}
e.progress.Add(1)
return true
}
func (e *inventoryEntryIterator) SeekGE(_ catalog.Path) {
e.value = nil
e.err = ErrIteratorNotSeekable
}
func (e *inventoryEntryIterator) Value() *catalog.EntryRecord {
return e.value
}
func (e *inventoryEntryIterator) Err() error {
return e.err
}
func (e *inventoryEntryIterator) Close() {
// nothing to do
}