1
0
mirror of https://github.com/go-task/task.git synced 2025-07-03 00:57:02 +02:00

fix: deep copying pointers inside slices (#1072)

This commit is contained in:
Pete Davison
2023-03-25 19:13:06 +00:00
committed by GitHub
parent d72eb009e4
commit cc1fd3d03e
7 changed files with 105 additions and 35 deletions

View File

@ -19,10 +19,21 @@ type Cmd struct {
Platforms []*Platform
}
// Dep is a task dependency
type Dep struct {
Task string
Vars *Vars
func (c *Cmd) DeepCopy() *Cmd {
if c == nil {
return nil
}
return &Cmd{
Cmd: c.Cmd,
Silent: c.Silent,
Task: c.Task,
Set: deepCopySlice(c.Set),
Shopt: deepCopySlice(c.Shopt),
Vars: c.Vars.DeepCopy(),
IgnoreError: c.IgnoreError,
Defer: c.Defer,
Platforms: deepCopySlice(c.Platforms),
}
}
func (c *Cmd) UnmarshalYAML(node *yaml.Node) error {
@ -94,30 +105,3 @@ func (c *Cmd) UnmarshalYAML(node *yaml.Node) error {
return fmt.Errorf("yaml: line %d: cannot unmarshal %s into command", node.Line, node.ShortTag())
}
func (d *Dep) UnmarshalYAML(node *yaml.Node) error {
switch node.Kind {
case yaml.ScalarNode:
var task string
if err := node.Decode(&task); err != nil {
return err
}
d.Task = task
return nil
case yaml.MappingNode:
var taskCall struct {
Task string
Vars *Vars
}
if err := node.Decode(&taskCall); err != nil {
return err
}
d.Task = taskCall.Task
d.Vars = taskCall.Vars
return nil
}
return fmt.Errorf("cannot unmarshal %s into dependency", node.ShortTag())
}