github-vet / github-vet/rangeloop-pointer-findings
otsuka-kentaro/fsw-copy-go: main.go; 44 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [otsuka-kentaro/fsw-copy-go](https://www.github.com/otsuka-kentaro/fsw-copy-go) at [main.go](https://github.com/otsuka-kentaro/fsw-copy-go/blob/e9658c048c565f18da6b2aa263e3c8e1b6c26b46/main.go#L175-L218)
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 189
[Click here to see the code in its original context.](https://github.com/otsuka-kentaro/fsw-copy-go/blob/e9658c048c565f18da6b2aa263e3c8e1b6c26b46/main.go#L175-L218)
Click here to show the 44 line(s) of Go which triggered the analyzer.
```go
for _, file := range changeFiles {
if lib.IsDirOrInvalidFile(file, srcBaseDir) {
lib.DoneWaitGroups(wg, len(destDir))
continue
}
info, err := os.Stat(file)
if err != nil {
return err
}
for _, destBaseDir := range destDir {
go func() {
defer wg.Done()
destFilePath := strings.Replace(file, srcBaseDir, destBaseDir, 1)
if info.IsDir() {
// ディレクトリ作成
if err := os.MkdirAll(destFilePath, info.Mode()); err != nil {
log.Println(err)
fmt.Printf("failed to create directory %s\n", destFilePath)
} else {
fmt.Printf("directory %s created\n", destFilePath)
}
} else {
// ファイルコピー
if err := lib.CopyFile(file, destFilePath); err != nil {
log.Println(err)
fmt.Printf("failed to copy file from %s to %s\n", file, destFilePath)
} else {
fmt.Printf("file copied from %s to %s\n", file, destFilePath)
}
}
}()
}
// ディレクトリの場合は watcher に追加
if info.IsDir() {
if err := watcher.Add(file); err != nil {
// 監視に追加できなかったので終了
return err
}
log.Println("added watching directory", file)
}
}
```
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: e9658c048c565f18da6b2aa263e3c8e1b6c26b46
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.