layer/layer_store.go
File layer_store.go
has 609 lines of code (exceeds 500 allowed). Consider refactoring. Open
Open
package layer // import "github.com/docker/docker/layer"
import (
"context"
"errors"
layerStore
has 23 methods (exceeds 20 allowed). Consider refactoring. Open
Open
type layerStore struct {
store *fileMetadataStore
driver graphdriver.Driver
layerMap map[ChainID]*roLayer
Method layerStore.registerWithDescriptor
has 71 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (ls *layerStore) registerWithDescriptor(ts io.Reader, parent ChainID, descriptor distribution.Descriptor) (Layer, error) {
// cErr is used to hold the error which will always trigger
// cleanup of creates sources but may not be an error returned
// to the caller (already exists).
var cErr error
Method layerStore.CreateRWLayer
has 60 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (ls *layerStore) CreateRWLayer(name string, parent ChainID, opts *CreateRWLayerOpts) (_ RWLayer, err error) {
var (
storageOpt map[string]string
initFunc MountInit
mountLabel string
Method layerStore.registerWithDescriptor
has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring. Open
Open
func (ls *layerStore) registerWithDescriptor(ts io.Reader, parent ChainID, descriptor distribution.Descriptor) (Layer, error) {
// cErr is used to hold the error which will always trigger
// cleanup of creates sources but may not be an error returned
// to the caller (already exists).
var cErr error
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method layerStore.registerWithDescriptor
has 9 return statements (exceeds 4 allowed). Open
Open
func (ls *layerStore) registerWithDescriptor(ts io.Reader, parent ChainID, descriptor distribution.Descriptor) (Layer, error) {
// cErr is used to hold the error which will always trigger
// cleanup of creates sources but may not be an error returned
// to the caller (already exists).
var cErr error
Method layerStore.loadLayer
has 8 return statements (exceeds 4 allowed). Open
Open
func (ls *layerStore) loadLayer(layer ChainID) (*roLayer, error) {
cl, ok := ls.layerMap[layer]
if ok {
return cl, nil
}
Method layerStore.ReleaseRWLayer
has 8 return statements (exceeds 4 allowed). Open
Open
func (ls *layerStore) ReleaseRWLayer(l RWLayer) ([]Metadata, error) {
name := l.Name()
ls.locker.Lock(name)
defer ls.locker.Unlock(name)
Method layerStore.loadMount
has 6 return statements (exceeds 4 allowed). Open
Open
func (ls *layerStore) loadMount(mount string) error {
ls.mountL.Lock()
defer ls.mountL.Unlock()
if _, ok := ls.mounts[mount]; ok {
return nil
Method layerStore.CreateRWLayer
has 6 return statements (exceeds 4 allowed). Open
Open
func (ls *layerStore) CreateRWLayer(name string, parent ChainID, opts *CreateRWLayerOpts) (_ RWLayer, err error) {
var (
storageOpt map[string]string
initFunc MountInit
mountLabel string
Method layerStore.initMount
has 5 return statements (exceeds 4 allowed). Open
Open
func (ls *layerStore) initMount(graphID, parent, mountLabel string, initFunc MountInit, storageOpt map[string]string) (string, error) {
// Use "<graph-id>-init" to maintain compatibility with graph drivers
// which are expecting this layer with this special name. If all
// graph drivers can be updated to not rely on knowing about this layer
// then the initID should be randomly generated.