2018-02-05 16:05:59 -05:00
|
|
|
package layer // import "github.com/docker/docker/layer"
|
2015-11-18 17:15:00 -05:00
|
|
|
|
2017-08-03 20:22:00 -04: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 00:41:53 -05:00
|
|
|
// since that returns an interface to account for unmountable layers.
|
2017-08-03 20:22:00 -04:00
|
|
|
GetLayerPath(id string) (string, error)
|
|
|
|
}
|
2015-11-18 17:15:00 -05: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 15:14:46 -04:00
|
|
|
if layerGetter, ok := ls.driver.(Getter); ok {
|
2017-08-03 20:22:00 -04:00
|
|
|
return layerGetter.GetLayerPath(rl.cacheID)
|
|
|
|
}
|
2017-09-19 15:14:46 -04:00
|
|
|
path, err := ls.driver.Get(rl.cacheID, "")
|
2015-11-18 17:15:00 -05:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2017-09-19 15:14:46 -04:00
|
|
|
if err := ls.driver.Put(rl.cacheID); err != nil {
|
2015-11-18 17:15:00 -05:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2022-09-23 14:09:51 -04:00
|
|
|
return path, nil
|
2015-11-18 17:15:00 -05:00
|
|
|
}
|
|
|
|
|
2015-12-16 17:13:50 -05:00
|
|
|
func (ls *layerStore) mountID(name string) string {
|
|
|
|
// windows has issues if container ID doesn't match mount ID
|
|
|
|
return name
|
|
|
|
}
|