state: do not overwrite values.yaml if nothing has changed
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
155c90e3e0
commit
322ca54e58
@ -1,6 +1,7 @@
|
|||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -167,12 +168,24 @@ func (w *Workspace) Save(ctx context.Context, st *State) error {
|
|||||||
|
|
||||||
manifestPath := path.Join(st.Path, manifestFile)
|
manifestPath := path.Join(st.Path, manifestFile)
|
||||||
|
|
||||||
encrypted, err := keychain.Reencrypt(ctx, manifestPath, data)
|
currentEncrypted, err := os.ReadFile(manifestPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := os.WriteFile(manifestPath, encrypted, 0600); err != nil {
|
currentPlain, err := keychain.Decrypt(ctx, currentEncrypted)
|
||||||
return err
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to decrypt state: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only update the encrypted file if there were changes
|
||||||
|
if bytes.Compare(data, currentPlain) != 0 {
|
||||||
|
encrypted, err := keychain.Reencrypt(ctx, manifestPath, data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(manifestPath, encrypted, 0600); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if st.Computed != "" {
|
if st.Computed != "" {
|
||||||
|
Reference in New Issue
Block a user