Skip to content

Commit 53101de

Browse files
committed
Merge branch 'relative-file' into relative-paths
2 parents 027683e + 95e3e5e commit 53101de

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

fields.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,43 @@ func validateFieldsV0(publiccode PublicCode, parser Parser, network bool) error
4848
}
4949

5050
if publiccodev0.Logo != "" {
51+
<<<<<<< HEAD
5152
if _, err := isRelativePathOrURL(publiccodev0.Logo, "logo"); err != nil {
5253
vr = append(vr, err)
5354
} else if validLogo, err := parser.validLogo(toCodeHostingURL(publiccodev0.Logo, parser.baseURL), network); !validLogo {
55+
=======
56+
if validLogo, err := parser.validLogo(toCodeHostingURL(publiccodev0.Logo, parser.baseURL, parser.localFilePath), network); !validLogo {
57+
>>>>>>> relative-file
5458
vr = append(vr, newValidationError("logo", err.Error()))
5559
}
5660
}
5761

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

65+
<<<<<<< HEAD
6166
if _, err := isRelativePathOrURL(publiccodev0.MonochromeLogo, "monochromeLogo"); err != nil {
6267
vr = append(vr, err)
6368
} else if validLogo, err := parser.validLogo(toCodeHostingURL(publiccodev0.MonochromeLogo, parser.baseURL), network); !validLogo {
69+
=======
70+
if validLogo, err := parser.validLogo(toCodeHostingURL(publiccodev0.MonochromeLogo, parser.baseURL, parser.localFilePath), network); !validLogo {
71+
>>>>>>> relative-file
6472
vr = append(vr, newValidationError("monochromeLogo", err.Error()))
6573
}
6674
}
6775

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

79+
<<<<<<< HEAD
7180
if _, err := isRelativePathOrURL(*publiccodev0.Legal.AuthorsFile, "legal.authorsFile"); err != nil {
7281
vr = append(vr, err)
7382
} else if exists, err := parser.fileExists(toCodeHostingURL(*publiccodev0.Legal.AuthorsFile, parser.baseURL), network); !exists {
7483
u := toCodeHostingURL(*publiccodev0.Legal.AuthorsFile, parser.baseURL)
84+
=======
85+
if !parser.fileExists(toCodeHostingURL(*publiccodev0.Legal.AuthorsFile, parser.baseURL, parser.localFilePath), network) {
86+
u := toCodeHostingURL(*publiccodev0.Legal.AuthorsFile, parser.baseURL, parser.localFilePath)
87+
>>>>>>> relative-file
7588

7689
vr = append(vr, newValidationError("legal.authorsFile", "'%s' does not exist: %s", urlutil.DisplayURL(&u), err.Error()))
7790
}
@@ -116,10 +129,14 @@ func validateFieldsV0(publiccode PublicCode, parser Parser, network bool) error
116129
}
117130

118131
for i, v := range desc.Screenshots {
132+
<<<<<<< HEAD
119133
keyName := fmt.Sprintf("description.%s.screenshots[%d]", lang, i)
120134
if _, err := isRelativePathOrURL(v, keyName); err != nil {
121135
vr = append(vr, err)
122136
} else if isImage, err := parser.isImageFile(toCodeHostingURL(v, parser.baseURL), network); !isImage {
137+
=======
138+
if isImage, err := parser.isImageFile(toCodeHostingURL(v, parser.baseURL, parser.localFilePath), network); !isImage {
139+
>>>>>>> relative-file
123140
vr = append(vr, newValidationError(
124141
keyName,
125142
"'%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)