From a0315dac8c91e388a81e91b5c1a982b4f631acbd Mon Sep 17 00:00:00 2001 From: Dan Streetman Date: Fri, 28 May 2021 16:26:18 -0400 Subject: [PATCH] archive: only download dsc file to the workdir from pull() method LP: #1928946 --- ubuntutools/archive.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/ubuntutools/archive.py b/ubuntutools/archive.py index d8427a3..2843537 100644 --- a/ubuntutools/archive.py +++ b/ubuntutools/archive.py @@ -37,6 +37,7 @@ import os.path import re import subprocess import sys +import tempfile from abc import (ABC, abstractmethod) @@ -52,7 +53,7 @@ from ubuntutools.lp.udtexceptions import (PackageNotFoundException, SeriesNotFoundException, PocketDoesNotExistError, InvalidDistroValueError) -from ubuntutools.misc import (download, verify_file_checksum, verify_file_checksums) +from ubuntutools.misc import (download, download_text, verify_file_checksum, verify_file_checksums) from ubuntutools.version import Version import logging @@ -180,11 +181,7 @@ class SourcePackage(ABC): # If provided a dscfile, process it now to set our source and version if self._dsc_source: - filename = os.path.basename(urlparse(self._dsc_source).path) - dst = os.path.join(self.workdir, filename) - download(self._dsc_source, dst) - with open(dst, 'rb') as f: - self._dsc = Dsc(f.read()) + self._dsc = Dsc(download_text(self._dsc_source, mode='rb')) self.source = self._dsc['Source'] self._version = Version(self._dsc['Version']) self._check_dsc_signature() @@ -282,11 +279,15 @@ class SourcePackage(ABC): def dsc(self): "Return the Dsc" if not self._dsc: + if self._dsc_source: + raise RuntimeError('Internal error: we have a dsc file but dsc not set') urls = self._source_urls(self.dsc_name) - self._download_file_from_urls(urls, self.dsc_pathname) - with open(self.dsc_pathname, 'rb') as f: - self._dsc = Dsc(f.read()) - self._check_dsc_signature() + with tempfile.TemporaryDirectory() as d: + tmpdsc = os.path.join(d, self.dsc_name) + self._download_file_from_urls(urls, tmpdsc) + with open(tmpdsc, 'rb') as f: + self._dsc = Dsc(f.read()) + self._check_dsc_signature() return self._dsc def getDistribution(self): @@ -424,6 +425,8 @@ class SourcePackage(ABC): def pull(self): "Pull into workdir" + with open(self.dsc_pathname, 'wb') as f: + f.write(self.dsc.raw_text) for entry in self.dsc['Files']: name = entry['name'] urls = self._source_urls(name)