MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / Get

Method Get

src/cmd/linuxkit/cache/open.go:12–45  ·  view source on GitHub ↗

Get get or initialize the cache

(cache string)

Source from the content-addressed store, hash-verified

10
11// Get get or initialize the cache
12func (p *Provider) Get(cache string) (layout.Path, error) {
13 // ensure the dir exists
14 if err := os.MkdirAll(cache, os.ModePerm); err != nil {
15 return "", fmt.Errorf("unable to create cache directory %s: %v", cache, err)
16 }
17
18 // first try to read the layout from the path
19 // if it exists, we can use it
20 // if it does not exist, we will initialize it
21 //
22 // do not lock for first read, because we do not need the lock except for initialization
23 // and future writes, so why slow down reads?
24 l, err := layout.FromPath(cache)
25
26 // initialize the cache path if needed
27 if err != nil {
28 if err := p.Lock(); err != nil {
29 return "", fmt.Errorf("unable to lock cache %s: %v", cache, err)
30 }
31 defer p.Unlock()
32
33 // after lock, try to read the layout again
34 // in case another process initialized it while we were waiting for the lock
35 // if it still does not exist, we will initialize it
36 l, err = layout.FromPath(cache)
37 if err != nil {
38 l, err = layout.Write(cache, empty.Index)
39 if err != nil {
40 return l, fmt.Errorf("could not initialize cache at path %s: %v", cache, err)
41 }
42 }
43 }
44 return l, nil
45}

Callers 15

NewProviderFunction · 0.95
systemInitCmdFunction · 0.45
mainFunction · 0.45
removeImagesFromCacheFunction · 0.45
CreateInstanceMethod · 0.45
pollOperationStatusMethod · 0.45
pkgRemoteTagCmdFunction · 0.45
createOpenStackImageFunction · 0.45
buildCmdFunction · 0.45
PushMethod · 0.45

Implementers 11

ProviderCDROMpkg/metadata/provider_cdrom.go
ProviderGCPpkg/metadata/provider_gcp.go
ProviderVMwarepkg/metadata/provider_vmware_unsupport
ProviderEquinixMetalpkg/metadata/provider_equinixmetal.go
ProviderVultrpkg/metadata/provider_vultr.go
ProviderDigitalOceanpkg/metadata/provider_digitalocean.go
ProviderHetznerpkg/metadata/provider_hetzner.go
ProviderMetaldatapkg/metadata/provider_metaldata.go
ProviderOpenstackpkg/metadata/provider_openstack.go
ProviderScalewaypkg/metadata/provider_scaleway.go
ProviderAWSpkg/metadata/provider_aws.go

Calls 3

LockMethod · 0.95
UnlockMethod · 0.95
WriteMethod · 0.45

Tested by

no test coverage detected