|
|
@@ -187,9 +187,14 @@ func (f *Firehol) updateLocalFile(ctx context.Context, filename string,
|
|
187
|
187
|
return fmt.Errorf("cannot open file: %w", err)
|
|
188
|
188
|
}
|
|
189
|
189
|
|
|
|
190
|
+ go func(ctx context.Context, closer io.Closer) {
|
|
|
191
|
+ <-ctx.Done()
|
|
|
192
|
+ closer.Close()
|
|
|
193
|
+ }(ctx, filefp)
|
|
|
194
|
+
|
|
190
|
195
|
defer filefp.Close()
|
|
191
|
196
|
|
|
192
|
|
- return f.updateTrees(ctx, mutex, filefp, v4tree, v6tree)
|
|
|
197
|
+ return f.updateTrees(mutex, filefp, v4tree, v6tree)
|
|
193
|
198
|
}
|
|
194
|
199
|
|
|
195
|
200
|
func (f *Firehol) updateRemoteURL(ctx context.Context, url string,
|
|
|
@@ -200,33 +205,31 @@ func (f *Firehol) updateRemoteURL(ctx context.Context, url string,
|
|
200
|
205
|
return fmt.Errorf("cannot build a request: %w", err)
|
|
201
|
206
|
}
|
|
202
|
207
|
|
|
203
|
|
- resp, err := f.httpClient.Do(req)
|
|
|
208
|
+ resp, err := f.httpClient.Do(req) // nolint: bodyclose
|
|
204
|
209
|
if err != nil {
|
|
205
|
210
|
return fmt.Errorf("cannot request a remote URL %s: %w", url, err)
|
|
206
|
211
|
}
|
|
207
|
212
|
|
|
208
|
|
- defer func() {
|
|
209
|
|
- io.Copy(ioutil.Discard, resp.Body) // nolint: errcheck
|
|
210
|
|
- resp.Body.Close()
|
|
211
|
|
- }()
|
|
|
213
|
+ go func(ctx context.Context, closer io.Closer) {
|
|
|
214
|
+ <-ctx.Done()
|
|
|
215
|
+ closer.Close()
|
|
|
216
|
+ }(ctx, resp.Body)
|
|
212
|
217
|
|
|
213
|
|
- return f.updateTrees(ctx, mutex, resp.Body, v4tree, v6tree)
|
|
|
218
|
+ defer func(rc io.ReadCloser) {
|
|
|
219
|
+ io.Copy(ioutil.Discard, rc) // nolint: errcheck
|
|
|
220
|
+ rc.Close()
|
|
|
221
|
+ }(resp.Body)
|
|
|
222
|
+
|
|
|
223
|
+ return f.updateTrees(mutex, resp.Body, v4tree, v6tree)
|
|
214
|
224
|
}
|
|
215
|
225
|
|
|
216
|
|
-func (f *Firehol) updateTrees(ctx context.Context,
|
|
217
|
|
- mutex sync.Locker,
|
|
|
226
|
+func (f *Firehol) updateTrees(mutex sync.Locker,
|
|
218
|
227
|
reader io.Reader,
|
|
219
|
228
|
v4tree *bool_tree.TreeV4,
|
|
220
|
229
|
v6tree *bool_tree.TreeV6) error {
|
|
221
|
230
|
scanner := bufio.NewScanner(reader)
|
|
222
|
231
|
|
|
223
|
232
|
for scanner.Scan() {
|
|
224
|
|
- select {
|
|
225
|
|
- case <-ctx.Done():
|
|
226
|
|
- return ctx.Err()
|
|
227
|
|
- default:
|
|
228
|
|
- }
|
|
229
|
|
-
|
|
230
|
233
|
text := scanner.Text()
|
|
231
|
234
|
text = fireholRegexpComment.ReplaceAllLiteralString(text, "")
|
|
232
|
235
|
text = strings.TrimSpace(text)
|