Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bd49d86

Browse files
committed
Add check for symlinks in library
1 parent 0824294 commit bd49d86

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

‎check/checkconfigurations/checkconfigurations.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,21 @@ var configurations = []Type{
761761
ErrorModes: nil,
762762
CheckFunction: checkfunctions.LibraryPropertiesMisspelledOptionalField,
763763
},
764+
{
765+
ProjectType: projecttype.Library,
766+
Category: "structure",
767+
Subcategory: "general",
768+
ID: "",
769+
Brief: "symlink",
770+
Description: "",
771+
MessageTemplate: "Symlink(s) found at {{.}}. These block acceptance to the Arduino Library Manager index.",
772+
DisableModes: nil,
773+
EnableModes: []checkmode.Type{checkmode.All},
774+
InfoModes: nil,
775+
WarningModes: []checkmode.Type{checkmode.Default},
776+
ErrorModes: []checkmode.Type{checkmode.LibraryManagerSubmission, checkmode.LibraryManagerIndexed},
777+
CheckFunction: checkfunctions.LibraryContainsSymlinks,
778+
},
764779
{
765780
ProjectType: projecttype.Sketch,
766781
Category: "structure",

‎check/checkfunctions/library.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package checkfunctions
1919

2020
import (
2121
"net/http"
22+
"os"
2223
"strings"
2324

2425
"github.com/arduino/arduino-check/check/checkdata"
@@ -785,6 +786,32 @@ func LibraryPropertiesMisspelledOptionalField() (result checkresult.Type, output
785786
return checkresult.Pass, ""
786787
}
787788

789+
func LibraryContainsSymlinks() (result checkresult.Type, output string) {
790+
projectPathListing, err := checkdata.ProjectPath().ReadDirRecursive()
791+
if err != nil {
792+
panic(err)
793+
}
794+
projectPathListing.FilterOutDirs()
795+
796+
symlinkPaths := []string{}
797+
for _, projectPathItem := range projectPathListing {
798+
projectPathItemStat, err := os.Lstat(projectPathItem.String())
799+
if err != nil {
800+
panic(err)
801+
}
802+
803+
if projectPathItemStat.Mode()&os.ModeSymlink != 0 {
804+
symlinkPaths = append(symlinkPaths, projectPathItem.String())
805+
}
806+
}
807+
808+
if len(symlinkPaths) > 0 {
809+
return checkresult.Fail, strings.Join(symlinkPaths, ", ")
810+
}
811+
812+
return checkresult.Pass, ""
813+
}
814+
788815
// spellCheckLibraryPropertiesFieldValue returns the value of the provided library.properties field with commonly misspelled words corrected.
789816
func spellCheckLibraryPropertiesFieldValue(fieldName string) (result checkresult.Type, output string) {
790817
if checkdata.LibraryPropertiesLoadError() != nil {

‎check/checkfunctions/library_test.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/arduino/arduino-check/project/projecttype"
2727
"github.com/arduino/go-paths-helper"
2828
"github.com/stretchr/testify/assert"
29+
"github.com/stretchr/testify/require"
2930
)
3031

3132
var testDataPath *paths.Path
@@ -170,3 +171,27 @@ func TestLibraryPropertiesPrecompiledFieldEnabledWithFlatLayout(t *testing.T) {
170171

171172
checkCheckFunction(LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout, testTables, t)
172173
}
174+
175+
func TestLibraryContainsSymlinks(t *testing.T) {
176+
testLibrary := "Recursive"
177+
symlinkPath := testDataPath.Join(testLibrary, "test-symlink")
178+
// It's probably most friendly to developers using Windows to create the symlink needed for the test on demand.
179+
err := os.Symlink(testDataPath.Join(testLibrary, "library.properties").String(), symlinkPath.String())
180+
require.Nil(t, err, "This test must be run as administrator on Windows to have symlink creation privilege.")
181+
defer symlinkPath.RemoveAll() // clean up
182+
183+
testTables := []checkFunctionTestTable{
184+
{"Has symlink", testLibrary, checkresult.Fail, ""},
185+
}
186+
187+
checkCheckFunction(LibraryContainsSymlinks, testTables, t)
188+
189+
err = symlinkPath.RemoveAll()
190+
require.Nil(t, err)
191+
192+
testTables = []checkFunctionTestTable{
193+
{"No symlink", testLibrary, checkresult.Pass, ""},
194+
}
195+
196+
checkCheckFunction(LibraryContainsSymlinks, testTables, t)
197+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /