| 140 | shutil.rmtree(self.prefetched_dir, False, warn_on_cant_remove) |
| 141 | |
| 142 | def clear_except(self, retained_segments): |
| 143 | sn = set(s.name for s in retained_segments) |
| 144 | |
| 145 | try: |
| 146 | for n in os.listdir(self.running): |
| 147 | if n not in sn and re.match(storage.SEGMENT_REGEXP, n): |
| 148 | try: |
| 149 | shutil.rmtree(path.join(self.running, n)) |
| 150 | except EnvironmentError as e: |
| 151 | if e.errno != errno.ENOENT: |
| 152 | raise |
| 153 | except EnvironmentError as e: |
| 154 | if e.errno != errno.ENOENT: |
| 155 | raise |
| 156 | |
| 157 | try: |
| 158 | for n in os.listdir(self.prefetched_dir): |
| 159 | if n not in sn and re.match(storage.SEGMENT_REGEXP, n): |
| 160 | try: |
| 161 | os.remove(path.join(self.prefetched_dir, n)) |
| 162 | except EnvironmentError as e: |
| 163 | if e.errno != errno.ENOENT: |
| 164 | raise |
| 165 | except EnvironmentError as e: |
| 166 | if e.errno != errno.ENOENT: |
| 167 | raise |
| 168 | |
| 169 | def contains(self, segment): |
| 170 | return path.isfile(path.join(self.prefetched_dir, segment.name)) |