Update table of contents mapping.
(self)
| 512 | path) |
| 513 | |
| 514 | def _refresh(self): |
| 515 | """Update table of contents mapping.""" |
| 516 | # If it has been less than two seconds since the last _refresh() call, |
| 517 | # we have to unconditionally re-read the mailbox just in case it has |
| 518 | # been modified, because os.path.mtime() has a 2 sec resolution in the |
| 519 | # most common worst case (FAT) and a 1 sec resolution typically. This |
| 520 | # results in a few unnecessary re-reads when _refresh() is called |
| 521 | # multiple times in that interval, but once the clock ticks over, we |
| 522 | # will only re-read as needed. Because the filesystem might be being |
| 523 | # served by an independent system with its own clock, we record and |
| 524 | # compare with the mtimes from the filesystem. Because the other |
| 525 | # system's clock might be skewing relative to our clock, we add an |
| 526 | # extra delta to our wait. The default is one tenth second, but is an |
| 527 | # instance variable and so can be adjusted if dealing with a |
| 528 | # particularly skewed or irregular system. |
| 529 | if time.time() - self._last_read > 2 + self._skewfactor: |
| 530 | refresh = False |
| 531 | for subdir in self._toc_mtimes: |
| 532 | mtime = os.path.getmtime(self._paths[subdir]) |
| 533 | if mtime > self._toc_mtimes[subdir]: |
| 534 | refresh = True |
| 535 | self._toc_mtimes[subdir] = mtime |
| 536 | if not refresh: |
| 537 | return |
| 538 | # Refresh toc |
| 539 | self._toc = {} |
| 540 | for subdir in self._toc_mtimes: |
| 541 | path = self._paths[subdir] |
| 542 | for entry in os.listdir(path): |
| 543 | p = os.path.join(path, entry) |
| 544 | if os.path.isdir(p): |
| 545 | continue |
| 546 | uniq = entry.split(self.colon)[0] |
| 547 | self._toc[uniq] = os.path.join(subdir, entry) |
| 548 | self._last_read = time.time() |
| 549 | |
| 550 | def _lookup(self, key): |
| 551 | """Use TOC to return subpath for given key, or raise a KeyError.""" |