...
Source file src/pkg/cmd/vendor/github.com/google/pprof/internal/driver/tempfile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package driver
16
17 import (
18 "fmt"
19 "os"
20 "path/filepath"
21 "sync"
22 )
23
24
25 func newTempFile(dir, prefix, suffix string) (*os.File, error) {
26 for index := 1; index < 10000; index++ {
27 path := filepath.Join(dir, fmt.Sprintf("%s%03d%s", prefix, index, suffix))
28 if _, err := os.Stat(path); err != nil {
29 return os.Create(path)
30 }
31 }
32
33 return nil, fmt.Errorf("could not create file of the form %s%03d%s", prefix, 1, suffix)
34 }
35
36 var tempFiles []string
37 var tempFilesMu = sync.Mutex{}
38
39
40 func deferDeleteTempFile(path string) {
41 tempFilesMu.Lock()
42 tempFiles = append(tempFiles, path)
43 tempFilesMu.Unlock()
44 }
45
46
47 func cleanupTempFiles() {
48 tempFilesMu.Lock()
49 for _, f := range tempFiles {
50 os.Remove(f)
51 }
52 tempFiles = nil
53 tempFilesMu.Unlock()
54 }
55
View as plain text