newTempFile returns a new output file in dir with the provided prefix and suffix.
(dir, prefix, suffix string)
| 23 | |
| 24 | // newTempFile returns a new output file in dir with the provided prefix and suffix. |
| 25 | func newTempFile(dir, prefix, suffix string) (*os.File, error) { |
| 26 | for index := 1; index < 10000; index++ { |
| 27 | switch f, err := os.OpenFile(filepath.Join(dir, fmt.Sprintf("%s%03d%s", prefix, index, suffix)), os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666); { |
| 28 | case err == nil: |
| 29 | return f, nil |
| 30 | case !os.IsExist(err): |
| 31 | return nil, err |
| 32 | } |
| 33 | } |
| 34 | // Give up |
| 35 | return nil, fmt.Errorf("could not create file of the form %s%03d%s", prefix, 1, suffix) |
| 36 | } |
| 37 | |
| 38 | var tempFiles []string |
| 39 | var tempFilesMu = sync.Mutex{} |
no outgoing calls
searching dependent graphs…