|
8 | 8 | "io" |
9 | 9 | "net/http" |
10 | 10 | "net/url" |
| 11 | + "os" |
11 | 12 | "path" |
12 | 13 | "path/filepath" |
13 | 14 | "strings" |
@@ -186,7 +187,7 @@ func (r *RepoFetcherImpl) fetchFile(fileType string, repo *bazeldnf.Repository, |
186 | 187 | log.Infof("Loading %s file from %s", fileType, fileURL) |
187 | 188 | resp, err := r.Getter.Get(fileURL) |
188 | 189 | if err != nil { |
189 | | - return fmt.Errorf("Failed to load promary repository file from %s: %v", fileURL, err) |
| 190 | + return fmt.Errorf("Failed to load primary repository file from %s: %v", fileURL, err) |
190 | 191 | } |
191 | 192 | sha := sha256.New() |
192 | 193 | defer resp.Body.Close() |
@@ -214,8 +215,29 @@ type Getter interface { |
214 | 215 |
|
215 | 216 | type getterImpl struct{} |
216 | 217 |
|
217 | | -func (*getterImpl) Get(url string) (resp *http.Response, err error) { |
218 | | - return http.Get(url) |
| 218 | +func fileGet(filename string) (*http.Response, error) { |
| 219 | + fp, err := os.Open(filename) |
| 220 | + if err != nil { |
| 221 | + return nil, err // skipped wrapping the error since the error already begins with "open: " |
| 222 | + } |
| 223 | + |
| 224 | + resp := &http.Response{ |
| 225 | + Status: "OK", |
| 226 | + StatusCode: http.StatusOK, |
| 227 | + Body: fp, |
| 228 | + } |
| 229 | + return resp, nil |
| 230 | +} |
| 231 | + |
| 232 | +func (*getterImpl) Get(rawURL string) (*http.Response, error) { |
| 233 | + u, err := url.Parse(rawURL) |
| 234 | + if err != nil { |
| 235 | + return nil, fmt.Errorf("Failed to parse URL: %w", err) |
| 236 | + } |
| 237 | + if u.Scheme == "file" { |
| 238 | + return fileGet(u.Path) |
| 239 | + } |
| 240 | + return http.Get(rawURL) |
219 | 241 | } |
220 | 242 |
|
221 | 243 | func toHex(hasher hash.Hash) string { |
|
0 commit comments