| 1 | /* |
| 2 | Copyright The ORAS Authors. |
| 3 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | you may not use this file except in compliance with the License. |
| 5 | You may obtain a copy of the License at |
| 6 | |
| 7 | http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | |
| 9 | Unless required by applicable law or agreed to in writing, software |
| 10 | distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | See the License for the specific language governing permissions and |
| 13 | limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | package statusscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/status`/ |
| 17 | |
| 18 | import ( |
| 19 | "syncscip-go gomod github.com/golang/go/src go1.23.0 sync/" |
| 20 | |
| 21 | ocispecscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/ "github.com/opencontainers/image-spec/specs-go/v1scip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/" |
| 22 | "oras.land/oras-go/v2/internal/descriptorscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/descriptor`/" |
| 23 | ) |
| 24 | |
| 25 | // Tracker tracks content status described by a descriptor. |
| 26 | type Trackerscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/status`/Tracker# struct { |
| 27 | statusscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/status`/Tracker#status. syncscip-go gomod github.com/golang/go/src go1.23.0 sync/.Mapscip-go gomod github.com/golang/go/src go1.23.0 sync/Map# // map[descriptor.Descriptor]chan struct{} |
| 28 | } |
| 29 | |
| 30 | // NewTracker creates a new content status tracker. |
| 31 | func NewTrackerscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/status`/NewTracker().() *Trackerscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/status`/Tracker# { |
| 32 | return &Trackerscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/status`/Tracker#{} |
| 33 | } |
| 34 | |
| 35 | // TryCommit tries to commit the work for the target descriptor. |
| 36 | // Returns true if committed. A channel is also returned for sending |
| 37 | // notifications. Once the work is done, the channel should be closed. |
| 38 | // Returns false if the work is done or still in progress. |
| 39 | func (t *Trackerscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/status`/Tracker#) TryCommitscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/status`/Tracker#TryCommit().(target ocispecscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/.Descriptorscip-go gomod github.com/opencontainers/image-spec v1.1.1 `github.com/opencontainers/image-spec/specs-go/v1`/Descriptor#) (chan struct{}, bool) { |
| 40 | key := descriptorscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/descriptor`/.FromOCIscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/descriptor`/FromOCI().(target) |
| 41 | status, exists := t.statusscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/internal/status`/Tracker#status..LoadOrStorescip-go gomod github.com/golang/go/src go1.23.0 sync/Map#LoadOrStore().(key, make(chan struct{})) |
| 42 | return status.(chan struct{}), !exists |
| 43 | } |