From b63def015068075d603a9ce19ed088316e577f28 Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Fri, 15 Sep 2023 17:59:35 +0200 Subject: [PATCH] fix CR: avoid mutating internal state --- arduino/builder/build_options_manager.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arduino/builder/build_options_manager.go b/arduino/builder/build_options_manager.go index 3079ecf9ea6..0d097bdb1e7 100644 --- a/arduino/builder/build_options_manager.go +++ b/arduino/builder/build_options_manager.go @@ -154,14 +154,16 @@ func (m *BuildOptionsManager) wipeBuildPath() error { return wipe() } + // Since we might apply a side effect we clone it + currentOptions := m.currentOptions.Clone() // If SketchLocation path is different but filename is the same, consider it equal - if filepath.Base(m.currentOptions.Get("sketchLocation")) == filepath.Base(prevOpts.Get("sketchLocation")) { - m.currentOptions.Remove("sketchLocation") + if filepath.Base(currentOptions.Get("sketchLocation")) == filepath.Base(prevOpts.Get("sketchLocation")) { + currentOptions.Remove("sketchLocation") prevOpts.Remove("sketchLocation") } // If options are not changed check if core has - if m.currentOptions.Equals(prevOpts) { + if currentOptions.Equals(prevOpts) { // check if any of the files contained in the core folders has changed // since the json was generated - like platform.txt or similar // if so, trigger a "safety" wipe