aboutsummaryrefslogtreecommitdiff
path: root/internal/plan/chain.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/plan/chain.go')
-rw-r--r--internal/plan/chain.go18
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 = ""