MCPcopy
hub / github.com/perkeep/perkeep / openForRead

Method openForRead

pkg/blobserver/diskpacked/diskpacked.go:227–241  ·  view source on GitHub ↗

openForRead will open pack file n for read and keep a handle to it in s.fds. os.IsNotExist returned if n >= the number of pack files in s.root. This function is not thread safe, s.mu should be locked by the caller.

(n int)

Source from the content-addressed store, hash-verified

225// s.fds. os.IsNotExist returned if n >= the number of pack files in s.root.
226// This function is not thread safe, s.mu should be locked by the caller.
227func (s *storage) openForRead(n int) error {
228 if n > len(s.fds) {
229 panic(fmt.Sprintf("openForRead called out of order got %d, expected %d", n, len(s.fds)))
230 }
231
232 fn := s.filename(n)
233 f, err := os.Open(fn)
234 if err != nil {
235 return err
236 }
237 openFdsVar.Add(s.root, 1)
238 debug.Printf("diskpacked: opened for read %q", fn)
239 s.fds = append(s.fds, f)
240 return nil
241}
242
243// openForWrite will create or open pack file n for writes, create a lock
244// visible external to the process and seek to the end of the file ready for

Callers 2

nextPackMethod · 0.95
openAllPacksMethod · 0.95

Calls 4

filenameMethod · 0.95
PrintfMethod · 0.80
OpenMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected