cache

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MountTargetExists

func MountTargetExists(path string) (bool, error)

MountTargetExists checks if a mount target path exists and has content. For files, it returns true if the file exists. For directories, it returns true only if the directory is non-empty. For symlinks, it follows the link and applies the same logic. Returns false for non-existent paths or broken symlinks.

Types

type CacheMetadata

type CacheMetadata struct {
	UpdatedAt   string                        `json:"updatedAt"`
	Version     int                           `json:"version"`
	UserRequest map[string]CacheMetadataEntry `json:"userRequest"`
}

type CacheMetadataEntry

type CacheMetadataEntry struct {
	CacheFramework *string  `json:"cacheFramework"`
	MountTarget    []string `json:"mountTarget"`
	Source         string   `json:"source"`
}

type DefaultExecutor

type DefaultExecutor struct{}

func (DefaultExecutor) DiskUsage

func (e DefaultExecutor) DiskUsage(ctx context.Context, path string) (DiskUsage, error)

func (DefaultExecutor) MkdirAll

func (e DefaultExecutor) MkdirAll(path string, perm os.FileMode) error

func (DefaultExecutor) Mount

func (e DefaultExecutor) Mount(ctx context.Context, from, to string) error

func (DefaultExecutor) RemoveAll

func (e DefaultExecutor) RemoveAll(name string) error

func (DefaultExecutor) Stat

func (e DefaultExecutor) Stat(name string) (os.FileInfo, error)

func (DefaultExecutor) WriteFile

func (e DefaultExecutor) WriteFile(name string, data []byte, perm os.FileMode) error

type DiskUsage

type DiskUsage struct {
	Total string `json:"total"`
	Used  string `json:"used"`
}

type Executor

type Executor interface {
	DiskUsage(ctx context.Context, path string) (DiskUsage, error)
	MkdirAll(path string, perm os.FileMode) error
	Mount(ctx context.Context, from, to string) error
	RemoveAll(name string) error
	Stat(name string) (os.FileInfo, error)
	WriteFile(name string, data []byte, perm os.FileMode) error
}

type ExecutorMock

type ExecutorMock struct {
	// DiskUsageFunc mocks the DiskUsage method.
	DiskUsageFunc func(ctx context.Context, path string) (DiskUsage, error)

	// MkdirAllFunc mocks the MkdirAll method.
	MkdirAllFunc func(path string, perm os.FileMode) error

	// MountFunc mocks the Mount method.
	MountFunc func(ctx context.Context, from string, to string) error

	// RemoveAllFunc mocks the RemoveAll method.
	RemoveAllFunc func(name string) error

	// StatFunc mocks the Stat method.
	StatFunc func(name string) (os.FileInfo, error)

	// WriteFileFunc mocks the WriteFile method.
	WriteFileFunc func(name string, data []byte, perm os.FileMode) error
	// contains filtered or unexported fields
}

ExecutorMock is a mock implementation of Executor.

func TestSomethingThatUsesExecutor(t *testing.T) {

	// make and configure a mocked Executor
	mockedExecutor := &ExecutorMock{
		DiskUsageFunc: func(ctx context.Context, path string) (DiskUsage, error) {
			panic("mock out the DiskUsage method")
		},
		MkdirAllFunc: func(path string, perm os.FileMode) error {
			panic("mock out the MkdirAll method")
		},
		MountFunc: func(ctx context.Context, from string, to string) error {
			panic("mock out the Mount method")
		},
		RemoveAllFunc: func(name string) error {
			panic("mock out the RemoveAll method")
		},
		StatFunc: func(name string) (os.FileInfo, error) {
			panic("mock out the Stat method")
		},
		WriteFileFunc: func(name string, data []byte, perm os.FileMode) error {
			panic("mock out the WriteFile method")
		},
	}

	// use mockedExecutor in code that requires Executor
	// and then make assertions.

}

func (*ExecutorMock) DiskUsage

func (mock *ExecutorMock) DiskUsage(ctx context.Context, path string) (DiskUsage, error)

DiskUsage calls DiskUsageFunc.

func (*ExecutorMock) DiskUsageCalls

func (mock *ExecutorMock) DiskUsageCalls() []struct {
	Ctx  context.Context
	Path string
}

DiskUsageCalls gets all the calls that were made to DiskUsage. Check the length with:

len(mockedExecutor.DiskUsageCalls())

func (*ExecutorMock) MkdirAll

func (mock *ExecutorMock) MkdirAll(path string, perm os.FileMode) error

MkdirAll calls MkdirAllFunc.

func (*ExecutorMock) MkdirAllCalls

func (mock *ExecutorMock) MkdirAllCalls() []struct {
	Path string
	Perm os.FileMode
}

MkdirAllCalls gets all the calls that were made to MkdirAll. Check the length with:

len(mockedExecutor.MkdirAllCalls())

func (*ExecutorMock) Mount

func (mock *ExecutorMock) Mount(ctx context.Context, from string, to string) error

Mount calls MountFunc.

func (*ExecutorMock) MountCalls

func (mock *ExecutorMock) MountCalls() []struct {
	Ctx  context.Context
	From string
	To   string
}

MountCalls gets all the calls that were made to Mount. Check the length with:

len(mockedExecutor.MountCalls())

func (*ExecutorMock) RemoveAll

func (mock *ExecutorMock) RemoveAll(name string) error

RemoveAll calls RemoveAllFunc.

func (*ExecutorMock) RemoveAllCalls

func (mock *ExecutorMock) RemoveAllCalls() []struct {
	Name string
}

RemoveAllCalls gets all the calls that were made to RemoveAll. Check the length with:

len(mockedExecutor.RemoveAllCalls())

func (*ExecutorMock) Stat

func (mock *ExecutorMock) Stat(name string) (os.FileInfo, error)

Stat calls StatFunc.

func (*ExecutorMock) StatCalls

func (mock *ExecutorMock) StatCalls() []struct {
	Name string
}

StatCalls gets all the calls that were made to Stat. Check the length with:

len(mockedExecutor.StatCalls())

func (*ExecutorMock) WriteFile

func (mock *ExecutorMock) WriteFile(name string, data []byte, perm os.FileMode) error

WriteFile calls WriteFileFunc.

func (*ExecutorMock) WriteFileCalls

func (mock *ExecutorMock) WriteFileCalls() []struct {
	Name string
	Data []byte
	Perm os.FileMode
}

WriteFileCalls gets all the calls that were made to WriteFile. Check the length with:

len(mockedExecutor.WriteFileCalls())

type MountRequest

type MountRequest struct {
	DetectAllModes bool
	DetectModes    []string
	ManualModes    []string
	ManualPaths    []string
}

func (MountRequest) EnabledModes

func (req MountRequest) EnabledModes(ctx context.Context, available mode.Modes) (mode.Modes, error)

EnabledModes returns the set of enabled cache modes based on the request. It performs detection as necessary, based on the detect modes specified.

type MountResponse

type MountResponse struct {
	Input  MountResponseInput  `json:"input,omitzero"`
	Output MountResponseOutput `json:"output,omitzero"`
}

type MountResponseInput

type MountResponseInput struct {
	Modes []string `json:"modes,omitzero"`
	Paths []string `json:"paths,omitzero"`
}

type MountResponseOutput

type MountResponseOutput struct {
	DestructiveMode bool              `json:"destructive_mode"`
	AddEnvs         map[string]string `json:"add_envs,omitzero"`
	DiskUsage       *DiskUsage        `json:"disk_usage,omitzero"` // lookup can fail, so inclusion is optional
	Mounts          []MountResult     `json:"mounts,omitzero"`
	RemovedPaths    []string          `json:"removed_paths,omitzero"`
}

type MountResult

type MountResult struct {
	Mode      string `json:"mode,omitzero"`
	CachePath string `json:"cache_path"`
	MountPath string `json:"mount_path"`
	CacheHit  bool   `json:"cache_hit"`
}

type Mounter

type Mounter struct {
	DestructiveMode bool
	CacheRoot       string
	Exec            Executor
	Modes           mode.Modes
}

func NewMounter

func NewMounter(cacheRoot string) (Mounter, error)

func (Mounter) Mount

func (m Mounter) Mount(ctx context.Context, req MountRequest) (MountResponse, error)

Mount mounts the cache paths based on the given request.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL