/
auxi.go
47 lines (35 loc) · 1.18 KB
/
auxi.go
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
package action
// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2021 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
import (
"path/filepath"
"strings"
"github.com/essentialkaos/bibop/recipe"
)
// ////////////////////////////////////////////////////////////////////////////////// //
// checkPathSafety return true if path is save
func checkPathSafety(r *recipe.Recipe, path string) (bool, error) {
if r.UnsafeActions {
return true, nil
}
targetPath, err := filepath.Abs(path)
if err != nil {
return false, err
}
workingDir, err := filepath.Abs(r.Dir)
if err != nil {
return false, err
}
return strings.HasPrefix(targetPath, workingDir), nil
}
// fmtValue formats value
func fmtValue(v string) string {
if v == "" {
return `""`
}
return v
}