walkFiles starts a goroutine to walk the directory tree at root and send the path of each regular file on the string channel. It sends the result of the walk on the error channel. If done is closed, walkFiles abandons its work.
(done <-chan struct{}, root string)
| 15 | // path of each regular file on the string channel. It sends the result of the |
| 16 | // walk on the error channel. If done is closed, walkFiles abandons its work. |
| 17 | func walkFiles(done <-chan struct{}, root string) (<-chan string, <-chan error) { |
| 18 | paths := make(chan string) |
| 19 | errc := make(chan error, 1) |
| 20 | go func() { // HL |
| 21 | // Close the paths channel after Walk returns. |
| 22 | defer close(paths) // HL |
| 23 | // No select needed for this send, since errc is buffered. |
| 24 | errc <- filepath.Walk(root, func(path string, info os.FileInfo, err error) error { // HL |
| 25 | if err != nil { |
| 26 | return err |
| 27 | } |
| 28 | if !info.Mode().IsRegular() { |
| 29 | return nil |
| 30 | } |
| 31 | select { |
| 32 | case paths <- path: // HL |
| 33 | case <-done: // HL |
| 34 | return errors.New("walk canceled") |
| 35 | } |
| 36 | return nil |
| 37 | }) |
| 38 | }() |
| 39 | return paths, errc |
| 40 | } |
| 41 | |
| 42 | // A result is the product of reading and summing a file using MD5. |
| 43 | type result struct { |