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()
|
|
|
|
// since that returns an interface to account for umountable layers.
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-08-03 20:22:00 -04:00
|
|
|
return path.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
|
|
|
|
}
|