github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/xdg/fake.go (about)

     1  package xdg
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  )
     8  
     9  type FakeBase struct {
    10  	Dir string
    11  }
    12  
    13  var _ Base = FakeBase{}
    14  
    15  func (b FakeBase) createPath(prefix, relPath string) (string, error) {
    16  	p := filepath.Join(b.Dir, "cache", relPath)
    17  	dir := filepath.Dir(p)
    18  	err := os.MkdirAll(dir, os.ModeDir|0700)
    19  	if err != nil {
    20  		return "", fmt.Errorf("creating dir %s: %v", dir, err)
    21  	}
    22  	return p, nil
    23  }
    24  
    25  func (b FakeBase) CacheFile(relPath string) (string, error) {
    26  	return b.createPath("cache", relPath)
    27  }
    28  func (b FakeBase) ConfigFile(relPath string) (string, error) {
    29  	return b.createPath("config", relPath)
    30  }
    31  func (b FakeBase) DataFile(relPath string) (string, error) {
    32  	return b.createPath("data", relPath)
    33  }
    34  func (b FakeBase) StateFile(relPath string) (string, error) {
    35  	return b.createPath("state", relPath)
    36  }
    37  func (b FakeBase) RuntimeFile(relPath string) (string, error) {
    38  	return b.createPath("runtime", relPath)
    39  }