Documentation
¶
Overview ¶
onpatch: transactional file patching service with rollback support.
This package exposes:
- Session‑scoped file operations (Add, Delete, Move, Update)
- Diff generation (F‑04)
- Unified‑patch application (F‑03)
Key change in this revision ➜ **each mutating call now stores its own unique backup snapshot**, preventing the original‑overwrite bug when the same file is patched multiple times within a single session.
External deps (add to go.mod):
github.com/pmezard/go-difflib/difflib github.com/sourcegraph/go-diff/diff
Example:
s, _ := onpatch.NewSession()
_ = s.Update("foo.txt", []byte("v1\n"))
_ = s.Update("foo.txt", []byte("v2\n")) // second update gets its own backup
_ = s.Rollback() // restores original pre‑session content
Index ¶
- Constants
- Variables
- type Action
- type ApplyInput
- type ApplyOutput
- type DiffInput
- type DiffOutput
- type DiffResult
- type DiffStats
- type EmptyInput
- type EmptyOutput
- type Service
- type Session
- func (s *Session) Add(path string, data []byte) error
- func (s *Session) ApplyPatch(patchText string) error
- func (s *Session) Commit() error
- func (s *Session) Delete(path string) error
- func (s *Session) Move(src, dst string) error
- func (s *Session) Rollback() error
- func (s *Session) Update(path string, newData []byte) error
Constants ¶
const Name = "system/patch"
Name of the system/patch action service.
Variables ¶
var ErrNoChange = errors.New("no change between old and new")
Functions ¶
This section is empty.
Types ¶
type ApplyInput ¶
type ApplyInput struct {
// Patch must be in the *standard* unified-diff format as produced by
// tools such as `git diff` or `diff -u`.
// A valid payload therefore starts with file header lines, for example:
//
// --- a/path/to/file.txt
// +++ b/path/to/file.txt
// @@ -10,2 +10,3 @@
// -old line
// +new line
//
// and continues with the usual @@ hunk blocks. Multi-file patches are
// accepted as well. The service applies the patch relative to the
// current working directory of the Fluxor runtime.
Patch string `json:"patch" description:"Unified-diff text (---/+++ file headers with @@ hunk markers) to apply"`
}
ApplyInput is the payload for Service.apply
type ApplyOutput ¶
type ApplyOutput struct {
Stats DiffStats `json:"stats,omitempty"`
}
ApplyOutput summarises the changes applied.
type DiffInput ¶
type DiffInput struct {
OldContent string `json:"old" description:"Original file content"`
NewContent string `json:"new" description:"Updated file content"`
Path string `json:"path,omitempty" description:"Display path for diff headers"`
ContextLines int `json:"contextLines,omitempty" description:"Number of context lines to include in diff (default 3)"`
}
DiffInput is the payload for Service.diff
type DiffOutput ¶
type DiffOutput DiffResult
DiffOutput is identical to DiffResult, re-exported for JSON tags.
type DiffResult ¶
func GenerateDiff ¶
func GenerateDiff(old, new []byte, path string, contextLines int) (DiffResult, error)
type EmptyOutput ¶
type EmptyOutput struct{}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service exposes filesystem patching capabilities as a Fluxor action service. It is stateless – every method call operates with its own ephemeral Session.
func (*Service) Method ¶
func (s *Service) Method(name string) (types.Executable, error)
Method maps method names to executable handlers.
func (*Service) Methods ¶
func (s *Service) Methods() types.Signatures
Methods returns service method catalogue.
type Session ¶
type Session struct {
ID string
// contains filtered or unexported fields
}