Skip to content

Commit

Permalink
Add Map() method to LayerStore interface
Browse files Browse the repository at this point in the history
This method return a map associating a chain ID to its layer object

Signed-off-by: Kenfe-Mickael Laventure <[email protected]>
  • Loading branch information
mlaventure committed Sep 29, 2016
1 parent ad398f1 commit 148aef9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions distribution/xfer/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ func createChainIDFromParent(parent layer.ChainID, dgsts ...layer.DiffID) layer.
return createChainIDFromParent(layer.ChainID(dgst), dgsts[1:]...)
}

func (ls *mockLayerStore) Map() map[layer.ChainID]layer.Layer {
layers := map[layer.ChainID]layer.Layer{}

for k, v := range ls.layers {
layers[k] = v
}

return layers
}

func (ls *mockLayerStore) Register(reader io.Reader, parentID layer.ChainID) (layer.Layer, error) {
return ls.RegisterWithDescriptor(reader, parentID, distribution.Descriptor{})
}
Expand Down
1 change: 1 addition & 0 deletions layer/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ type MountInit func(root string) error
type Store interface {
Register(io.Reader, ChainID) (Layer, error)
Get(ChainID) (Layer, error)
Map() map[ChainID]Layer
Release(Layer) ([]Metadata, error)

CreateRWLayer(id string, parent ChainID, mountLabel string, initFunc MountInit, storageOpt map[string]string) (RWLayer, error)
Expand Down
13 changes: 13 additions & 0 deletions layer/layer_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,19 @@ func (ls *layerStore) Get(l ChainID) (Layer, error) {
return layer.getReference(), nil
}

func (ls *layerStore) Map() map[ChainID]Layer {
ls.layerL.Lock()
defer ls.layerL.Unlock()

layers := map[ChainID]Layer{}

for k, v := range ls.layerMap {
layers[k] = v
}

return layers
}

func (ls *layerStore) deleteLayer(layer *roLayer, metadata *Metadata) error {
err := ls.driver.Remove(layer.cacheID)
if err != nil {
Expand Down

0 comments on commit 148aef9

Please sign in to comment.