MCPcopy Index your code
hub / github.com/syncthing/syncthing / TempFile

Function TempFile

lib/osutil/tempfile.go:49–65  ·  view source on GitHub ↗

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

(filesystem fs.Filesystem, dir, prefix string)

Source from the content-addressed store, hash-verified

47// to find the pathname of the file. It is the caller's responsibility
48// to remove the file when no longer needed.
49func TempFile(filesystem fs.Filesystem, dir, prefix string) (f fs.File, err error) {
50 nconflict := 0
51 for range 10000 {
52 name := filepath.Join(dir, prefix+nextSuffix())
53 f, err = filesystem.OpenFile(name, fs.OptReadWrite|fs.OptCreate|fs.OptExclusive, 0o600)
54 if fs.IsExist(err) {
55 if nconflict++; nconflict > 10 {
56 randmu.Lock()
57 rand = reseed()
58 randmu.Unlock()
59 }
60 continue
61 }
62 break
63 }
64 return
65}

Callers 4

TestCachingFunction · 0.92
BenchmarkMatchCachedFunction · 0.92
TestCacheReloadFunction · 0.92
CreateAtomicFilesystemFunction · 0.85

Calls 5

IsExistFunction · 0.92
nextSuffixFunction · 0.85
reseedFunction · 0.85
UnlockMethod · 0.80
OpenFileMethod · 0.65

Tested by 3

TestCachingFunction · 0.74
BenchmarkMatchCachedFunction · 0.74
TestCacheReloadFunction · 0.74