|
@@ -21,25 +21,16 @@ import (
|
21
|
21
|
"sync"
|
22
|
22
|
)
|
23
|
23
|
|
24
|
|
-// newTempFilePath returns an unused path for output files.
|
25
|
|
-func newTempFilePath(dir, prefix, suffix string) (string, error) {
|
|
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
|
26
|
for index := 1; index < 10000; index++ {
|
27
|
27
|
path := filepath.Join(dir, fmt.Sprintf("%s%03d%s", prefix, index, suffix))
|
28
|
28
|
if _, err := os.Stat(path); err != nil {
|
29
|
|
- return path, nil
|
|
29
|
+ return os.Create(path)
|
30
|
30
|
}
|
31
|
31
|
}
|
32
|
32
|
// Give up
|
33
|
|
- return "", fmt.Errorf("could not create file of the form %s%03d%s", prefix, 1, suffix)
|
34
|
|
-}
|
35
|
|
-
|
36
|
|
-// newTempFile returns a new file with a random name for output files.
|
37
|
|
-func newTempFile(dir, prefix, suffix string) (*os.File, error) {
|
38
|
|
- path, err := newTempFilePath(dir, prefix, suffix)
|
39
|
|
- if err != nil {
|
40
|
|
- return nil, err
|
41
|
|
- }
|
42
|
|
- return os.Create(path)
|
|
33
|
+ return nil, fmt.Errorf("could not create file of the form %s%03d%s", prefix, 1, suffix)
|
43
|
34
|
}
|
44
|
35
|
|
45
|
36
|
var tempFiles []string
|