Skip to content

Commit

Permalink
Ignoring all files that start with a dot. Fixes #82
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Fissore <[email protected]>
  • Loading branch information
Federico Fissore committed Dec 11, 2015
1 parent b875fc2 commit d44f411
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ func (s *CollectAllSourceFilesFromFoldersWithSources) Run(context map[string]int
}

func collectByWalk(filePaths *[]string, folder string) error {
checkExtensionFunc := func(ext string) bool {
return ADDITIONAL_FILE_VALID_EXTENSIONS_NO_HEADERS[ext]
checkExtensionFunc := func(filePath string) bool {
name := filepath.Base(filePath)
ext := strings.ToLower(filepath.Ext(filePath))
return !strings.HasPrefix(name, ".") && ADDITIONAL_FILE_VALID_EXTENSIONS_NO_HEADERS[ext]
}
walkFunc := utils.CollectAllReadableFiles(filePaths, checkExtensionFunc)
err := gohasissues.Walk(folder, walkFunc)
Expand Down
6 changes: 4 additions & 2 deletions src/arduino.cc/builder/sketch_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ func (s *SketchLoader) Run(context map[string]interface{}) error {

func collectAllSketchFiles(from string) ([]string, error) {
filePaths := []string{}
checkExtensionFunc := func(ext string) bool {
return MAIN_FILE_VALID_EXTENSIONS[ext] || ADDITIONAL_FILE_VALID_EXTENSIONS[ext]
checkExtensionFunc := func(filePath string) bool {
name := filepath.Base(filePath)
ext := strings.ToLower(filepath.Ext(filePath))
return !strings.HasPrefix(name, ".") && MAIN_FILE_VALID_EXTENSIONS[ext] || ADDITIONAL_FILE_VALID_EXTENSIONS[ext]
}
walkFunc := utils.CollectAllReadableFiles(&filePaths, checkExtensionFunc)
err := gohasissues.Walk(from, walkFunc)
Expand Down
23 changes: 23 additions & 0 deletions src/arduino.cc/builder/test/sketch_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,26 @@ func TestLoadSketchWithBackup(t *testing.T) {
require.Equal(t, 0, len(sketch.AdditionalFiles))
require.Equal(t, 0, len(sketch.OtherSketchFiles))
}

func TestLoadSketchWithMacOSXGarbage(t *testing.T) {
context := make(map[string]interface{})
context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_with_macosx_garbage", "sketch.ino")

commands := []types.Command{
&builder.SetupHumanLoggerIfMissing{},
&builder.SketchLoader{},
}

for _, command := range commands {
err := command.Run(context)
NoError(t, err)
}

sketch := context[constants.CTX_SKETCH].(*types.Sketch)
require.NotNil(t, sketch)

require.Contains(t, sketch.MainFile.Name, "sketch.ino")

require.Equal(t, 0, len(sketch.AdditionalFiles))
require.Equal(t, 0, len(sketch.OtherSketchFiles))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
void setup()
void loop) }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
void setup() {}
void loop() {}
7 changes: 3 additions & 4 deletions src/arduino.cc/builder/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,9 @@ func FilterOutFoldersByNames(folders []os.FileInfo, names ...string) []os.FileIn
return filtered
}

type CheckFileExtensionFunc func(ext string) bool
type CheckFilePathFunc func(filePath string) bool

func CollectAllReadableFiles(collector *[]string, test CheckFileExtensionFunc) filepath.WalkFunc {
func CollectAllReadableFiles(collector *[]string, test CheckFilePathFunc) filepath.WalkFunc {
walkFunc := func(currentPath string, info os.FileInfo, err error) error {
if err != nil {
return err
Expand All @@ -395,8 +395,7 @@ func CollectAllReadableFiles(collector *[]string, test CheckFileExtensionFunc) f
if info.IsDir() {
return nil
}
ext := strings.ToLower(filepath.Ext(currentPath))
if !test(ext) {
if !test(currentPath) {
return nil
}
currentFile, err := os.Open(currentPath)
Expand Down

0 comments on commit d44f411

Please sign in to comment.