@@ -8,15 +8,15 @@ import (
88 "fmt"
99 "io/fs"
1010 "io/ioutil"
11- "path"
1211 "path/filepath"
1312 "regexp"
1413 "strings"
1514
16- ve "github.com/elastic/package-spec/code/go/internal/errors"
17-
1815 "github.com/pkg/errors"
1916 "gopkg.in/yaml.v3"
17+
18+ ve "github.com/elastic/package-spec/code/go/internal/errors"
19+ "github.com/elastic/package-spec/code/go/internal/fspath"
2020)
2121
2222const (
@@ -66,11 +66,11 @@ func newFolderSpec(fs fs.FS, specPath string) (*folderSpec, error) {
6666 return & spec , nil
6767}
6868
69- func (s * folderSpec ) validate (packageName string , folderPath string ) ve.ValidationErrors {
69+ func (s * folderSpec ) validate (packageName string , fsys fspath. FS , path string ) ve.ValidationErrors {
7070 var errs ve.ValidationErrors
71- files , err := ioutil .ReadDir (folderPath )
71+ files , err := fs .ReadDir (fsys , path )
7272 if err != nil {
73- errs = append (errs , errors .Wrapf (err , "could not read folder [%s]" , folderPath ))
73+ errs = append (errs , errors .Wrapf (err , "could not read folder [%s]" , fsys . Path ( path ) ))
7474 return errs
7575 }
7676
@@ -87,16 +87,16 @@ func (s *folderSpec) validate(packageName string, folderPath string) ve.Validati
8787 if file .IsDir () {
8888 if ! s .DevelopmentFolder && strings .Contains (fileName , "-" ) {
8989 errs = append (errs ,
90- fmt .Errorf (`file "%s/%s " is invalid: directory name inside package %s contains -: %s` ,
91- folderPath , fileName , packageName , fileName ))
90+ fmt .Errorf (`file "%s" is invalid: directory name inside package %s contains -: %s` ,
91+ fsys . Path ( path , fileName ) , packageName , fileName ))
9292 }
9393 }
9494 continue
9595 }
9696
9797 if itemSpec == nil && ! s .AdditionalContents {
9898 // No spec found for current folder item and we do not allow additional contents in folder.
99- errs = append (errs , fmt .Errorf ("item [%s] is not allowed in folder [%s]" , fileName , folderPath ))
99+ errs = append (errs , fmt .Errorf ("item [%s] is not allowed in folder [%s]" , fileName , fsys . Path ( path ) ))
100100 continue
101101 }
102102
@@ -118,7 +118,7 @@ func (s *folderSpec) validate(packageName string, folderPath string) ve.Validati
118118
119119 var subFolderSpec * folderSpec
120120 if itemSpec .Ref != "" {
121- subFolderSpecPath := path .Join (filepath .Dir (s .specPath ), itemSpec .Ref )
121+ subFolderSpecPath := filepath .Join (filepath .Dir (s .specPath ), itemSpec .Ref )
122122 subFolderSpec , err = newFolderSpec (s .fs , subFolderSpecPath )
123123 if err != nil {
124124 errs = append (errs , err )
@@ -140,23 +140,23 @@ func (s *folderSpec) validate(packageName string, folderPath string) ve.Validati
140140 subFolderSpec .DevelopmentFolder = true
141141 }
142142
143- subFolderPath := path .Join (folderPath , fileName )
144- subErrs := subFolderSpec .validate (packageName , subFolderPath )
143+ subFolderPath := filepath .Join (path , fileName )
144+ subErrs := subFolderSpec .validate (packageName , fsys , subFolderPath )
145145 if len (subErrs ) > 0 {
146146 errs = append (errs , subErrs ... )
147147 }
148148
149149 } else {
150150 if ! itemSpec .isSameType (file ) {
151- errs = append (errs , fmt .Errorf ("[%s] is a file but is expected to be a folder" , fileName ))
151+ errs = append (errs , fmt .Errorf ("[%s] is a file but is expected to be a folder" , fsys . Path ( fileName ) ))
152152 continue
153153 }
154154
155- itemPath := filepath .Join (folderPath , file .Name ())
156- itemValidationErrs := itemSpec .validate (s .fs , s .specPath , itemPath )
155+ itemPath := filepath .Join (path , file .Name ())
156+ itemValidationErrs := itemSpec .validate (s .fs , fsys , s .specPath , itemPath )
157157 if itemValidationErrs != nil {
158158 for _ , ive := range itemValidationErrs {
159- errs = append (errs , errors .Wrapf (ive , "file \" %s\" is invalid" , itemPath ))
159+ errs = append (errs , errors .Wrapf (ive , "file \" %s\" is invalid" , fsys . Path ( itemPath ) ))
160160 }
161161 }
162162 }
@@ -177,9 +177,9 @@ func (s *folderSpec) validate(packageName string, folderPath string) ve.Validati
177177 if ! fileFound {
178178 var err error
179179 if itemSpec .Name != "" {
180- err = fmt .Errorf ("expecting to find [%s] %s in folder [%s]" , itemSpec .Name , itemSpec .ItemType , folderPath )
180+ err = fmt .Errorf ("expecting to find [%s] %s in folder [%s]" , itemSpec .Name , itemSpec .ItemType , fsys . Path ( path ) )
181181 } else if itemSpec .Pattern != "" {
182- err = fmt .Errorf ("expecting to find %s matching pattern [%s] in folder [%s]" , itemSpec .ItemType , itemSpec .Pattern , folderPath )
182+ err = fmt .Errorf ("expecting to find %s matching pattern [%s] in folder [%s]" , itemSpec .ItemType , itemSpec .Pattern , fsys . Path ( path ) )
183183 }
184184 errs = append (errs , err )
185185 }
0 commit comments