From 3a8fd215de94d6f417ef7e4517f3fe644d07e3b4 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sat, 24 Aug 2019 13:32:33 -0400 Subject: [PATCH] engine: resources: file: Add Copy method to file res This lets us implement the CopyableRes interface. --- engine/resources/file.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/engine/resources/file.go b/engine/resources/file.go index 6c323bd0..b8a0353a 100644 --- a/engine/resources/file.go +++ b/engine/resources/file.go @@ -1023,6 +1023,29 @@ func (obj *FileRes) UnmarshalYAML(unmarshal func(interface{}) error) error { 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. func smartPath(fileInfo os.FileInfo) string { smartPath := fileInfo.Name() // absolute path