filetracking

package
v2.934.3 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanOrphanedFiles

func CleanOrphanedFiles(
	ctx context.Context,
	outDir string,
	newFiles []string,
	previousFiles []string,
	untrackedPatterns []*regexp.Regexp,
	ignore *Ignore,
	onRemovedFile func(string),
) error

CleanOrphanedFiles removes any previously generated files that are no longer being generated in a subsequent generation run. These orphaned files cannot stay behind because they can accidentally break builds or augment an SDK's behavior or public interface in unexpected ways.

func CleanOrphanedFilesByDirWalk

func CleanOrphanedFilesByDirWalk(
	ctx context.Context,
	outDir string,
	subDir string,
	trackedFiles map[string]struct{},
	skipSubDirs []string,
	untrackedPatterns []*regexp.Regexp,
	ignore *Ignore,
	onRemovedFile func(string),
) error

CleanOrphanedFilesByDirWalk removes any file under subDir (relative to outDir) that is not present in trackedFiles, ignoring matches against .genignore or untrackedPatterns. Paths in trackedFiles and the keys passed to ignore must be relative to outDir using forward slashes.

skipSubDirs lists directory paths relative to subDir that should not be traversed at all. Useful for subtrees populated by direct file copies that bypass the file tracker, where every entry would otherwise look like an orphan.

Unlike CleanOrphanedFiles, this is anchored to disk state rather than a prior gen.lock, so it removes files that were never recorded in gen.lock for any reason. Callers should only invoke this for subtrees that are fully owned by the generator (e.g. generated test infrastructure).

Types

type AddHeaderPattern

type AddHeaderPattern struct {
	Pattern   *regexp.Regexp
	DontMatch bool
}

type FileTrackerResult

type FileTrackerResult struct {
	NewFiles      config.TrackedFiles
	PreviousFiles []string
}

type Ignore

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

Ignore encapsulates zero or more .genignore files and provides the ShouldIgnore method to check whether a given file matches the .genignore loaded files.

func NewIgnore

func NewIgnore() *Ignore

NewIgnore creates an empty Ignore struct. You will need to call AddGenIgnoreFile to add .genignore files to it.

func NewIgnoreFromRoot

func NewIgnoreFromRoot(root string) (*Ignore, error)

NewIgnoreFromRoot creates an Ignore struct by walking the given root directory and adding any .genignore files it finds.

func (*Ignore) AddGenIgnoreFile

func (i *Ignore) AddGenIgnoreFile(root, genFile string) error

AddGenIgnoreFile adds a .genignore file to the Ignore struct. The root parameter is the root directory of the project, and genFile is the path to the .genignore file relative to the root.

func (*Ignore) AddIgnoreOverride

func (i *Ignore) AddIgnoreOverride(regex string)

Add a regex pattern that will not be ignored even if its present in the .genignore file

func (*Ignore) HasIgnoredFiles

func (i *Ignore) HasIgnoredFiles() bool

func (*Ignore) ShouldIgnore

func (i *Ignore) ShouldIgnore(path string) bool

ShouldIgnore returns true if the given path should be ignored, false otherwise.

type OnWriteFileFunc

type OnWriteFileFunc func(filename string, data []byte, perm fs.FileMode, checkExisting bool) error

type Options

type Options struct {
	OutDir    string
	GenLockId string
	FS        filesystem.FileSystem
	// SkipTempLockFile skips writing to the temporary lock file during generation.
	// When persistent edits is enabled, files are collected in memory and written
	// atomically at the end, so the incremental crash-recovery lock file is unnecessary.
	// We still read any existing lock file for orphan cleanup from previous crashes.
	SkipTempLockFile bool
	// SkipChecksums skips computing and recording last_write_checksum for tracked
	// files. When persistent edits is explicitly disabled (enabled: never) nothing
	// consumes the checksums, and omitting them keeps gen.lock stable across
	// regenerations so parallel branches don't merge-conflict on checksum churn.
	SkipChecksums bool
}

type Tracker

type Tracker struct {

	// List of file path regular expressions that should not be tracked.
	// Automatically instantiated with files such as README.md, .gitignore,
	// documentation theme files, and others in [NewTracker]. Targets can
	// dynamically add to these via AddUntrackedPattern.
	UntrackedPatterns []*regexp.Regexp

	// List of file path regular expressions that should not have a header.
	AddHeaderPatterns []*AddHeaderPattern

	Options Options
	// contains filtered or unexported fields
}

Tracker keeps track of all the files created either by generating file content by executing a template or by copying a file. Tracked files are then written to a file called files.gen in the root of the output directory.

func NewTracker

func NewTracker(ctx context.Context, opts Options) *Tracker

NewTracker creates a new Tracker.

func (*Tracker) AddHeaderToFile

func (t *Tracker) AddHeaderToFile(file string) bool

AddHeaderToFile returns true if the file requires a header.

func (*Tracker) AddUntrackedPattern

func (t *Tracker) AddUntrackedPattern(pattern *regexp.Regexp)

AddUntrackedPattern appends a compiled regex to the untracked patterns list. It is safe for concurrent use.

func (*Tracker) Close

func (t *Tracker) Close(ctx context.Context)

func (*Tracker) GetResult

func (t *Tracker) GetResult() FileTrackerResult

func (*Tracker) IsUntrackedPatternFile

func (t *Tracker) IsUntrackedPatternFile(file string) bool

IsUntrackedPatternFile returns true if the file matches any regular expressions in the Tracker UntrackedPatterns.

func (*Tracker) TrackFile

func (t *Tracker) TrackFile(file string, data []byte)

TrackFile is called for each generated file that needs to be tracked in the generatedFiles section in the gen.lock file. Some special file names are ignored.

func (*Tracker) TrackFileImmediate

func (t *Tracker) TrackFileImmediate(file string, data []byte) error

TrackFileImmediate records a generated file outside the normal template tracking channel.

func (*Tracker) UntrackFile

func (t *Tracker) UntrackFile(path string)

UntrackFile removes a generated file from the current run's tracked set. This is used when a patch file deletes a virtual file after templates have already reported it to the tracker. The removal goes through the tracking channel so it is ordered after any in-flight TrackFile for the same path; once the channel is drained (GetResult) it falls back to a direct delete.

func (*Tracker) UpdateTrackedFile

func (t *Tracker) UpdateTrackedFile(path string, id, pristineGitObject string)

UpdateTrackedFile updates a tracked file entry with ID and PristineGitObject metadata. This is used by the patches subsystem after the 3-way merge completes.

func (*Tracker) UpdateTrackedFileChecksum

func (t *Tracker) UpdateTrackedFileChecksum(path string, data []byte)

UpdateTrackedFileChecksum updates the checksum for a tracked file. This is used after compilation modifies files to ensure gen.lock checksums match the post-compile file content.

Jump to

Keyboard shortcuts

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