walk

package
v2.1.1-0...-08c721e Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNoCache

func GetNoCache(ctx context.Context) bool

func SetNoCache

func SetNoCache(ctx context.Context, noCache bool) context.Context

func TypeStrings

func TypeStrings() []string

TypeStrings returns a slice of all String values of the enum

Types

type CachedReader

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

CachedReader reads files from a delegate Reader, appending a cache Entry on read (if on exists) and updating the cache after the file has been processed.

func NewCachedReader

func NewCachedReader(db *bolt.DB, batchSize int, delegate Reader) (*CachedReader, error)

NewCachedReader creates a cache Reader instance, backed by a bolt DB and delegating reads to delegate.

func (*CachedReader) Close

func (c *CachedReader) Close() error

Close waits for any processing to complete.

func (*CachedReader) Read

func (c *CachedReader) Read(ctx context.Context, files []*File) (n int, err error)

type CompositeReader

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

CompositeReader combines multiple Readers into one. It iterates over the given readers, reading each until completion.

func (*CompositeReader) Close

func (c *CompositeReader) Close() error

func (*CompositeReader) Read

func (c *CompositeReader) Read(ctx context.Context, files []*File) (n int, err error)

type File

type File struct {
	Path    string
	RelPath string
	Info    fs.FileInfo

	// FormattedInfo is the result of os.stat after formatting the file.
	FormattedInfo fs.FileInfo

	// FormattersSignature represents the sequence of formatters and their config that was applied to this file.
	FormattersSignature []byte

	// CachedFormatSignature is the last FormatSignature generated for this file, retrieved from the cache.
	CachedFormatSignature []byte
	// contains filtered or unexported fields
}

File represents a file object with its path, relative path, file info, and potential cache entry.

func (*File) AddReleaseFunc

func (f *File) AddReleaseFunc(fn ReleaseFunc)

AddReleaseFunc adds a release function to the File's list of release functions.

func (*File) FormatSignature

func (f *File) FormatSignature(formattersSig []byte) ([]byte, error)

FormatSignature takes the file's info from when it was traversed and appends it to formattersSig, generating a unique format signature which encapsulates the sequence of formatters that were applied to this file and the outcome.

func (*File) NewFormatSignature

func (f *File) NewFormatSignature() ([]byte, error)

NewFormatSignature takes the file's info after being formatted and appends it to FormattersSignature, generating a unique format signature which encapsulates the sequence of formatters that were applied to this file and the outcome.

func (*File) Release

func (f *File) Release(ctx context.Context) error

Release calls all registered release functions for the File and returns an error if any function fails. Accepts a context which can be used to pass parameters to the release hooks.

func (*File) Stat

func (f *File) Stat() (changed bool, info fs.FileInfo, err error)

Stat checks if the file has changed by comparing its current state (size, mod time) to when it was first read. It returns a boolean indicating if the file has changed, the current file info, and an error if any.

func (*File) String

func (f *File) String() string

String returns the file's path as a string.

type FilesystemReader

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

FilesystemReader traverses and reads files from a specified root directory and its subdirectories.

func NewFilesystemReader

func NewFilesystemReader(
	root string,
	path string,
	statz *stats.Stats,
	batchSize int,
) *FilesystemReader

NewFilesystemReader creates a new instance of FilesystemReader to traverse and read files from the specified paths and root.

func (*FilesystemReader) Close

func (f *FilesystemReader) Close() error

Close waits for all filesystem processing to complete.

func (*FilesystemReader) Read

func (f *FilesystemReader) Read(ctx context.Context, files []*File) (n int, err error)

Read populates the provided files array with as many files as are available until the provided context is cancelled. You must ensure to pass a context with a timeout otherwise this will block until files is full.

type GitReader

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

func NewGitReader

func NewGitReader(
	root string,
	path string,
	statz *stats.Stats,
) (*GitReader, error)

func (*GitReader) Close

func (g *GitReader) Close() error

func (*GitReader) Read

func (g *GitReader) Read(ctx context.Context, files []*File) (n int, err error)

type Reader

type Reader interface {
	Read(ctx context.Context, files []*File) (n int, err error)
	Close() error
}

Reader is an interface for reading files.

func NewCompositeReader

func NewCompositeReader(
	walkType Type,
	root string,
	paths []string,
	db *bolt.DB,
	statz *stats.Stats,
) (Reader, error)

func NewReader

func NewReader(
	walkType Type,
	root string,
	path string,
	db *bolt.DB,
	statz *stats.Stats,
) (Reader, error)

type ReleaseFunc

type ReleaseFunc func(ctx context.Context) error

type StdinReader

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

func NewStdinReader

func NewStdinReader(root string, path string, statz *stats.Stats) StdinReader

func (StdinReader) Close

func (s StdinReader) Close() error

func (StdinReader) Read

func (s StdinReader) Read(_ context.Context, files []*File) (n int, err error)

type Type

type Type int
const (
	Auto Type = iota
	Stdin
	Filesystem
	Git

	BatchSize = 1024
)

func TypeString

func TypeString(s string) (Type, error)

TypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func TypeValues

func TypeValues() []Type

TypeValues returns all values of the enum

func (Type) IsAType

func (i Type) IsAType() bool

IsAType returns "true" if the value is listed in the enum definition. "false" otherwise

func (Type) MarshalText

func (i Type) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for Type

func (Type) String

func (i Type) String() string

func (*Type) UnmarshalText

func (i *Type) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for Type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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