Skip to content

Commit 0329b1c

Browse files
author
Federico Fissore
committed
Writing additional sketch files to target folder ONLY if they changed.
Fixes #77 Signed-off-by: Federico Fissore <[email protected]>
1 parent 892ebf9 commit 0329b1c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Diff for: src/arduino.cc/builder/additional_sketch_files_copier.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"arduino.cc/builder/constants"
3434
"arduino.cc/builder/types"
3535
"arduino.cc/builder/utils"
36+
"bytes"
3637
"io/ioutil"
3738
"path/filepath"
3839
)
@@ -67,8 +68,22 @@ func (s *AdditionalSketchFilesCopier) Run(context map[string]interface{}) error
6768
return utils.WrapError(err)
6869
}
6970

70-
utils.WriteFileBytes(targetFilePath, bytes)
71+
if targetFileChanged(bytes, targetFilePath) {
72+
err := utils.WriteFileBytes(targetFilePath, bytes)
73+
if err != nil {
74+
return utils.WrapError(err)
75+
}
76+
}
7177
}
7278

7379
return nil
7480
}
81+
82+
func targetFileChanged(currentBytes []byte, targetFilePath string) bool {
83+
oldBytes, err := ioutil.ReadFile(targetFilePath)
84+
if err != nil {
85+
return true
86+
}
87+
88+
return bytes.Compare(currentBytes, oldBytes) != 0
89+
}

0 commit comments

Comments
 (0)