Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 01fe479

Browse files
committed
ImageFetcher: Don't open a new FTP connection for every fetch
Otherwise we can exceed FTP connection limits :)
1 parent c9102dd commit 01fe479

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

virtinst/ImageFetcher.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,39 @@ def hasFile(self, filename):
120120
request = urllib2.Request(path)
121121
request.get_method = lambda: "HEAD"
122122
urllib2.urlopen(request)
123-
except Exception:
124-
logging.debug("HTTP hasFile: didn't find %s" % path)
123+
except Exception, e:
124+
logging.debug("HTTP hasFile: didn't find %s: %s" % (path, str(e)))
125125
return False
126126
return True
127127

128128
class FTPImageFetcher(URIImageFetcher):
129129

130+
def __init__(self, location, scratchdir):
131+
URIImageFetcher.__init__(self, location, scratchdir)
132+
133+
self.ftp = None
134+
135+
def prepareLocation(self):
136+
url = urlparse.urlparse(self._make_path(""))
137+
self.ftp = ftplib.FTP(url[1])
138+
self.ftp.login()
139+
130140
def hasFile(self, filename):
131141
path = self._make_path(filename)
132-
133142
url = urlparse.urlparse(path)
143+
134144
try:
135-
ftp = ftplib.FTP(url[1])
136-
ftp.login()
137145
try:
138-
ftp.size(url[2]) # If a file
146+
# If it's a file
147+
self.ftp.size(url[2])
139148
except ftplib.all_errors:
140-
ftp.cwd(url[2]) # If a dir
141-
except ftplib.all_errors:
142-
logging.debug("FTP hasFile: couldn't access %s/%s" % \
143-
(url[1], url[2]))
149+
# If it's a dir
150+
self.ftp.cwd(url[2])
151+
except ftplib.all_errors, e:
152+
logging.debug("FTP hasFile: couldn't access %s: %s" %
153+
(path, str(e)))
144154
return False
155+
145156
return True
146157

147158
class LocalImageFetcher(ImageFetcher):

virtinst/OSDistro.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def _locationCheckWrapper(guest, baseuri, progresscb,
120120
try:
121121
fetcher.prepareLocation()
122122
except ValueError, e:
123+
logging.exception("Error preparing install location")
123124
raise ValueError(_("Invalid install location: ") + str(e))
124125

125126
try:

0 commit comments

Comments
 (0)