-
Notifications
You must be signed in to change notification settings - Fork 351
/
inventory.go
60 lines (52 loc) · 1.45 KB
/
inventory.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
package onboard
import (
"encoding/json"
"strconv"
"time"
"github.com/treeverse/lakefs/pkg/block"
"github.com/treeverse/lakefs/pkg/catalog"
"github.com/treeverse/lakefs/pkg/cmdutils"
)
type InventoryDiff struct {
DryRun bool
AddedOrChanged []block.InventoryObject
Deleted []block.InventoryObject
PreviousInventoryURL string
PreviousImportDate time.Time
}
type ImportObject struct {
Obj block.InventoryObject
IsDeleted bool
IsChanged bool
}
type Iterator interface {
cmdutils.ProgressReporter
Next() bool
Err() error
Get() ImportObject
}
// onboard.InventoryIterator reads from block.InventoryIterator and converts the objects to ImportObject
type InventoryIterator struct {
block.InventoryIterator
}
func NewInventoryIterator(it block.InventoryIterator) *InventoryIterator {
return &InventoryIterator{InventoryIterator: it}
}
func (s *InventoryIterator) Get() ImportObject {
return ImportObject{
Obj: *s.InventoryIterator.Get(),
IsDeleted: false,
}
}
func CreateCommitMetadata(inv block.Inventory, stats Stats, prefixes []string) catalog.Metadata {
metadata := catalog.Metadata{
"inventory_url": inv.InventoryURL(),
"source": inv.SourceName(),
"added_or_changed_objects": strconv.Itoa(stats.AddedOrChanged),
}
if len(prefixes) > 0 {
prefixesSerialized, _ := json.Marshal(prefixes)
metadata["key_prefixes"] = string(prefixesSerialized)
}
return metadata
}