github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/builder/fscache/naivedriver.go (about)

     1  package fscache
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  
     7  	"github.com/pkg/errors"
     8  )
     9  
    10  // NewNaiveCacheBackend is a basic backend implementation for fscache
    11  func NewNaiveCacheBackend(root string) Backend {
    12  	return &naiveCacheBackend{root: root}
    13  }
    14  
    15  type naiveCacheBackend struct {
    16  	root string
    17  }
    18  
    19  func (tcb *naiveCacheBackend) Get(id string) (string, error) {
    20  	d := filepath.Join(tcb.root, id)
    21  	if err := os.MkdirAll(d, 0700); err != nil {
    22  		return "", errors.Wrapf(err, "failed to create tmp dir for %s", d)
    23  	}
    24  	return d, nil
    25  }
    26  func (tcb *naiveCacheBackend) Remove(id string) error {
    27  	return errors.WithStack(os.RemoveAll(filepath.Join(tcb.root, id)))
    28  }