filesetwriter

package
v0.0.0-...-336081c Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConflictPolicy

type ConflictPolicy int

ConflictPolicy determines what happens when a target file already exists.

const (
	Overwrite ConflictPolicy = iota // Replace the existing file (default).
	Skip                            // Don't write; keep the original.
	Rename                          // Write to AlternatePath instead.
	Update                          // Like Overwrite, but shown as less scary in preview.
)

type FileAction

type FileAction int

FileAction describes the resolved action for a file after scanning.

const (
	ActionCreate    FileAction = iota // File is new, will be created.
	ActionOverwrite                   // File exists, will be overwritten.
	ActionSkip                        // File exists, will be skipped.
	ActionRename                      // File exists, will be written to alternate path.
	ActionUpdate                      // File exists, will be updated with explanation.
	ActionUnchanged                   // File exists with identical content, no write needed.
)

type FileResult

type FileResult struct {
	File      PlannedFile // The original planned file.
	Action    FileAction  // Resolved action after scan.
	WritePath string      // Actual path that will be written (may differ for Rename).
	Exists    bool        // Target path already exists on disk.
	ReadOnly  bool        // File at WritePath is read-only.
}

FileResult is the scan result for a single planned file.

type Plan

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

Plan holds planned file operations and their resolved outcomes.

func NewPlan

func NewPlan(interactive bool) *Plan

NewPlan creates a new empty file plan. Set interactive to true for animated progress (spinner, \r line overwrites) or false for CI / non-interactive environments.

func (*Plan) Add

func (p *Plan) Add(path string, content []byte, perm os.FileMode) *Plan

Add appends a file that will overwrite any existing file at the path.

func (*Plan) AddSkipExisting

func (p *Plan) AddSkipExisting(path string, content []byte, perm os.FileMode) *Plan

AddSkipExisting appends a file that will be skipped if it already exists.

func (*Plan) AddUpdate

func (p *Plan) AddUpdate(path string, content []byte, perm os.FileMode, message string) *Plan

AddUpdate appends a file that will be updated if it exists, or created if absent. The message is shown in preview to explain the update (e.g., "added io.metaplay.unitysdk reference").

func (*Plan) AddWithRename

func (p *Plan) AddWithRename(path, alternatePath string, content []byte, perm os.FileMode) *Plan

AddWithRename appends a file that will be written to alternatePath if the primary path already exists.

func (*Plan) AddZipExtraction

func (p *Plan) AddZipExtraction(zipPath, prefix, destDir string) *Plan

AddZipExtraction adds a zip archive to be extracted during Execute. Only entries whose name starts with prefix are extracted. Entries are written to destDir with their full zip path (the prefix is not stripped).

func (*Plan) Execute

func (p *Plan) Execute() error

Execute writes all planned files to disk and extracts any zip archives. On failure, the error includes details about which files were already written. Use Written() to retrieve the list of successfully written paths.

func (*Plan) FilesToWrite

func (p *Plan) FilesToWrite() int

FilesToWrite returns the number of files that will actually be written (excludes skipped files). Includes files from zip extractions.

func (*Plan) HasConflicts

func (p *Plan) HasConflicts() bool

HasConflicts returns true if any result has an action that represents a genuinely unexpected change: an overwrite or a rename. Routine actions (create, skip, update) are not considered conflicts.

func (*Plan) HasReadOnlyFiles

func (p *Plan) HasReadOnlyFiles() bool

HasReadOnlyFiles returns true if any writable target is read-only.

func (*Plan) Preview

func (p *Plan) Preview(collapseDirectories bool)

Preview logs a summary of the planned file operations. When collapseDirectories is true, directories containing only new files are collapsed into summary lines.

func (*Plan) Results

func (p *Plan) Results() []FileResult

Results returns the scan results. Panics if Scan has not been called.

func (*Plan) Scan

func (p *Plan) Scan() error

Scan inspects the filesystem and resolves the action for each planned file. For zip extractions, it counts the files to be extracted.

func (*Plan) SetConflictPolicy

func (p *Plan) SetConflictPolicy(policy ConflictPolicy, renameSuffix string)

SetConflictPolicy changes the conflict policy on all planned files. For Rename, AlternatePath is set to Path + renameSuffix. Resets scan state so Scan() must be called again.

func (*Plan) Written

func (p *Plan) Written() []string

Written returns the paths that were successfully written during Execute. Before a failure this is the partial list; on success it is all written paths.

type PlannedFile

type PlannedFile struct {
	Path          string         // Target path to write to.
	Content       []byte         // File content.
	Perm          os.FileMode    // Permission bits (0644, 0755, etc).
	OnConflict    ConflictPolicy // What to do if Path already exists.
	AlternatePath string         // Used when OnConflict is Rename. Written if Path exists.
	Message       string         // Optional message shown in preview (used by Update).
}

PlannedFile represents a single file to be written.

type ZipExtraction

type ZipExtraction struct {
	ZipPath string // Path to the zip file.
	Prefix  string // Only extract entries with this prefix (e.g., "MetaplaySDK/").
	DestDir string // Destination directory.
	// contains filtered or unexported fields
}

ZipExtraction describes a zip archive to be extracted during Execute.

Jump to

Keyboard shortcuts

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