2018-02-05 21:05:59 +00:00
|
|
|
package layer // import "github.com/docker/docker/layer"
|
2015-11-18 22:15:00 +00:00
|
|
|
|
2017-08-04 00:22:00 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Getter is an interface to get the path to a layer on the host.
|
|
|
|
type Getter interface {
|
|
|
|
// GetLayerPath gets the path for the layer. This is different from Get()
|
2018-11-18 05:41:53 +00:00
|
|
|
// since that returns an interface to account for unmountable layers.
|
2017-08-04 00:22:00 +00:00
|
|
|
GetLayerPath(id string) (string, error)
|
|
|
|
}
|
2015-11-18 22:15:00 +00:00
|
|
|
|
|
|
|
// GetLayerPath returns the path to a layer
|
|
|
|
func GetLayerPath(s Store, layer ChainID) (string, error) {
|
|
|
|
ls, ok := s.(*layerStore)
|
|
|
|
if !ok {
|
|
|
|
return "", errors.New("unsupported layer store")
|
|
|
|
}
|
|
|
|
ls.layerL.Lock()
|
|
|
|
defer ls.layerL.Unlock()
|
|
|
|
|
|
|
|
rl, ok := ls.layerMap[layer]
|
|
|
|
if !ok {
|
|
|
|
return "", ErrLayerDoesNotExist
|
|
|
|
}
|
|
|
|
|
2017-09-19 19:14:46 +00:00
|
|
|
if layerGetter, ok := ls.driver.(Getter); ok {
|
2017-08-04 00:22:00 +00:00
|
|
|
return layerGetter.GetLayerPath(rl.cacheID)
|
|
|
|
}
|
2017-09-19 19:14:46 +00:00
|
|
|
path, err := ls.driver.Get(rl.cacheID, "")
|
2015-11-18 22:15:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2017-09-19 19:14:46 +00:00
|
|
|
if err := ls.driver.Put(rl.cacheID); err != nil {
|
2015-11-18 22:15:00 +00:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:25:19 +00:00
|
|
|
return string(path), nil
|
2015-11-18 22:15:00 +00:00
|
|
|
}
|
|
|
|
|
2015-12-16 22:13:50 +00:00
|
|
|
func (ls *layerStore) mountID(name string) string {
|
|
|
|
// windows has issues if container ID doesn't match mount ID
|
|
|
|
return name
|
|
|
|
}
|