Skip to content

Commit aaafa1e

Browse files
committed
Do not fail if a non-sketch file is a broken symlink
1 parent 23fc5d7 commit aaafa1e

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed

Diff for: internal/arduino/sketch/sketch.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/hex"
2121
"errors"
2222
"fmt"
23+
"io/fs"
2324
"sort"
2425
"strings"
2526

@@ -169,8 +170,26 @@ func (s *Sketch) supportedFiles() (paths.PathList, error) {
169170
return !p.Join("build.options.json").Exist()
170171
}
171172

173+
filterOutBrokenLinks := func(p *paths.Path) (res bool) {
174+
if stat, err := p.LStat(); err != nil {
175+
return false
176+
} else if stat.Mode()&fs.ModeSymlink != fs.ModeSymlink {
177+
// not a symlink, accept
178+
return true
179+
} else if target := p.Clone(); target.FollowSymLink() != nil {
180+
// failed to follow symlink -> do not accept
181+
return false
182+
} else {
183+
// accept only valid symlinks
184+
return target.Exist()
185+
}
186+
}
187+
172188
files, err := s.FullPath.ReadDirRecursiveFiltered(
173-
filterOutBuildPaths,
189+
paths.AndFilter(
190+
filterOutBrokenLinks,
191+
filterOutBuildPaths,
192+
),
174193
paths.AndFilter(
175194
paths.FilterOutPrefixes("."),
176195
filterValidExtensions,
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2023 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package compile_test
17+
18+
import (
19+
"testing"
20+
21+
"github.com/arduino/arduino-cli/internal/integrationtest"
22+
"github.com/arduino/go-paths-helper"
23+
"github.com/stretchr/testify/require"
24+
)
25+
26+
func TestCompileWithBrokenSymLinks(t *testing.T) {
27+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
28+
t.Cleanup(env.CleanUp)
29+
30+
// Install Arduino AVR Boards
31+
_, _, err := cli.Run("core", "install", "arduino:[email protected]")
32+
require.NoError(t, err)
33+
34+
t.Run("NonSketchFileBroken", func(t *testing.T) {
35+
sketch, err := paths.New("testdata", "ValidSketchWithBrokenSymlink").Abs()
36+
require.NoError(t, err)
37+
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", sketch.String())
38+
require.NoError(t, err)
39+
})
40+
}
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 @@
1+
broken
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
broken

0 commit comments

Comments
 (0)