(d string)
| 133 | } |
| 134 | |
| 135 | func (p *Pool) rollLocal(d string) (string, error) { |
| 136 | files, err := os.ReadDir(d) |
| 137 | if err != nil { |
| 138 | return "", err |
| 139 | } |
| 140 | if len(files) == 0 { |
| 141 | return "", ErrEmptyType |
| 142 | } |
| 143 | if len(files) == 1 { |
| 144 | if files[0].IsDir() { |
| 145 | return "", ErrEmptyType |
| 146 | } |
| 147 | return d + "/" + files[0].Name(), nil |
| 148 | } |
| 149 | for c := 0; c < 128; c++ { |
| 150 | f := files[rand.Intn(len(files))] |
| 151 | if !f.IsDir() { |
| 152 | return d + "/" + f.Name(), nil |
| 153 | } |
| 154 | } |
| 155 | return "", ErrEmptyType |
| 156 | } |