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 e8ca1c2

Browse files
authored
Merge pull request #56 from arduino/per1234/symlink-check
Add check for symlinks in library
2 parents e2656e4 + 7a62024 commit e8ca1c2

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

‎check/checkconfigurations/checkconfigurations.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,21 @@ var configurations = []Type{
806806
ErrorModes: nil,
807807
CheckFunction: checkfunctions.LibraryHasSubmodule,
808808
},
809+
{
810+
ProjectType: projecttype.Library,
811+
Category: "structure",
812+
Subcategory: "general",
813+
ID: "",
814+
Brief: "symlink",
815+
Description: "",
816+
MessageTemplate: "Symlink(s) found at {{.}}. These block acceptance to the Arduino Library Manager index.",
817+
DisableModes: nil,
818+
EnableModes: []checkmode.Type{checkmode.All},
819+
InfoModes: nil,
820+
WarningModes: []checkmode.Type{checkmode.Default},
821+
ErrorModes: []checkmode.Type{checkmode.LibraryManagerSubmission, checkmode.LibraryManagerIndexed},
822+
CheckFunction: checkfunctions.LibraryContainsSymlinks,
823+
},
809824
{
810825
ProjectType: projecttype.Sketch,
811826
Category: "structure",

‎check/checkfunctions/library.go‎

Lines changed: 28 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
"path/filepath"
2324
"strings"
2425

@@ -864,6 +865,33 @@ func LibraryHasSubmodule() (result checkresult.Type, output string) {
864865
return checkresult.Pass, ""
865866
}
866867

868+
// LibraryContainsSymlinks checks if the library folder contains symbolic links.
869+
func LibraryContainsSymlinks() (result checkresult.Type, output string) {
870+
projectPathListing, err := checkdata.ProjectPath().ReadDirRecursive()
871+
if err != nil {
872+
panic(err)
873+
}
874+
projectPathListing.FilterOutDirs()
875+
876+
symlinkPaths := []string{}
877+
for _, projectPathItem := range projectPathListing {
878+
projectPathItemStat, err := os.Lstat(projectPathItem.String())
879+
if err != nil {
880+
panic(err)
881+
}
882+
883+
if projectPathItemStat.Mode()&os.ModeSymlink != 0 {
884+
symlinkPaths = append(symlinkPaths, projectPathItem.String())
885+
}
886+
}
887+
888+
if len(symlinkPaths) > 0 {
889+
return checkresult.Fail, strings.Join(symlinkPaths, ", ")
890+
}
891+
892+
return checkresult.Pass, ""
893+
}
894+
867895
// spellCheckLibraryPropertiesFieldValue returns the value of the provided library.properties field with commonly misspelled words corrected.
868896
func spellCheckLibraryPropertiesFieldValue(fieldName string) (result checkresult.Type, output string) {
869897
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
@@ -200,3 +201,27 @@ func TestLibraryHasSubmodule(t *testing.T) {
200201

201202
checkCheckFunction(LibraryHasSubmodule, testTables, t)
202203
}
204+
205+
func TestLibraryContainsSymlinks(t *testing.T) {
206+
testLibrary := "Recursive"
207+
symlinkPath := testDataPath.Join(testLibrary, "test-symlink")
208+
// It's probably most friendly to developers using Windows to create the symlink needed for the test on demand.
209+
err := os.Symlink(testDataPath.Join(testLibrary, "library.properties").String(), symlinkPath.String())
210+
require.Nil(t, err, "This test must be run as administrator on Windows to have symlink creation privilege.")
211+
defer symlinkPath.RemoveAll() // clean up
212+
213+
testTables := []checkFunctionTestTable{
214+
{"Has symlink", testLibrary, checkresult.Fail, ""},
215+
}
216+
217+
checkCheckFunction(LibraryContainsSymlinks, testTables, t)
218+
219+
err = symlinkPath.RemoveAll()
220+
require.Nil(t, err)
221+
222+
testTables = []checkFunctionTestTable{
223+
{"No symlink", testLibrary, checkresult.Pass, ""},
224+
}
225+
226+
checkCheckFunction(LibraryContainsSymlinks, testTables, t)
227+
}

0 commit comments

Comments
(0)

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