TempFile creates a new temporary file in the directory dir with a name beginning with prefix, opens the file for reading and writing, and returns the resulting *os.File. If dir is the empty string, TempFile uses the default directory for temporary files (see os.TempDir). Multiple programs calling Te
(dir, prefix string, postfix string)
| 45 | // to find the pathname of the file. It is the caller's responsibility |
| 46 | // to remove the file when no longer needed. |
| 47 | func TempFileWithPostfix(dir, prefix string, postfix string) (f *os.File, err error) { |
| 48 | if dir == "" { |
| 49 | dir = os.TempDir() |
| 50 | } |
| 51 | |
| 52 | nconflict := 0 |
| 53 | for i := 0; i < 10000; i++ { |
| 54 | name := filepath.Join(dir, prefix+nextSuffix()+postfix) |
| 55 | f, err = os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600) |
| 56 | if os.IsExist(err) { |
| 57 | if nconflict++; nconflict > 10 { |
| 58 | rand = reseed() |
| 59 | } |
| 60 | continue |
| 61 | } |
| 62 | break |
| 63 | } |
| 64 | return |
| 65 | } |
no test coverage detected
searching dependent graphs…