github.com/reds/docker@v1.11.2-rc1/layer/layer_windows.go (about)

     1  package layer
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"github.com/Sirupsen/logrus"
     8  	"github.com/docker/distribution/digest"
     9  	"github.com/docker/docker/daemon/graphdriver"
    10  )
    11  
    12  // GetLayerPath returns the path to a layer
    13  func GetLayerPath(s Store, layer ChainID) (string, error) {
    14  	ls, ok := s.(*layerStore)
    15  	if !ok {
    16  		return "", errors.New("unsupported layer store")
    17  	}
    18  	ls.layerL.Lock()
    19  	defer ls.layerL.Unlock()
    20  
    21  	rl, ok := ls.layerMap[layer]
    22  	if !ok {
    23  		return "", ErrLayerDoesNotExist
    24  	}
    25  
    26  	path, err := ls.driver.Get(rl.cacheID, "")
    27  	if err != nil {
    28  		return "", err
    29  	}
    30  
    31  	if err := ls.driver.Put(rl.cacheID); err != nil {
    32  		return "", err
    33  	}
    34  
    35  	return path, nil
    36  }
    37  
    38  func (ls *layerStore) RegisterDiffID(graphID string, size int64) (Layer, error) {
    39  	var err error // this is used for cleanup in existingLayer case
    40  	diffID := digest.FromBytes([]byte(graphID))
    41  
    42  	// Create new roLayer
    43  	layer := &roLayer{
    44  		cacheID:        graphID,
    45  		diffID:         DiffID(diffID),
    46  		referenceCount: 1,
    47  		layerStore:     ls,
    48  		references:     map[Layer]struct{}{},
    49  		size:           size,
    50  	}
    51  
    52  	tx, err := ls.store.StartTransaction()
    53  	if err != nil {
    54  		return nil, err
    55  	}
    56  	defer func() {
    57  		if err != nil {
    58  			if err := tx.Cancel(); err != nil {
    59  				logrus.Errorf("Error canceling metadata transaction %q: %s", tx.String(), err)
    60  			}
    61  		}
    62  	}()
    63  
    64  	layer.chainID = createChainIDFromParent("", layer.diffID)
    65  
    66  	if !ls.driver.Exists(layer.cacheID) {
    67  		return nil, fmt.Errorf("layer %q is unknown to driver", layer.cacheID)
    68  	}
    69  	if err = storeLayer(tx, layer); err != nil {
    70  		return nil, err
    71  	}
    72  
    73  	ls.layerL.Lock()
    74  	defer ls.layerL.Unlock()
    75  
    76  	if existingLayer := ls.getWithoutLock(layer.chainID); existingLayer != nil {
    77  		// Set error for cleanup, but do not return
    78  		err = errors.New("layer already exists")
    79  		return existingLayer.getReference(), nil
    80  	}
    81  
    82  	if err = tx.Commit(layer.chainID); err != nil {
    83  		return nil, err
    84  	}
    85  
    86  	ls.layerMap[layer.chainID] = layer
    87  
    88  	return layer.getReference(), nil
    89  }
    90  
    91  func (ls *layerStore) mountID(name string) string {
    92  	// windows has issues if container ID doesn't match mount ID
    93  	return name
    94  }
    95  
    96  func (ls *layerStore) GraphDriver() graphdriver.Driver {
    97  	return ls.driver
    98  }