Skip to content

Commit d562a71

Browse files
committed
Track index download info to facilitate cleanup #664
Signed-off-by: Jono Yang <[email protected]>
1 parent 2ecb6d6 commit d562a71

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

minecode_pipelines/pipes/debian.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import gzip
2424
import os
2525
from datetime import datetime
26+
from shutil import rmtree
2627

2728
import debian_inspector
2829
from aboutcode import hashid
@@ -82,21 +83,23 @@ class DebianCollector:
8283

8384
def __init__(self, index_location=None):
8485
if index_location:
86+
self.index_download = None
8587
self.index_location = index_location
8688
else:
87-
self.index_location = self._fetch_index()
88-
self.index_location_given = bool(index_location)
89+
self.index_download = self._fetch_index()
90+
self.index_location = self.index_download.path
8991

9092
def __del__(self):
91-
if self.index_location and not self.index_location_given:
92-
os.remove(self.index_location)
93+
if self.index_download:
94+
rmtree(self.index_download.directory)
9395

9496
def _fetch_index(self, uri=DEBIAN_LSLR_URL):
9597
"""
96-
Return a temporary location where the debian index was saved.
98+
Fetch the Debian index at `uri` and return a Download with information
99+
about where it was saved.
97100
"""
98101
index = fetch_http(uri)
99-
return index.path
102+
return index
100103

101104
def get_packages(self, previous_index_last_modified_date=None, logger=None):
102105
"""Yield Package objects from debian index"""

0 commit comments

Comments
 (0)