diff --git a/.licenses/arduino-lint/go/github.com/arduino/go-paths-helper.dep.yml b/.licenses/arduino-lint/go/github.com/arduino/go-paths-helper.dep.yml index e5ea4290..1de189b7 100644 --- a/.licenses/arduino-lint/go/github.com/arduino/go-paths-helper.dep.yml +++ b/.licenses/arduino-lint/go/github.com/arduino/go-paths-helper.dep.yml @@ -1,6 +1,6 @@ --- name: github.com/arduino/go-paths-helper -version: v1.11.0 +version: v1.12.0 type: go summary: homepage: https://pkg.go.dev/github.com/arduino/go-paths-helper diff --git a/.licenses/docsgen/go/github.com/arduino/go-paths-helper.dep.yml b/.licenses/docsgen/go/github.com/arduino/go-paths-helper.dep.yml index e5ea4290..1de189b7 100644 --- a/.licenses/docsgen/go/github.com/arduino/go-paths-helper.dep.yml +++ b/.licenses/docsgen/go/github.com/arduino/go-paths-helper.dep.yml @@ -1,6 +1,6 @@ --- name: github.com/arduino/go-paths-helper -version: v1.11.0 +version: v1.12.0 type: go summary: homepage: https://pkg.go.dev/github.com/arduino/go-paths-helper diff --git a/.licenses/ruledocsgen/go/github.com/arduino/go-paths-helper.dep.yml b/.licenses/ruledocsgen/go/github.com/arduino/go-paths-helper.dep.yml index e5ea4290..1de189b7 100644 --- a/.licenses/ruledocsgen/go/github.com/arduino/go-paths-helper.dep.yml +++ b/.licenses/ruledocsgen/go/github.com/arduino/go-paths-helper.dep.yml @@ -1,6 +1,6 @@ --- name: github.com/arduino/go-paths-helper -version: v1.11.0 +version: v1.12.0 type: go summary: homepage: https://pkg.go.dev/github.com/arduino/go-paths-helper diff --git a/docsgen/go.mod b/docsgen/go.mod index 5b03c743..f3340b5c 100644 --- a/docsgen/go.mod +++ b/docsgen/go.mod @@ -19,7 +19,7 @@ require ( github.com/ProtonMail/go-crypto v0.0.0-20230518184743-7afd39499903 // indirect github.com/acomagu/bufpipe v1.0.4 // indirect github.com/arduino/arduino-cli v0.0.0-20201210103408-bf7a3194bb63 // indirect - github.com/arduino/go-paths-helper v1.11.0 // indirect + github.com/arduino/go-paths-helper v1.12.0 // indirect github.com/arduino/go-properties-orderedmap v1.8.0 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/client9/misspell v0.3.4 // indirect diff --git a/docsgen/go.sum b/docsgen/go.sum index b6347a98..1ff8d9fe 100644 --- a/docsgen/go.sum +++ b/docsgen/go.sum @@ -60,8 +60,8 @@ github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c/go.mod h1: github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= github.com/arduino/go-paths-helper v1.2.0/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= github.com/arduino/go-paths-helper v1.3.2/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= -github.com/arduino/go-paths-helper v1.11.0 h1:hkpGb9AtCTByTj2FKutuHWb3klDf4kAKL10hW+fN+oE= -github.com/arduino/go-paths-helper v1.11.0/go.mod h1:jcpW4wr0u69GlXhTYydsdsqAjLaYK5n7oWHfKqOG6LM= +github.com/arduino/go-paths-helper v1.12.0 h1:xizOQtI9iHdl19qXd1EmWg5i9W//2bOCOYwlNv8F61E= +github.com/arduino/go-paths-helper v1.12.0/go.mod h1:jcpW4wr0u69GlXhTYydsdsqAjLaYK5n7oWHfKqOG6LM= github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= github.com/arduino/go-properties-orderedmap v1.8.0 h1:wEfa6hHdpezrVOh787OmClsf/Kd8qB+zE3P2Xbrn0CQ= github.com/arduino/go-properties-orderedmap v1.8.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= diff --git a/go.mod b/go.mod index 477b1598..5359c6f8 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ replace github.com/oleiade/reflections => github.com/oleiade/reflections v1.0.1 require ( github.com/arduino/arduino-cli v0.0.0-20201210103408-bf7a3194bb63 - github.com/arduino/go-paths-helper v1.11.0 + github.com/arduino/go-paths-helper v1.12.0 github.com/arduino/go-properties-orderedmap v1.8.0 github.com/client9/misspell v0.3.4 github.com/go-git/go-git/v5 v5.7.0 diff --git a/go.sum b/go.sum index 5b0feaf4..bc2d96f5 100644 --- a/go.sum +++ b/go.sum @@ -61,8 +61,8 @@ github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c/go.mod h1: github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= github.com/arduino/go-paths-helper v1.2.0/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= github.com/arduino/go-paths-helper v1.3.2/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= -github.com/arduino/go-paths-helper v1.11.0 h1:hkpGb9AtCTByTj2FKutuHWb3klDf4kAKL10hW+fN+oE= -github.com/arduino/go-paths-helper v1.11.0/go.mod h1:jcpW4wr0u69GlXhTYydsdsqAjLaYK5n7oWHfKqOG6LM= +github.com/arduino/go-paths-helper v1.12.0 h1:xizOQtI9iHdl19qXd1EmWg5i9W//2bOCOYwlNv8F61E= +github.com/arduino/go-paths-helper v1.12.0/go.mod h1:jcpW4wr0u69GlXhTYydsdsqAjLaYK5n7oWHfKqOG6LM= github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= github.com/arduino/go-properties-orderedmap v1.8.0 h1:wEfa6hHdpezrVOh787OmClsf/Kd8qB+zE3P2Xbrn0CQ= github.com/arduino/go-properties-orderedmap v1.8.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= diff --git a/internal/project/project.go b/internal/project/project.go index 3adaaa6e..d0f43a9f 100644 --- a/internal/project/project.go +++ b/internal/project/project.go @@ -146,7 +146,7 @@ func findProjectsUnderPath(targetPath *paths.Path, projectTypeFilter projecttype // It is possible for a combination of symlinks to parent paths to cause project discovery to get stuck in // an endless loop of recursion. This is avoided by keeping count of the depth of symlinks and discontinuing // recursion when it exceeds reason. - pathStat, err := os.Lstat(potentialProjectDirectory.String()) + pathStat, err := potentialProjectDirectory.Lstat() if err != nil { panic(err) } diff --git a/internal/project/project_test.go b/internal/project/project_test.go index 067cd249..aad77e65 100644 --- a/internal/project/project_test.go +++ b/internal/project/project_test.go @@ -63,6 +63,57 @@ func TestSymlinkLoop(t *testing.T) { assert.Panics(t, func() { FindProjects() }, "Infinite symlink loop encountered during project discovery") } +func TestBrokenSymlink(t *testing.T) { + projectsPath := testDataPath.Join("Projects") + symlinkPath := projectsPath.Join("test-symlink") + symlinkTargetPath := projectsPath.Join("nonexistent") + // The broken symlink must have the attributes of a folder in order to be effective in this test, so the target must + // exist at the time the symlink is created. + err := symlinkTargetPath.Mkdir() + require.Nil(t, err) + // Create a folder symlink in the projects folder. + // It's probably most friendly to developers using Windows to create the symlink needed for the test on demand. + err = os.Symlink(projectsPath.Join("nonexistent").String(), symlinkPath.String()) + require.Nil(t, err, "This test must be run as administrator on Windows to have symlink creation privilege.") + defer symlinkPath.RemoveAll() // Clean up. + + // Break the symlink. + err = symlinkTargetPath.Remove() + require.Nil(t, err) + + flags := test.ConfigurationFlags() + flags.Set("project-type", "all") + flags.Set("recursive", "true") + configuration.Initialize(flags, []string{projectsPath.String()}) + + foundProjects, err := FindProjects() + require.Nil(t, err) + assert.True( + t, + reflect.DeepEqual( + foundProjects, + []Type{ + { + Path: testDataPath.Join("Projects", "Library"), + ProjectType: projecttype.Library, + SuperprojectType: projecttype.Library, + }, + { + Path: testDataPath.Join("Projects", "Library", "examples", "Example"), + ProjectType: projecttype.Sketch, + SuperprojectType: projecttype.Library, + }, + { + Path: testDataPath.Join("Projects", "Sketch"), + ProjectType: projecttype.Sketch, + SuperprojectType: projecttype.Sketch, + }, + }, + ), + "Broken symlink encountered during project discovery", + ) +} + func TestFindProjects(t *testing.T) { sketchPath := testDataPath.Join("Sketch") libraryPath := testDataPath.Join("Library") diff --git a/internal/rule/rulefunction/library.go b/internal/rule/rulefunction/library.go index d57f9ef9..031abf6d 100644 --- a/internal/rule/rulefunction/library.go +++ b/internal/rule/rulefunction/library.go @@ -92,7 +92,7 @@ func LibraryContainsSymlinks() (result ruleresult.Type, output string) { symlinkPaths := []string{} for _, projectPathItem := range projectPathListing { - projectPathItemStat, err := os.Lstat(projectPathItem.String()) + projectPathItemStat, err := projectPathItem.Lstat() if err != nil { panic(err) } diff --git a/internal/rule/rulefunction/library_test.go b/internal/rule/rulefunction/library_test.go index a0ccf937..7812e257 100644 --- a/internal/rule/rulefunction/library_test.go +++ b/internal/rule/rulefunction/library_test.go @@ -135,6 +135,19 @@ func TestLibraryContainsSymlinks(t *testing.T) { err = symlinkPath.RemoveAll() require.Nil(t, err) + // Set up a library with a broken symlink. + err = os.Symlink(librariesTestDataPath.Join(testLibrary, "nonexistent").String(), symlinkPath.String()) + require.Nil(t, err) + + testTables = []libraryRuleFunctionTestTable{ + {"Has broken symlink", testLibrary, ruleresult.Fail, ""}, + } + + checkLibraryRuleFunction(LibraryContainsSymlinks, testTables, t) + + err = symlinkPath.RemoveAll() + require.Nil(t, err) + testTables = []libraryRuleFunctionTestTable{ {"No symlink", testLibrary, ruleresult.Pass, ""}, } diff --git a/ruledocsgen/go.mod b/ruledocsgen/go.mod index 782c1795..236585e8 100644 --- a/ruledocsgen/go.mod +++ b/ruledocsgen/go.mod @@ -9,7 +9,7 @@ replace github.com/jandelgado/gcov2lcov => github.com/jandelgado/gcov2lcov v1.0. require ( github.com/JohannesKaufmann/html-to-markdown v1.4.0 github.com/arduino/arduino-lint v0.0.0 - github.com/arduino/go-paths-helper v1.11.0 + github.com/arduino/go-paths-helper v1.12.0 github.com/olekukonko/tablewriter v0.0.5 github.com/stretchr/testify v1.8.4 ) diff --git a/ruledocsgen/go.sum b/ruledocsgen/go.sum index 36df4f49..34660401 100644 --- a/ruledocsgen/go.sum +++ b/ruledocsgen/go.sum @@ -64,8 +64,8 @@ github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c/go.mod h1: github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= github.com/arduino/go-paths-helper v1.2.0/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= github.com/arduino/go-paths-helper v1.3.2/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= -github.com/arduino/go-paths-helper v1.11.0 h1:hkpGb9AtCTByTj2FKutuHWb3klDf4kAKL10hW+fN+oE= -github.com/arduino/go-paths-helper v1.11.0/go.mod h1:jcpW4wr0u69GlXhTYydsdsqAjLaYK5n7oWHfKqOG6LM= +github.com/arduino/go-paths-helper v1.12.0 h1:xizOQtI9iHdl19qXd1EmWg5i9W//2bOCOYwlNv8F61E= +github.com/arduino/go-paths-helper v1.12.0/go.mod h1:jcpW4wr0u69GlXhTYydsdsqAjLaYK5n7oWHfKqOG6LM= github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= github.com/arduino/go-properties-orderedmap v1.8.0 h1:wEfa6hHdpezrVOh787OmClsf/Kd8qB+zE3P2Xbrn0CQ= github.com/arduino/go-properties-orderedmap v1.8.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=