github-vet / github-vet/rangeloop-pointer-findings
LSvKing/centipede: pipeline/pipeline.go; 53 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [LSvKing/centipede](https://www.github.com/LSvKing/centipede) at [pipeline/pipeline.go](https://github.com/LSvKing/centipede/blob/5ba0be8e08116756e8a43f2235b425749d499a27/pipeline/pipeline.go#L116-L168)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first
issue it finds, so please do not limit your consideration to the contents of the below message.
> range-loop variable file used in defer or goroutine at line 122
[Click here to see the code in its original context.](https://github.com/LSvKing/centipede/blob/5ba0be8e08116756e8a43f2235b425749d499a27/pipeline/pipeline.go#L116-L168)
Click here to show the 53 line(s) of Go which triggered the analyzer.
```go
for file := range pipeline.FileChan {
wait.Add(1)
go func() {
defer func() {
file.Response.Body.Close()
wait.Done()
}()
d, err := os.Stat(fileOutPath + file.Path)
if err != nil || !d.IsDir() {
if err := os.MkdirAll(fileOutPath+file.Path, 0777); err != nil {
//logs.Log.Error(
// " * Fail [文件下载:%v | KEYIN:%v | 批次:%v] %v [ERROR] %v\n",
// self.Spider.GetName(), self.Spider.GetKeyin(), atomic.LoadUint64(&self.fileBatch), fileName, err,
//)
log.Error("[创建目录]", err)
return
}
}
// 文件不存在就以0777的权限创建文件,如果存在就在写入之前清空内容
f, err := os.OpenFile(fileOutPath+file.Path+"/"+file.FileName, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
if err != nil {
//logs.Log.Error(
// " * Fail [文件下载:%v | KEYIN:%v | 批次:%v] %v [ERROR] %v\n",
// self.Spider.GetName(), self.Spider.GetKeyin(), atomic.LoadUint64(&self.fileBatch), fileName, err,
//)
log.Error("[文件下载]", err)
return
}
//log.Debugf("存储时: %p",&file.Body,file.Body.ContentLength)
size, err := io.Copy(f, file.Response.Body)
log.Debug(file.FileName, "Size:", size)
if err != nil {
//logs.Log.Error(
// " * Fail [文件下载:%v | KEYIN:%v | 批次:%v] %v (%s) [ERROR] %v\n",
// self.Spider.GetName(), self.Spider.GetKeyin(), atomic.LoadUint64(&self.fileBatch), fileName, bytesSize.Format(uint64(size)), err,
//)
log.Error(err)
return
}
}()
wait.Wait()
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: 5ba0be8e08116756e8a43f2235b425749d499a27
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.