From 24a84671ace373ae331fa83a1ff484990f4dff0e Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Sat, 12 Sep 2026 12:58:14 +0200 Subject: krino: planning — chains, placeholders, conflicts, JSON MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/plan/step.go | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 internal/plan/step.go (limited to 'internal/plan/step.go') diff --git a/internal/plan/step.go b/internal/plan/step.go new file mode 100644 index 0000000..e4f280f --- /dev/null +++ b/internal/plan/step.go @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package plan + +import ( + "fmt" + + "krino/internal/config" + "krino/internal/scan" +) + +// Kind is what a step does. +type Kind int + +const ( + Copy Kind = iota + Move + Rename + Trash // (delete) + DeletePermanent // (delete permanent) +) + +// String is for display only; Task 5's JSON representation defines its own +// action names. +func (k Kind) String() string { + switch k { + case Copy: + return "copy" + case Move: + return "move" + case Rename: + return "rename" + case Trash: + return "trash" + case DeletePermanent: + return "DELETE permanently" + } + return fmt.Sprintf("Kind(%d)", int(k)) +} + +// Step is one action to carry out, already resolved to absolute paths. +type Step struct { + Kind Kind + Rule string // the rule that contributed it + Src string // absolute path the step reads from + Dst string // absolute path the file has after the step; "" for the two deletes + Reason string // the rule's match reasons, for display + Skip string // non-empty: this step will not run, and why + Conflict config.Conflict // the contributing rule's on-conflict policy + Displaces string // overwrite only: the existing file that must be trashed first +} + +// Chain is one file's steps, in order. +type Chain struct { + File scan.File + Steps []Step + Warnings []string +} + +// RuleMatch is one matching rule's contribution to a file's chain. +// internal/plan must not import internal/engine (engine imports plan), so +// the engine converts its own types into these. +type RuleMatch struct { + Name string + Actions []config.Action + Settings config.Resolved + Captures []string + Reasons []string +} -- cgit v1.3