MCPcopy
hub / github.com/perkeep/perkeep / SetAttrValues

Method SetAttrValues

pkg/importer/importer.go:1534–1564  ·  view source on GitHub ↗

SetAttrValues sets multi-valued attribute.

(key string, attrs []string)

Source from the content-addressed store, hash-verified

1532
1533// SetAttrValues sets multi-valued attribute.
1534func (o *Object) SetAttrValues(key string, attrs []string) error {
1535 ctx := context.TODO() // TODO: make it possible to get a context via Object; either new context field, or via some "ImportRun" field?
1536
1537 exists := asSet(o.Attrs(key))
1538 actual := asSet(attrs)
1539 o.mu.Lock()
1540 defer o.mu.Unlock()
1541 // add new values
1542 for v := range actual {
1543 if exists[v] {
1544 delete(exists, v)
1545 continue
1546 }
1547 _, err := o.h.upload(ctx, schema.NewAddAttributeClaim(o.pn, key, v))
1548 if err != nil {
1549 return err
1550 }
1551 }
1552 // delete unneeded values
1553 for v := range exists {
1554 _, err := o.h.upload(ctx, schema.NewDelAttributeClaim(o.pn, key, v))
1555 if err != nil {
1556 return err
1557 }
1558 }
1559 if o.attr == nil {
1560 o.attr = make(map[string][]string)
1561 }
1562 o.attr[key] = attrs
1563 return nil
1564}
1565
1566func asSet(elts []string) map[string]bool {
1567 if len(elts) == 0 {

Callers 3

importCheckinMethod · 0.80
updatePhotoInAlbumMethod · 0.80
importPostMethod · 0.80

Calls 8

AttrsMethod · 0.95
NewAddAttributeClaimFunction · 0.92
NewDelAttributeClaimFunction · 0.92
asSetFunction · 0.85
deleteFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
uploadMethod · 0.80

Tested by

no test coverage detected