openAllPacks opens read-only each pack file in s.root, populating s.fds. The latest pack file will also have a writable handle opened. This function is not thread safe, s.mu should be locked by the caller.
()
| 309 | // The latest pack file will also have a writable handle opened. |
| 310 | // This function is not thread safe, s.mu should be locked by the caller. |
| 311 | func (s *storage) openAllPacks() error { |
| 312 | debug.Println("diskpacked: openAllPacks") |
| 313 | n := 0 |
| 314 | for { |
| 315 | err := s.openForRead(n) |
| 316 | if os.IsNotExist(err) { |
| 317 | break |
| 318 | } |
| 319 | if err != nil { |
| 320 | return err |
| 321 | } |
| 322 | n++ |
| 323 | } |
| 324 | |
| 325 | if n == 0 { |
| 326 | // If no pack files are found, we create one open for read and write. |
| 327 | return s.nextPack() |
| 328 | } |
| 329 | |
| 330 | // If 1 or more pack files are found, open the last one read and write. |
| 331 | return s.openForWrite(n - 1) |
| 332 | } |
| 333 | |
| 334 | // Close index and all opened fds, with locking. |
| 335 | func (s *storage) Close() error { |
no test coverage detected