MCPcopy
hub / github.com/syncthing/syncthing / tempFile

Method tempFile

lib/model/sharedpullerstate.go:131–151  ·  view source on GitHub ↗

tempFile returns the fd for the temporary file, reusing an open fd or creating the file as necessary.

()

Source from the content-addressed store, hash-verified

129// tempFile returns the fd for the temporary file, reusing an open fd
130// or creating the file as necessary.
131func (s *sharedPullerState) tempFile() (*lockedWriterAt, error) {
132 s.mut.Lock()
133 defer s.mut.Unlock()
134
135 // If we've already hit an error, return early
136 if s.err != nil {
137 return nil, s.err
138 }
139
140 // If the temp file is already open, return the file descriptor
141 if s.writer != nil {
142 return s.writer, nil
143 }
144
145 if err := s.addWriterLocked(); err != nil {
146 s.failLocked(err)
147 return nil, err
148 }
149
150 return s.writer, nil
151}
152
153func (s *sharedPullerState) addWriterLocked() error {
154 return inWritableDir(s.tempFileInWritableDir, s.fs, s.tempName, s.ignorePerms)

Callers 5

TestReadOnlyDirFunction · 0.95
copierRoutineMethod · 0.80
copyBlockFromFileMethod · 0.80
pullBlockMethod · 0.80

Calls 3

addWriterLockedMethod · 0.95
failLockedMethod · 0.95
UnlockMethod · 0.80

Tested by 2

TestReadOnlyDirFunction · 0.76