
These interfaces allow us to preserve both the checking of error "cause" as well as messages returned from the gRPC API so that the client gets full error reason instead of a default "metadata: not found" in the case of a missing image. Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
37 lines
535 B
Go
37 lines
535 B
Go
package content
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
)
|
|
|
|
// Handles locking references
|
|
// TODO: use boltdb for lock status
|
|
|
|
var (
|
|
// locks lets us lock in process
|
|
locks = map[string]struct{}{}
|
|
locksMu sync.Mutex
|
|
)
|
|
|
|
func tryLock(ref string) error {
|
|
locksMu.Lock()
|
|
defer locksMu.Unlock()
|
|
|
|
if _, ok := locks[ref]; ok {
|
|
return ErrLocked(fmt.Sprintf("key %s is locked", ref))
|
|
}
|
|
|
|
locks[ref] = struct{}{}
|
|
return nil
|
|
}
|
|
|
|
func unlock(ref string) {
|
|
locksMu.Lock()
|
|
defer locksMu.Unlock()
|
|
|
|
if _, ok := locks[ref]; ok {
|
|
delete(locks, ref)
|
|
}
|
|
}
|