(ctx context.Context, info content.Info, fieldpaths ...string)
| 92 | } |
| 93 | |
| 94 | func (cs *contentStore) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) { |
| 95 | ns, err := namespaces.NamespaceRequired(ctx) |
| 96 | if err != nil { |
| 97 | return content.Info{}, err |
| 98 | } |
| 99 | |
| 100 | cs.l.RLock() |
| 101 | defer cs.l.RUnlock() |
| 102 | |
| 103 | updated := content.Info{ |
| 104 | Digest: info.Digest, |
| 105 | } |
| 106 | if err := update(ctx, cs.db, func(tx *bolt.Tx) error { |
| 107 | bkt := getBlobBucket(tx, ns, info.Digest) |
| 108 | if bkt == nil { |
| 109 | return fmt.Errorf("content digest %v: %w", info.Digest, errdefs.ErrNotFound) |
| 110 | } |
| 111 | |
| 112 | if err := readInfo(&updated, bkt); err != nil { |
| 113 | return fmt.Errorf("info %q: %w", info.Digest, err) |
| 114 | } |
| 115 | |
| 116 | if len(fieldpaths) > 0 { |
| 117 | for _, path := range fieldpaths { |
| 118 | if strings.HasPrefix(path, "labels.") { |
| 119 | if updated.Labels == nil { |
| 120 | updated.Labels = map[string]string{} |
| 121 | } |
| 122 | |
| 123 | key := strings.TrimPrefix(path, "labels.") |
| 124 | updated.Labels[key] = info.Labels[key] |
| 125 | continue |
| 126 | } |
| 127 | |
| 128 | switch path { |
| 129 | case "labels": |
| 130 | updated.Labels = info.Labels |
| 131 | default: |
| 132 | return fmt.Errorf("cannot update %q field on content info %q: %w", path, info.Digest, errdefs.ErrInvalidArgument) |
| 133 | } |
| 134 | } |
| 135 | } else { |
| 136 | // Set mutable fields |
| 137 | updated.Labels = info.Labels |
| 138 | } |
| 139 | if err := validateInfo(&updated); err != nil { |
| 140 | return err |
| 141 | } |
| 142 | |
| 143 | updated.UpdatedAt = time.Now().UTC() |
| 144 | return writeInfo(&updated, bkt) |
| 145 | }); err != nil { |
| 146 | return content.Info{}, err |
| 147 | } |
| 148 | return updated, nil |
| 149 | } |
| 150 | |
| 151 | func (cs *contentStore) Walk(ctx context.Context, fn content.WalkFunc, fs ...string) error { |
nothing calls this directly
no test coverage detected