file

package
v0.1.0-dev.20260223223859 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package file provides filesystem actions for the operation graph.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(reg *op.ActionRegistry)

Register registers all file actions with the given registry.

Types

type Backup

type Backup struct{ Impl *Provider }

Backup — Backup moves the file at path to a timestamped backup location. Returns the backup path and compensation state.

func (*Backup) Do

func (o *Backup) Do(ctx *op.Context, slots map[string]any) (op.Result, op.UndoState, error)

func (*Backup) Name

func (o *Backup) Name() string

func (*Backup) Undo

func (o *Backup) Undo(_ *op.Context, state op.UndoState) error

type Copy

type Copy struct{ Impl *Provider }

Copy — Copy writes content to path with the given mode. Returns the SHA256 checksum of the written content and compensation state.

func (*Copy) Do

func (o *Copy) Do(ctx *op.Context, slots map[string]any) (op.Result, op.UndoState, error)

func (*Copy) Name

func (o *Copy) Name() string

func (*Copy) Undo

func (o *Copy) Undo(_ *op.Context, state op.UndoState) error

type Exists

type Exists struct{ Impl *Provider }

Exists — Exists returns true if path exists on the filesystem.

func (*Exists) Do

func (o *Exists) Do(ctx *op.Context, slots map[string]any) (op.Result, op.UndoState, error)

func (*Exists) Name

func (o *Exists) Name() string

type IsDir

type IsDir struct{ Impl *Provider }

IsDir — IsDir returns true if path exists and is a directory.

func (*IsDir) Do

func (o *IsDir) Do(ctx *op.Context, slots map[string]any) (op.Result, op.UndoState, error)

func (*IsDir) Name

func (o *IsDir) Name() string
type Link struct{ Impl *Provider }

Link — Link creates a symlink at path pointing to source. Idempotent: if the symlink already points correctly, it's a no-op (returns nil state).

func (*Link) Do

func (o *Link) Do(ctx *op.Context, slots map[string]any) (op.Result, op.UndoState, error)

func (*Link) Name

func (o *Link) Name() string

func (*Link) Undo

func (o *Link) Undo(_ *op.Context, state op.UndoState) error

type Mkdir

type Mkdir struct{ Impl *Provider }

Mkdir — Mkdir creates a directory (and parents) with the given mode.

func (*Mkdir) Do

func (o *Mkdir) Do(ctx *op.Context, slots map[string]any) (op.Result, op.UndoState, error)

func (*Mkdir) Name

func (o *Mkdir) Name() string

type Move

type Move struct{ Impl *Provider }

Move — Move moves a file from source to path. Uses gitMv if provided (preserves git history), falling back to os.Rename. Returns compensation state with paths for reverse move.

func (*Move) Do

func (o *Move) Do(ctx *op.Context, slots map[string]any) (op.Result, op.UndoState, error)

func (*Move) Name

func (o *Move) Name() string

func (*Move) Undo

func (o *Move) Undo(_ *op.Context, state op.UndoState) error

type Provider

type Provider struct{}

Provider provides file system actions. Each method receives all inputs as parameters — no execution context, no node access.

Compensable Forward methods return (string, map[string]any, error): the resource path, the compensation receipt, and an error. The map is opaque to the executor, meaningful only to the corresponding Compensate* Backward method.

func (*Provider) Backup

func (p *Provider) Backup(path, backupSuffix string) (result string, state map[string]any, retErr error)

Backup moves the file at path to a timestamped backup location. Returns the backup path and compensation state.

Parameters:

  • path: Absolute path to the file to back up
  • backupSuffix: Suffix appended before the timestamp (default: .writ-backup)

+devlore:access=planned

func (*Provider) CompensateBackup

func (p *Provider) CompensateBackup(state any) error

CompensateBackup undoes a Backup by moving the backup back to the original path.

func (*Provider) CompensateCopy

func (p *Provider) CompensateCopy(state any) error

CompensateCopy undoes a Copy action using the captured state.

func (p *Provider) CompensateLink(state any) error

CompensateLink undoes a Link action using the captured state.

func (*Provider) CompensateMove

func (p *Provider) CompensateMove(state any) error

CompensateMove undoes a Move by moving the file back from path to source.

func (*Provider) CompensateRemove

func (p *Provider) CompensateRemove(state any) error

CompensateRemove undoes a Remove by re-creating the file with saved content and mode.

func (p *Provider) CompensateUnlink(state any) error

CompensateUnlink undoes an Unlink by re-creating the symlink.

func (*Provider) CompensateWrite

func (p *Provider) CompensateWrite(state any) error

CompensateWrite undoes a Write action using the captured state.

func (*Provider) Copy

func (p *Provider) Copy(path string, mode os.FileMode, content []byte) (checksum string, state map[string]any, retErr error)

Copy writes content to path with the given mode. Returns the SHA256 checksum of the written content and compensation state.

Parameters:

  • path: Absolute path where the file will be written
  • mode: File permission bits (e.g., 0o644)

+devlore:access=planned

func (*Provider) Exists

func (p *Provider) Exists(path string) (bool, error)

Exists returns true if path exists on the filesystem.

Parameters:

  • path: Absolute path to check

+devlore:access=both

func (*Provider) IsDir

func (p *Provider) IsDir(path string) (bool, error)

IsDir returns true if path exists and is a directory.

Parameters:

  • path: Absolute path to check

+devlore:access=both

func (p *Provider) Link(source, path string) (result string, state map[string]any, retErr error)

Link creates a symlink at path pointing to source. Idempotent: if the symlink already points correctly, it's a no-op (returns nil state).

Parameters:

  • source: Absolute path to the symlink target
  • path: Absolute path where the symlink will be created

+devlore:access=planned

func (*Provider) Mkdir

func (p *Provider) Mkdir(path string, mode os.FileMode) (string, error)

Mkdir creates a directory (and parents) with the given mode.

Parameters:

  • path: Absolute path of the directory to create
  • mode: Directory permission bits (e.g., 0o755)

+devlore:access=planned

func (*Provider) Move

func (p *Provider) Move(gitMv func(src, dst string) error, source, path string) (result string, compState map[string]any, retErr error)

Move moves a file from source to path. Uses gitMv if provided (preserves git history), falling back to os.Rename. Returns compensation state with paths for reverse move.

Parameters:

  • source: Absolute path to the file to move
  • path: Absolute destination path

+devlore:access=planned

func (*Provider) Remove

func (p *Provider) Remove(path string, prune bool, pruneBoundary string) (result string, compState map[string]any, retErr error)

Remove deletes the file at path. If prune is true and pruneBoundary is set, empty parent directories are removed up to the boundary. Returns compensation state with file content for re-creation.

Parameters:

  • path: Absolute path to the file to delete
  • prune: If true, remove empty parent directories after deletion
  • pruneBoundary: Stop pruning at this directory (prevents removing too much)

+devlore:access=planned

func (*Provider) Source

func (p *Provider) Source(path string) ([]byte, error)

Source reads a file and returns its contents.

Parameters:

  • path: Absolute path to the file to read

+devlore:access=planned

func (p *Provider) Unlink(path string, prune bool, pruneBoundary string) (result string, compState map[string]any, retErr error)

Unlink removes a symlink at path. If prune is true and pruneBoundary is set, empty parent directories are removed up to the boundary. Returns compensation state with the symlink target for re-creation.

Parameters:

  • path: Absolute path to the symlink to remove
  • prune: If true, remove empty parent directories after unlinking
  • pruneBoundary: Stop pruning at this directory (prevents removing too much)

+devlore:access=planned

func (*Provider) Write

func (p *Provider) Write(content, path string, mode os.FileMode) (result string, compState map[string]any, retErr error)

Write writes inline content to path with the given mode. Returns compensation state for undo.

Parameters:

  • content: String content to write to the file
  • path: Absolute path where the file will be written
  • mode: File permission bits (e.g., 0o644)

+devlore:access=planned

type Remove

type Remove struct{ Impl *Provider }

Remove — Remove deletes the file at path. If prune is true and pruneBoundary is set, empty parent directories are removed up to the boundary. Returns compensation state with file content for re-creation.

func (*Remove) Do

func (o *Remove) Do(ctx *op.Context, slots map[string]any) (op.Result, op.UndoState, error)

func (*Remove) Name

func (o *Remove) Name() string

func (*Remove) Undo

func (o *Remove) Undo(_ *op.Context, state op.UndoState) error

type Source

type Source struct{ Impl *Provider }

Source — Source reads a file and returns its contents.

func (*Source) Do

func (o *Source) Do(ctx *op.Context, slots map[string]any) (op.Result, op.UndoState, error)

func (*Source) Name

func (o *Source) Name() string
type Unlink struct{ Impl *Provider }

Unlink — Unlink removes a symlink at path. If prune is true and pruneBoundary is set, empty parent directories are removed up to the boundary. Returns compensation state with the symlink target for re-creation.

func (*Unlink) Do

func (o *Unlink) Do(ctx *op.Context, slots map[string]any) (op.Result, op.UndoState, error)

func (*Unlink) Name

func (o *Unlink) Name() string

func (*Unlink) Undo

func (o *Unlink) Undo(_ *op.Context, state op.UndoState) error

type Write

type Write struct{ Impl *Provider }

Write — Write writes inline content to path with the given mode. Returns compensation state for undo.

func (*Write) Do

func (o *Write) Do(ctx *op.Context, slots map[string]any) (op.Result, op.UndoState, error)

func (*Write) Name

func (o *Write) Name() string

func (*Write) Undo

func (o *Write) Undo(_ *op.Context, state op.UndoState) error

Jump to

Keyboard shortcuts

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