-
Notifications
You must be signed in to change notification settings - Fork 203
/
raw_export_base.go
65 lines (52 loc) · 1.99 KB
/
raw_export_base.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package config
import (
"context"
"path/filepath"
"strings"
"github.com/werf/logboek"
)
type rawExportBase struct {
Add string `yaml:"add,omitempty"`
To string `yaml:"to,omitempty"`
IncludePaths interface{} `yaml:"includePaths,omitempty"`
ExcludePaths interface{} `yaml:"excludePaths,omitempty"`
Owner string `yaml:"owner,omitempty"`
Group string `yaml:"group,omitempty"`
rawOrigin rawOrigin `yaml:"-"` // parent
}
func (c *rawExportBase) inlinedIntoRaw(rawOrigin rawOrigin) {
c.rawOrigin = rawOrigin
}
func (c *rawExportBase) toDirective() (exportBase *ExportBase, err error) {
exportBase = &ExportBase{}
exportBase.Add = filepath.ToSlash(filepath.Clean(c.Add))
if strings.HasSuffix(c.To, "/") && c.To != "/" {
toWithoutTrailingSlash := strings.TrimSuffix(c.To, "/")
logboek.Context(context.Background()).Warn().LogF(
"WARNING: `to: %s` will be treated like `to: %s`, i.e. file/directory from `add: %s` will NOT be copied inside of the %q, instead it will be copied as %q! To hide this warning, change `to: %s` to `to: %s`.\n",
c.To, toWithoutTrailingSlash, c.Add, c.To, toWithoutTrailingSlash, c.To, toWithoutTrailingSlash,
)
}
exportBase.To = filepath.ToSlash(filepath.Clean(c.To))
if includePaths, err := InterfaceToStringArray(c.IncludePaths, c.rawOrigin.configSection(), c.rawOrigin.doc()); err != nil {
return nil, err
} else {
for _, p := range includePaths {
exportBase.IncludePaths = append(exportBase.IncludePaths, filepath.ToSlash(filepath.Clean(p)))
}
}
if excludePaths, err := InterfaceToStringArray(c.ExcludePaths, c.rawOrigin.configSection(), c.rawOrigin.doc()); err != nil {
return nil, err
} else {
for _, p := range excludePaths {
exportBase.ExcludePaths = append(exportBase.ExcludePaths, filepath.ToSlash(filepath.Clean(p)))
}
}
exportBase.Owner = c.Owner
exportBase.Group = c.Group
exportBase.raw = c
if err := exportBase.validate(); err != nil {
return nil, err
}
return exportBase, nil
}