Skip to content

Commit d44f411

Browse files
author
Federico Fissore
committed
Ignoring all files that start with a dot. Fixes #82
Signed-off-by: Federico Fissore <[email protected]>
1 parent b875fc2 commit d44f411

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ func (s *CollectAllSourceFilesFromFoldersWithSources) Run(context map[string]int
6868
}
6969

7070
func collectByWalk(filePaths *[]string, folder string) error {
71-
checkExtensionFunc := func(ext string) bool {
72-
return ADDITIONAL_FILE_VALID_EXTENSIONS_NO_HEADERS[ext]
71+
checkExtensionFunc := func(filePath string) bool {
72+
name := filepath.Base(filePath)
73+
ext := strings.ToLower(filepath.Ext(filePath))
74+
return !strings.HasPrefix(name, ".") && ADDITIONAL_FILE_VALID_EXTENSIONS_NO_HEADERS[ext]
7375
}
7476
walkFunc := utils.CollectAllReadableFiles(filePaths, checkExtensionFunc)
7577
err := gohasissues.Walk(folder, walkFunc)

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ func (s *SketchLoader) Run(context map[string]interface{}) error {
8787

8888
func collectAllSketchFiles(from string) ([]string, error) {
8989
filePaths := []string{}
90-
checkExtensionFunc := func(ext string) bool {
91-
return MAIN_FILE_VALID_EXTENSIONS[ext] || ADDITIONAL_FILE_VALID_EXTENSIONS[ext]
90+
checkExtensionFunc := func(filePath string) bool {
91+
name := filepath.Base(filePath)
92+
ext := strings.ToLower(filepath.Ext(filePath))
93+
return !strings.HasPrefix(name, ".") && MAIN_FILE_VALID_EXTENSIONS[ext] || ADDITIONAL_FILE_VALID_EXTENSIONS[ext]
9294
}
9395
walkFunc := utils.CollectAllReadableFiles(&filePaths, checkExtensionFunc)
9496
err := gohasissues.Walk(from, walkFunc)

Diff for: src/arduino.cc/builder/test/sketch_loader_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,26 @@ func TestLoadSketchWithBackup(t *testing.T) {
165165
require.Equal(t, 0, len(sketch.AdditionalFiles))
166166
require.Equal(t, 0, len(sketch.OtherSketchFiles))
167167
}
168+
169+
func TestLoadSketchWithMacOSXGarbage(t *testing.T) {
170+
context := make(map[string]interface{})
171+
context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_with_macosx_garbage", "sketch.ino")
172+
173+
commands := []types.Command{
174+
&builder.SetupHumanLoggerIfMissing{},
175+
&builder.SketchLoader{},
176+
}
177+
178+
for _, command := range commands {
179+
err := command.Run(context)
180+
NoError(t, err)
181+
}
182+
183+
sketch := context[constants.CTX_SKETCH].(*types.Sketch)
184+
require.NotNil(t, sketch)
185+
186+
require.Contains(t, sketch.MainFile.Name, "sketch.ino")
187+
188+
require.Equal(t, 0, len(sketch.AdditionalFiles))
189+
require.Equal(t, 0, len(sketch.OtherSketchFiles))
190+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup()
2+
void loop) }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() {}
2+
void loop() {}

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,9 @@ func FilterOutFoldersByNames(folders []os.FileInfo, names ...string) []os.FileIn
384384
return filtered
385385
}
386386

387-
type CheckFileExtensionFunc func(ext string) bool
387+
type CheckFilePathFunc func(filePath string) bool
388388

389-
func CollectAllReadableFiles(collector *[]string, test CheckFileExtensionFunc) filepath.WalkFunc {
389+
func CollectAllReadableFiles(collector *[]string, test CheckFilePathFunc) filepath.WalkFunc {
390390
walkFunc := func(currentPath string, info os.FileInfo, err error) error {
391391
if err != nil {
392392
return err
@@ -395,8 +395,7 @@ func CollectAllReadableFiles(collector *[]string, test CheckFileExtensionFunc) f
395395
if info.IsDir() {
396396
return nil
397397
}
398-
ext := strings.ToLower(filepath.Ext(currentPath))
399-
if !test(ext) {
398+
if !test(currentPath) {
400399
return nil
401400
}
402401
currentFile, err := os.Open(currentPath)

0 commit comments

Comments
 (0)