github.com/replicatedhq/ship@v0.55.0/pkg/lifecycle/render/root/fs.go (about)

     1  package root
     2  
     3  import (
     4  	"github.com/pkg/errors"
     5  	"github.com/replicatedhq/ship/pkg/constants"
     6  	"github.com/spf13/afero"
     7  )
     8  
     9  // Fs is a struct for a filesystem with a base path of RootPath
    10  type Fs struct {
    11  	afero.Afero
    12  	RootPath string
    13  }
    14  
    15  func (f Fs) TempDir(prefix, name string) (string, error) {
    16  	if prefix == "" {
    17  		return "", errors.New("rootfs does not support using system default temp dirs")
    18  	}
    19  	return f.Afero.TempDir(prefix, name)
    20  }
    21  
    22  // NewRootFS initializes a Fs struct with a base path of root
    23  func NewRootFS(fs afero.Afero, root string) Fs {
    24  	if root == "" {
    25  		root = constants.InstallerPrefixPath
    26  	}
    27  	if root != "." && root != "./" {
    28  		fs = afero.Afero{
    29  			Fs: afero.NewBasePathFs(fs.Fs, root),
    30  		}
    31  	}
    32  	return Fs{
    33  		Afero:    fs,
    34  		RootPath: root,
    35  	}
    36  }