Skip to content

Commit a967e3c

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

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

minecode_pipelines/pipes/debian.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
# Visit https://github.com/aboutcode-org/scancode.io for support and download.
2222

2323
import gzip
24-
import os
2524
from datetime import datetime
25+
from shutil import rmtree
2626

2727
import debian_inspector
2828
from aboutcode import hashid
@@ -82,21 +82,23 @@ class DebianCollector:
8282

8383
def __init__(self, index_location=None):
8484
if index_location:
85+
self.index_download = None
8586
self.index_location = index_location
8687
else:
87-
self.index_location = self._fetch_index()
88-
self.index_location_given = bool(index_location)
88+
self.index_download = self._fetch_index()
89+
self.index_location = self.index_download.path
8990

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

9495
def _fetch_index(self, uri=DEBIAN_LSLR_URL):
9596
"""
96-
Return a temporary location where the debian index was saved.
97+
Fetch the Debian index at `uri` and return a Download with information
98+
about where it was saved.
9799
"""
98100
index = fetch_http(uri)
99-
return index.path
101+
return index
100102

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

0 commit comments

Comments
 (0)