Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 13fa7de

Browse files
committedJan 15, 2021
slightly refactored directoryContainsFile function
1 parent 39a1b2b commit 13fa7de

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed
 

‎legacy/builder/phases/libraries_builder.go

+7-11
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,12 @@ func (s *LibrariesBuilder) Run(ctx *types.Context) error {
5353
return nil
5454
}
5555

56-
func containsFile(folder *paths.Path) bool {
57-
res, _ := folder.ReadDir()
58-
hasfiles := false
59-
for _, el := range res {
60-
if !el.IsDir() {
61-
hasfiles = true
62-
break
63-
}
56+
func directoryContainsFile(folder *paths.Path) bool {
57+
if files, err := folder.ReadDir(); err == nil {
58+
files.FilterOutDirs()
59+
return len(files) > 0
6460
}
65-
return hasfiles
61+
return false
6662
}
6763

6864
func findExpectedPrecompiledLibFolder(ctx *types.Context, library *libraries.Library) *paths.Path {
@@ -98,15 +94,15 @@ func findExpectedPrecompiledLibFolder(ctx *types.Context, library *libraries.Lib
9894
if len(fpuSpecs) > 0 {
9995
fpuSpecs = strings.TrimRight(fpuSpecs, "-")
10096
fullPrecompDir := library.SourceDir.Join(mcu).Join(fpuSpecs)
101-
if fullPrecompDir.Exist() && containsFile(fullPrecompDir) {
97+
if fullPrecompDir.Exist() && directoryContainsFile(fullPrecompDir) {
10298
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_INFO, "Using precompiled library in {0}", fullPrecompDir)
10399
return fullPrecompDir
104100
}
105101
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_INFO, "Precompiled library in \"{0}\" not found", fullPrecompDir)
106102
}
107103

108104
precompDir := library.SourceDir.Join(mcu)
109-
if precompDir.Exist() && containsFile(precompDir) {
105+
if precompDir.Exist() && directoryContainsFile(precompDir) {
110106
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_INFO, "Using precompiled library in {0}", precompDir)
111107
return precompDir
112108
}

0 commit comments

Comments
 (0)
Please sign in to comment.