filesystem

package
v1.203.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package filesystem is a generated GoMock package.

Package filesystem is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetGlobMatches added in v1.203.0

func GetGlobMatches(pattern string) ([]string, error)

GetGlobMatches tries to read and return the Glob matches content from the sync map if it exists in the map, otherwise it finds and returns all files matching the pattern, stores the files in the map and returns the files.

func PathMatch added in v1.203.0

func PathMatch(pattern, name string) (bool, error)

PathMatch returns true if `name` matches the file name `pattern`. PathMatch normalizes both pattern and name to use forward slashes for cross-platform compatibility, then uses doublestar.Match (not PathMatch) which expects Unix-style paths. This ensures patterns work consistently on Windows, Linux, and macOS.

Note: perf.Track() removed from this hot path to reduce overhead (called 2M+ times). Results are cached to avoid redundant pattern matching during affected detection.

func WriteFileAtomicUnix added in v1.203.0

func WriteFileAtomicUnix(filename string, data []byte, perm os.FileMode) error

WriteFileAtomicUnix uses renameio for atomic file writing on Unix systems. This ensures atomic visibility (readers never see truncated files) via temp file + rename. Note: durability depends on fsync behavior.

Types

type FileSystem

type FileSystem interface {
	// Open opens a file for reading.
	Open(name string) (*os.File, error)

	// Create creates or truncates a file.
	Create(name string) (*os.File, error)

	// Stat returns file info.
	Stat(name string) (os.FileInfo, error)

	// MkdirAll creates a directory and all parent directories.
	MkdirAll(path string, perm os.FileMode) error

	// Chmod changes file permissions.
	Chmod(name string, mode os.FileMode) error

	// MkdirTemp creates a temporary directory.
	MkdirTemp(dir, pattern string) (string, error)

	// CreateTemp creates a temporary file in the directory dir with a name beginning with pattern.
	// If dir is the empty string, CreateTemp uses the default directory for temporary files.
	// It returns the opened file and its name.
	CreateTemp(dir, pattern string) (*os.File, error)

	// WriteFile writes data to a file.
	WriteFile(name string, data []byte, perm os.FileMode) error

	// ReadFile reads a file.
	ReadFile(name string) ([]byte, error)

	// Remove removes a file or empty directory.
	Remove(name string) error

	// RemoveAll removes a path and any children.
	RemoveAll(path string) error

	// Walk walks the file tree.
	Walk(root string, fn filepath.WalkFunc) error

	// Getwd returns the current working directory.
	Getwd() (string, error)

	// WriteFileAtomic writes data to a file atomically.
	// On Unix: Uses renameio (write temp + fsync + atomic rename).
	// On Windows: Uses temp file + rename approach.
	WriteFileAtomic(name string, data []byte, perm os.FileMode) error
}

FileSystem defines filesystem operations for testability. This interface allows mocking of file I/O operations in tests.

type GlobMatcher

type GlobMatcher interface {
	// GetGlobMatches returns all files matching the glob pattern.
	GetGlobMatches(pattern string) ([]string, error)

	// PathMatch returns true if name matches the pattern.
	PathMatch(pattern, name string) (bool, error)
}

GlobMatcher defines glob pattern matching operations.

type HomeDirProvider

type HomeDirProvider interface {
	Dir() (string, error)
	Expand(path string) (string, error)
}

HomeDirProvider defines the interface for resolving home directories.

type IOCopier

type IOCopier interface {
	// Copy copies from src to dst until EOF or error.
	Copy(dst io.Writer, src io.Reader) (written int64, err error)
}

IOCopier defines I/O copy operations.

type MockFileSystem

type MockFileSystem struct {
	// contains filtered or unexported fields
}

MockFileSystem is a mock of FileSystem interface.

func NewMockFileSystem

func NewMockFileSystem(ctrl *gomock.Controller) *MockFileSystem

NewMockFileSystem creates a new mock instance.

func (*MockFileSystem) Chmod

func (m *MockFileSystem) Chmod(name string, mode os.FileMode) error

Chmod mocks base method.

func (*MockFileSystem) Create

func (m *MockFileSystem) Create(name string) (*os.File, error)

Create mocks base method.

func (*MockFileSystem) CreateTemp

func (m *MockFileSystem) CreateTemp(dir, pattern string) (*os.File, error)

CreateTemp mocks base method.

func (*MockFileSystem) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockFileSystem) Getwd

func (m *MockFileSystem) Getwd() (string, error)

Getwd mocks base method.

func (*MockFileSystem) MkdirAll

func (m *MockFileSystem) MkdirAll(path string, perm os.FileMode) error

MkdirAll mocks base method.

func (*MockFileSystem) MkdirTemp

func (m *MockFileSystem) MkdirTemp(dir, pattern string) (string, error)

MkdirTemp mocks base method.

func (*MockFileSystem) Open

func (m *MockFileSystem) Open(name string) (*os.File, error)

Open mocks base method.

func (*MockFileSystem) ReadFile

func (m *MockFileSystem) ReadFile(name string) ([]byte, error)

ReadFile mocks base method.

func (*MockFileSystem) Remove

func (m *MockFileSystem) Remove(name string) error

Remove mocks base method.

func (*MockFileSystem) RemoveAll

func (m *MockFileSystem) RemoveAll(path string) error

RemoveAll mocks base method.

func (*MockFileSystem) Stat

func (m *MockFileSystem) Stat(name string) (os.FileInfo, error)

Stat mocks base method.

func (*MockFileSystem) Walk

func (m *MockFileSystem) Walk(root string, fn filepath.WalkFunc) error

Walk mocks base method.

func (*MockFileSystem) WriteFile

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

WriteFile mocks base method.

func (*MockFileSystem) WriteFileAtomic added in v1.203.0

func (m *MockFileSystem) WriteFileAtomic(name string, data []byte, perm os.FileMode) error

WriteFileAtomic mocks base method.

type MockFileSystemMockRecorder

type MockFileSystemMockRecorder struct {
	// contains filtered or unexported fields
}

MockFileSystemMockRecorder is the mock recorder for MockFileSystem.

func (*MockFileSystemMockRecorder) Chmod

func (mr *MockFileSystemMockRecorder) Chmod(name, mode any) *gomock.Call

Chmod indicates an expected call of Chmod.

func (*MockFileSystemMockRecorder) Create

func (mr *MockFileSystemMockRecorder) Create(name any) *gomock.Call

Create indicates an expected call of Create.

func (*MockFileSystemMockRecorder) CreateTemp

func (mr *MockFileSystemMockRecorder) CreateTemp(dir, pattern any) *gomock.Call

CreateTemp indicates an expected call of CreateTemp.

func (*MockFileSystemMockRecorder) Getwd

func (mr *MockFileSystemMockRecorder) Getwd() *gomock.Call

Getwd indicates an expected call of Getwd.

func (*MockFileSystemMockRecorder) MkdirAll

func (mr *MockFileSystemMockRecorder) MkdirAll(path, perm any) *gomock.Call

MkdirAll indicates an expected call of MkdirAll.

func (*MockFileSystemMockRecorder) MkdirTemp

func (mr *MockFileSystemMockRecorder) MkdirTemp(dir, pattern any) *gomock.Call

MkdirTemp indicates an expected call of MkdirTemp.

func (*MockFileSystemMockRecorder) Open

func (mr *MockFileSystemMockRecorder) Open(name any) *gomock.Call

Open indicates an expected call of Open.

func (*MockFileSystemMockRecorder) ReadFile

func (mr *MockFileSystemMockRecorder) ReadFile(name any) *gomock.Call

ReadFile indicates an expected call of ReadFile.

func (*MockFileSystemMockRecorder) Remove

func (mr *MockFileSystemMockRecorder) Remove(name any) *gomock.Call

Remove indicates an expected call of Remove.

func (*MockFileSystemMockRecorder) RemoveAll

func (mr *MockFileSystemMockRecorder) RemoveAll(path any) *gomock.Call

RemoveAll indicates an expected call of RemoveAll.

func (*MockFileSystemMockRecorder) Stat

func (mr *MockFileSystemMockRecorder) Stat(name any) *gomock.Call

Stat indicates an expected call of Stat.

func (*MockFileSystemMockRecorder) Walk

func (mr *MockFileSystemMockRecorder) Walk(root, fn any) *gomock.Call

Walk indicates an expected call of Walk.

func (*MockFileSystemMockRecorder) WriteFile

func (mr *MockFileSystemMockRecorder) WriteFile(name, data, perm any) *gomock.Call

WriteFile indicates an expected call of WriteFile.

func (*MockFileSystemMockRecorder) WriteFileAtomic added in v1.203.0

func (mr *MockFileSystemMockRecorder) WriteFileAtomic(name, data, perm any) *gomock.Call

WriteFileAtomic indicates an expected call of WriteFileAtomic.

type MockGlobMatcher

type MockGlobMatcher struct {
	// contains filtered or unexported fields
}

MockGlobMatcher is a mock of GlobMatcher interface.

func NewMockGlobMatcher

func NewMockGlobMatcher(ctrl *gomock.Controller) *MockGlobMatcher

NewMockGlobMatcher creates a new mock instance.

func (*MockGlobMatcher) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockGlobMatcher) GetGlobMatches

func (m *MockGlobMatcher) GetGlobMatches(pattern string) ([]string, error)

GetGlobMatches mocks base method.

func (*MockGlobMatcher) PathMatch

func (m *MockGlobMatcher) PathMatch(pattern, name string) (bool, error)

PathMatch mocks base method.

type MockGlobMatcherMockRecorder

type MockGlobMatcherMockRecorder struct {
	// contains filtered or unexported fields
}

MockGlobMatcherMockRecorder is the mock recorder for MockGlobMatcher.

func (*MockGlobMatcherMockRecorder) GetGlobMatches

func (mr *MockGlobMatcherMockRecorder) GetGlobMatches(pattern any) *gomock.Call

GetGlobMatches indicates an expected call of GetGlobMatches.

func (*MockGlobMatcherMockRecorder) PathMatch

func (mr *MockGlobMatcherMockRecorder) PathMatch(pattern, name any) *gomock.Call

PathMatch indicates an expected call of PathMatch.

type MockHomeDirProvider

type MockHomeDirProvider struct {
	// contains filtered or unexported fields
}

MockHomeDirProvider is a mock of HomeDirProvider interface.

func NewMockHomeDirProvider

func NewMockHomeDirProvider(ctrl *gomock.Controller) *MockHomeDirProvider

NewMockHomeDirProvider creates a new mock instance.

func (*MockHomeDirProvider) Dir

func (m *MockHomeDirProvider) Dir() (string, error)

Dir mocks base method.

func (*MockHomeDirProvider) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockHomeDirProvider) Expand

func (m *MockHomeDirProvider) Expand(path string) (string, error)

Expand mocks base method.

type MockHomeDirProviderMockRecorder

type MockHomeDirProviderMockRecorder struct {
	// contains filtered or unexported fields
}

MockHomeDirProviderMockRecorder is the mock recorder for MockHomeDirProvider.

func (*MockHomeDirProviderMockRecorder) Dir

Dir indicates an expected call of Dir.

func (*MockHomeDirProviderMockRecorder) Expand

func (mr *MockHomeDirProviderMockRecorder) Expand(path any) *gomock.Call

Expand indicates an expected call of Expand.

type MockIOCopier

type MockIOCopier struct {
	// contains filtered or unexported fields
}

MockIOCopier is a mock of IOCopier interface.

func NewMockIOCopier

func NewMockIOCopier(ctrl *gomock.Controller) *MockIOCopier

NewMockIOCopier creates a new mock instance.

func (*MockIOCopier) Copy

func (m *MockIOCopier) Copy(dst io.Writer, src io.Reader) (int64, error)

Copy mocks base method.

func (*MockIOCopier) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

type MockIOCopierMockRecorder

type MockIOCopierMockRecorder struct {
	// contains filtered or unexported fields
}

MockIOCopierMockRecorder is the mock recorder for MockIOCopier.

func (*MockIOCopierMockRecorder) Copy

func (mr *MockIOCopierMockRecorder) Copy(dst, src any) *gomock.Call

Copy indicates an expected call of Copy.

type OSFileSystem

type OSFileSystem struct{}

OSFileSystem is the default implementation that uses the os package.

func NewOSFileSystem

func NewOSFileSystem() *OSFileSystem

NewOSFileSystem creates a new OS filesystem implementation.

func (*OSFileSystem) Chmod

func (o *OSFileSystem) Chmod(name string, mode os.FileMode) error

Chmod changes file permissions.

func (*OSFileSystem) Create

func (o *OSFileSystem) Create(name string) (*os.File, error)

Create creates or truncates a file.

func (*OSFileSystem) CreateTemp

func (o *OSFileSystem) CreateTemp(dir, pattern string) (*os.File, error)

CreateTemp creates a temporary file in the directory dir with a name beginning with pattern.

func (*OSFileSystem) Getwd

func (o *OSFileSystem) Getwd() (string, error)

Getwd returns the current working directory.

func (*OSFileSystem) MkdirAll

func (o *OSFileSystem) MkdirAll(path string, perm os.FileMode) error

MkdirAll creates a directory and all parent directories.

func (*OSFileSystem) MkdirTemp

func (o *OSFileSystem) MkdirTemp(dir, pattern string) (string, error)

MkdirTemp creates a temporary directory.

func (*OSFileSystem) Open

func (o *OSFileSystem) Open(name string) (*os.File, error)

Open opens a file for reading.

func (*OSFileSystem) ReadFile

func (o *OSFileSystem) ReadFile(name string) ([]byte, error)

ReadFile reads a file.

func (*OSFileSystem) Remove

func (o *OSFileSystem) Remove(name string) error

Remove removes a file or empty directory.

func (*OSFileSystem) RemoveAll

func (o *OSFileSystem) RemoveAll(path string) error

RemoveAll removes a path and any children.

func (*OSFileSystem) Stat

func (o *OSFileSystem) Stat(name string) (os.FileInfo, error)

Stat returns file info.

func (*OSFileSystem) Walk

func (o *OSFileSystem) Walk(root string, fn filepath.WalkFunc) error

Walk walks the file tree.

func (*OSFileSystem) WriteFile

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

WriteFile writes data to a file.

func (*OSFileSystem) WriteFileAtomic added in v1.203.0

func (o *OSFileSystem) WriteFileAtomic(name string, data []byte, perm os.FileMode) error

WriteFileAtomic writes data to a file atomically using platform-specific implementations.

type OSGlobMatcher

type OSGlobMatcher struct{}

OSGlobMatcher is the default implementation that uses pkg/utils.

func NewOSGlobMatcher

func NewOSGlobMatcher() *OSGlobMatcher

NewOSGlobMatcher creates a new OS glob matcher implementation.

func (*OSGlobMatcher) GetGlobMatches

func (o *OSGlobMatcher) GetGlobMatches(pattern string) ([]string, error)

GetGlobMatches returns all files matching the glob pattern.

func (*OSGlobMatcher) PathMatch

func (o *OSGlobMatcher) PathMatch(pattern, name string) (bool, error)

PathMatch returns true if name matches the pattern.

type OSHomeDirProvider

type OSHomeDirProvider struct{}

OSHomeDirProvider is the default implementation using Atmos's vendored homedir package.

func NewOSHomeDirProvider

func NewOSHomeDirProvider() *OSHomeDirProvider

NewOSHomeDirProvider creates a new OS homedir provider.

func (*OSHomeDirProvider) Dir

func (h *OSHomeDirProvider) Dir() (string, error)

Dir returns the home directory for the current user.

func (*OSHomeDirProvider) Expand

func (h *OSHomeDirProvider) Expand(path string) (string, error)

Expand expands the path to include the home directory if the path begins with `~`.

type OSIOCopier

type OSIOCopier struct{}

OSIOCopier is the default implementation that uses io.Copy.

func NewOSIOCopier

func NewOSIOCopier() *OSIOCopier

NewOSIOCopier creates a new OS I/O copier implementation.

func (*OSIOCopier) Copy

func (o *OSIOCopier) Copy(dst io.Writer, src io.Reader) (written int64, err error)

Copy copies from src to dst until EOF or error.

Jump to

Keyboard shortcuts

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