mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 10:30:59 +00:00
Merge pull request #4087 from campoy/fsnode-alias-fix
Avoid aliasing in fsnode by forcing copies for file contents
This commit is contained in:
@@ -123,11 +123,11 @@ func (n *fsNode) addFile(name string, c []byte) (result *fsNode, err error) {
|
|||||||
if result.offset != nil {
|
if result.offset != nil {
|
||||||
return nil, fmt.Errorf("cannot add already opened file '%s'", n.Path())
|
return nil, fmt.Errorf("cannot add already opened file '%s'", n.Path())
|
||||||
}
|
}
|
||||||
result.content = c
|
result.content = append(result.content[:0], c...)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
result = &fsNode{
|
result = &fsNode{
|
||||||
content: c,
|
content: append([]byte(nil), c...),
|
||||||
parent: parent,
|
parent: parent,
|
||||||
}
|
}
|
||||||
parent.dir[fileName] = result
|
parent.dir[fileName] = result
|
||||||
|
|||||||
@@ -157,9 +157,13 @@ func runBasicOperations(
|
|||||||
if string(stuff) != both {
|
if string(stuff) != both {
|
||||||
t.Fatalf("%s; unexpected content '%s', expected '%s'", c.what, stuff, both)
|
t.Fatalf("%s; unexpected content '%s', expected '%s'", c.what, stuff, both)
|
||||||
}
|
}
|
||||||
if err := fSys.WriteFile(c.path, []byte(shortContent)); err != nil {
|
|
||||||
|
content := []byte(shortContent)
|
||||||
|
if err := fSys.WriteFile(c.path, content); err != nil {
|
||||||
t.Fatalf("%s; unexpected error: %v", c.what, err)
|
t.Fatalf("%s; unexpected error: %v", c.what, err)
|
||||||
}
|
}
|
||||||
|
// This ensures that modifying the original slice does not change the contents of the file.
|
||||||
|
content[0] = '@'
|
||||||
stuff, err = fSys.ReadFile(c.path)
|
stuff, err = fSys.ReadFile(c.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s; unexpected error: %v", c.what, err)
|
t.Fatalf("%s; unexpected error: %v", c.what, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user