github-vet / github-vet/rangeloop-pointer-findings
pilgreen/drive2hugo: main.go; 57 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [pilgreen/drive2hugo](https://www.github.com/pilgreen/drive2hugo) at [main.go](https://github.com/pilgreen/drive2hugo/blob/26669be48cef7ee16a7193905977e61906c160e8/main.go#L75-L131)
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 folder used in defer or goroutine at line 106
[Click here to see the code in its original context.](https://github.com/pilgreen/drive2hugo/blob/26669be48cef7ee16a7193905977e61906c160e8/main.go#L75-L131)
Click here to show the 57 line(s) of Go which triggered the analyzer.
```go
for _, folder := range config.Folders {
var q string
mod, err := modTime()
if *mPtr == true && err == nil {
q = fmt.Sprintf("mimeType = 'application/vnd.google-apps.document' and '%s' in parents and modifiedTime > '%s'", folder.Id, mod)
} else {
q = fmt.Sprintf("mimeType = 'application/vnd.google-apps.document' and '%s' in parents", folder.Id)
}
r, err := srv.Files.List().Q(q).Fields("files(name, id)").Do()
if err != nil {
log.Fatalf("Unable to retrieve files: %v", err)
}
log.Printf("%d files found in %s\n", len(r.Files), folder.Id)
if len(r.Files) > 0 {
os.MkdirAll(folder.Path, 0755)
queue := make(chan *drive.File, len(r.Files))
done := make(chan bool)
// Set up the goroutine to handle the individual files
go func() {
for {
file, more := <-queue
if more {
req, err := srv.Files.Export(file.Id, "text/plain").Download()
if err != nil {
log.Fatalf("Unable to download file: %v", err)
}
filename := filepath.Join(folder.Path, file.Name + ".md")
body, _ := ioutil.ReadAll(req.Body)
err = ioutil.WriteFile(filename, body, 0644)
if err != nil {
log.Printf("Problem writing %s: %v\n", filename, err)
} else {
log.Printf("%s ... \u2713\n", filename)
}
} else {
log.Printf("all done with folder: %s\n", folder.Id)
done <- true
return
}
}
}()
for _, file := range r.Files {
queue <- file
}
close(queue)
<- done
}
}
```
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: 26669be48cef7ee16a7193905977e61906c160e8
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.