engine: resources: file: Add Copy method to file res

This lets us implement the CopyableRes interface.
This commit is contained in:
James Shubin
2019-08-24 13:32:33 -04:00
parent 87572e8922
commit 3a8fd215de

View File

@@ -1023,6 +1023,29 @@ func (obj *FileRes) UnmarshalYAML(unmarshal func(interface{}) error) error {
return nil return nil
} }
// Copy copies the resource. Don't call it directly, use engine.ResCopy instead.
// TODO: should this copy internal state?
func (obj *FileRes) Copy() engine.CopyableRes {
var content *string
if obj.Content != nil { // copy the string contents, not the pointer...
s := *obj.Content
content = &s
}
return &FileRes{
Path: obj.Path,
Dirname: obj.Dirname,
Basename: obj.Basename,
Content: content,
Source: obj.Source,
State: obj.State,
Owner: obj.Owner,
Group: obj.Group,
Mode: obj.Mode,
Recurse: obj.Recurse,
Force: obj.Force,
}
}
// smartPath adds a trailing slash to the path if it is a directory. // smartPath adds a trailing slash to the path if it is a directory.
func smartPath(fileInfo os.FileInfo) string { func smartPath(fileInfo os.FileInfo) string {
smartPath := fileInfo.Name() // absolute path smartPath := fileInfo.Name() // absolute path