| 44 | return self |
| 45 | |
| 46 | def __exit__(self, exc_type, exc_val, exc_tb): |
| 47 | try: |
| 48 | if exc_type is None: |
| 49 | # Success. Mark the segment as complete. |
| 50 | # |
| 51 | # In event of a crash, this os.link() without an fsync |
| 52 | # can leave a corrupt file in the prefetch directory, |
| 53 | # but given Postgres retries corrupt archive logs |
| 54 | # (because it itself makes no provisions to sync |
| 55 | # them), that is assumed to be acceptable. |
| 56 | os.link(self.tf.name, path.join( |
| 57 | self.prefetch_dir.prefetched_dir, self.segment.name)) |
| 58 | finally: |
| 59 | shutil.rmtree(self.prefetch_dir.seg_dir(self.segment)) |
| 60 | |
| 61 | |
| 62 | class Dirs(object): |