diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 23:45:23 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 23:45:23 +0200 |
| commit | 97c8164bc81e0a438dab92d7244485005dac4ff2 (patch) | |
| tree | 08d657f8b92a6539259b6aa8f08b0e9ef8cc6710 /internal/plan/chain.go | |
| parent | 166565025832c8a8faf7397766aeaa878980dd2d (diff) | |
| download | krino-97c8164bc81e0a438dab92d7244485005dac4ff2.tar.gz krino-97c8164bc81e0a438dab92d7244485005dac4ff2.zip | |
literal braces are text, not placeholders, for containment and walk exclusion
Diffstat (limited to 'internal/plan/chain.go')
| -rw-r--r-- | internal/plan/chain.go | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/internal/plan/chain.go b/internal/plan/chain.go index 793e0e1..b32cc7d 100644 --- a/internal/plan/chain.go +++ b/internal/plan/chain.go @@ -233,8 +233,8 @@ func expandDir(raw string, facts Facts, root string) (string, error) { return "", err } resolved := ResolveDir(expanded, root) - if strings.ContainsRune(raw, '{') { - if base := staticDir(raw, root); !within(resolved, base) { + if prefix, templated := StaticPrefix(raw); templated { + if base := staticDir(prefix, root); !within(resolved, base) { return "", fmt.Errorf("destination %q leaves %s through a placeholder", expanded, xdg.Abbrev(base)) } } @@ -242,15 +242,11 @@ func expandDir(raw string, facts Facts, root string) (string, error) { } // staticDir is the directory a destination names before its first -// placeholder: its last complete path segment, resolved like any -// destination. "Work/Acme/{mtime:%Y}" is root/Work/Acme, "Work/Ac{1}" is -// root/Work, "{1}/x" is root itself, "~/{1}" is the home directory and -// "/{1}" is "/". -func staticDir(raw, root string) string { - prefix := raw - if i := strings.IndexByte(raw, '{'); i >= 0 { - prefix = raw[:i] - } +// placeholder, given that text (StaticPrefix): its last complete path +// segment, resolved like any destination. "Work/Acme/{mtime:%Y}" is +// root/Work/Acme, "Work/Ac{1}" is root/Work, "{1}/x" is root itself, "~/{1}" +// is the home directory and "/{1}" is "/". +func staticDir(prefix, root string) string { switch i := strings.LastIndexByte(prefix, '/'); { case i < 0: prefix = "" |
