Skip to content

Commit 95e3e5e

Browse files
committed
fix: wip: correct cwd when network is disabled
1 parent caa695e commit 95e3e5e

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

fields.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,24 @@ func validateFieldsV0(publiccode PublicCode, parser Parser, network bool) error
4747
}
4848

4949
if publiccodev0.Logo != "" {
50-
if validLogo, err := parser.validLogo(toCodeHostingURL(publiccodev0.Logo, parser.baseURL), network); !validLogo {
50+
if validLogo, err := parser.validLogo(toCodeHostingURL(publiccodev0.Logo, parser.baseURL, parser.localFilePath), network); !validLogo {
5151
vr = append(vr, newValidationError("logo", err.Error()))
5252
}
5353
}
5454

5555
if publiccodev0.MonochromeLogo != "" {
5656
vr = append(vr, ValidationWarning{"monochromeLogo", "This key is DEPRECATED and will be removed in the future", 0, 0})
5757

58-
if validLogo, err := parser.validLogo(toCodeHostingURL(publiccodev0.MonochromeLogo, parser.baseURL), network); !validLogo {
58+
if validLogo, err := parser.validLogo(toCodeHostingURL(publiccodev0.MonochromeLogo, parser.baseURL, parser.localFilePath), network); !validLogo {
5959
vr = append(vr, newValidationError("monochromeLogo", err.Error()))
6060
}
6161
}
6262

6363
if publiccodev0.Legal.AuthorsFile != nil {
6464
vr = append(vr, ValidationWarning{"legal.authorsFile", "This key is DEPRECATED and will be removed in the future", 0, 0})
6565

66-
if !parser.fileExists(toCodeHostingURL(*publiccodev0.Legal.AuthorsFile, parser.baseURL), network) {
67-
u := toCodeHostingURL(*publiccodev0.Legal.AuthorsFile, parser.baseURL)
66+
if !parser.fileExists(toCodeHostingURL(*publiccodev0.Legal.AuthorsFile, parser.baseURL, parser.localFilePath), network) {
67+
u := toCodeHostingURL(*publiccodev0.Legal.AuthorsFile, parser.baseURL, parser.localFilePath)
6868

6969
vr = append(vr, newValidationError("legal.authorsFile", "'%s' does not exist", urlutil.DisplayURL(&u)))
7070
}
@@ -109,7 +109,7 @@ func validateFieldsV0(publiccode PublicCode, parser Parser, network bool) error
109109
}
110110

111111
for i, v := range desc.Screenshots {
112-
if isImage, err := parser.isImageFile(toCodeHostingURL(v, parser.baseURL), network); !isImage {
112+
if isImage, err := parser.isImageFile(toCodeHostingURL(v, parser.baseURL, parser.localFilePath), network); !isImage {
113113
vr = append(vr, newValidationError(
114114
fmt.Sprintf("description.%s.screenshots[%d]", lang, i),
115115
"'%s' is not an image: %s", v, err.Error(),

parser.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type Parser struct {
4848
domain Domain
4949
branch string
5050
baseURL *url.URL
51+
localFilePath string
5152
}
5253

5354
// Domain is a single code hosting service.
@@ -274,6 +275,7 @@ func (p *Parser) Parse(uri string) (PublicCode, error) {
274275
if err != nil {
275276
return nil, fmt.Errorf("can't open file '%s': %w", url.Path, err)
276277
}
278+
p.localFilePath = url.Path
277279
} else {
278280
resp, err := http.Get(uri)
279281
if err != nil {

validations.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (p *Parser) isReachable(u url.URL, network bool) (bool, error) {
9696
//
9797
// It supports relative paths and turns them into remote URLs or file:// URLs
9898
// depending on the value of baseURL
99-
func toCodeHostingURL(file string, baseURL *url.URL) url.URL {
99+
func toCodeHostingURL(file string, baseURL *url.URL, localFilePath string) url.URL {
100100
// Check if file is an absolute URL
101101
if uri, err := url.ParseRequestURI(file); err == nil {
102102
if raw := vcsurl.GetRawFile(uri); raw != nil {
@@ -116,9 +116,8 @@ func toCodeHostingURL(file string, baseURL *url.URL) url.URL {
116116
return u
117117
}
118118

119-
// Let's construct a valid URL that will not be used anyway, because
120-
// of DisableNetwork == true.
121-
return url.URL{Scheme: "file", Path: file}
119+
// It's a local file
120+
return url.URL{Scheme: "file", Path: path.Join(localFilePath, file)}
122121
}
123122

124123
// fileExists returns true if the file resource exists.

0 commit comments

Comments
 (0)