aboutsummaryrefslogtreecommitdiff
path: root/internal/plan/step.go
blob: c613ce5c2b6c6077a1758e2bd8177642d95f54e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: GPL-3.0-or-later

package plan

import (
	"fmt"

	"git.labunix.xyz/krino/internal/config"
	"git.labunix.xyz/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; the 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
}