[apt-proxy-devel] r668 - trunk/apt_proxy

Chris Halls halls at alioth.debian.org
Fri Jul 13 12:49:12 UTC 2007


Author: halls
Date: Fri Jul 13 12:49:11 2007
New Revision: 668

Log:
Add support for removing entries from download queue


Modified:
   trunk/apt_proxy/fetchers.py

Modified: trunk/apt_proxy/fetchers.py
==============================================================================
--- trunk/apt_proxy/fetchers.py	(original)
+++ trunk/apt_proxy/fetchers.py	Fri Jul 13 12:49:11 2007
@@ -192,8 +192,9 @@
         self.fail_over(http.SERVICE_UNAVAILABLE, reason)
 
     def connected(self, result):
-        log.debug("Connected to "+ self.backendServer.uri, 'Fetcher')
-        self.download()
+        if self.fetcher:
+            log.debug("Connected to "+ self.backendServer.uri, 'Fetcher')
+            self.download()
 
     def download(self):
         mtime = self.cacheEntry.get_request_mtime()
@@ -459,6 +460,7 @@
         self.backendServer = backendServer
         self.isConnected = False
         self.instance = None
+        self.connector = False
 
     def connect(self):
         self.connectCallback = defer.Deferred()
@@ -478,24 +480,28 @@
         self.timeout = self.backendServer.backend.config.timeout
         if self.timeout:
             factory = policies.TimeoutFactory(factory, timeoutPeriod=self.timeout)
-        reactor.connectTCP(host, port, factory, self.backendServer.backend.config.timeout)
+        self.connector = reactor.connectTCP(host, port, factory, self.backendServer.backend.config.timeout)
         return self.connectCallback
 
     def buildProtocol(self, addr):
+        self.connector = None
         return FetcherHttpClient(self)
 
     def connected(self, connection):
         "Connection was made to HTTP backend (callback from HTTP client)"
         self.connection = connection
+        self.connector = None
         self.isConnected = True
         self.connectCallback.callback(None)
 
     def clientConnectionFailed(self, connector, reason):
         #self.instance.connectionFailed(reason)
         log.debug("clientConnectionFailed reason: %s" % (reason), "HttpFetcher")
+        self.connector = None
         self.connectCallback.errback(reason)
     def clientConnectionLost(self, connector, reason):
         log.debug("clientConnectionLost reason=%s" %(reason), "HttpFetcher")
+        self.connector = None
         if self.connection is not None and self.connection.fetcher is not None:
             self.connection.fetcher.connection_closed(self)
 
@@ -512,9 +518,11 @@
             fetcher.fetcher_internal_error("http_client self.connection == None")
 
     def disconnect(self):
-        if self.isConnected:
+        if self.connector:
+            self.connector.disconnect()
+        else:
             self.connection.transport.loseConnection()
-            self.isConnected = False
+        self.isConnected = False
 
 class FtpFetcher(protocol.Protocol):
     """
@@ -983,16 +991,20 @@
         self.timeoutCB = None
         if self.fetcher is not None:
             log.debug("closing fetcher [%s]" % (self.fetcher.backendServer), 'DownloadQueue')
-            self.fetcher.disconnect()
+            # set self.fetcher to None so any callback does not start a new download
+            fetcher = self.fetcher
             self.fetcher = None
+            fetcher.disconnect()
 
             if self.parent is not None:
                 self.parent.downloadQueueEmpty(self, self.parentId)
 
     def stop(self):
         log.debug("queue stop", 'DownloadQueue')
+        self.queue = []
         if self.timeoutCB is not None:
             self.timeoutCB.cancel()
+            self.timeoutCB = None
         self.closeFetcher()
 
 class DownloadQueuePerClient:



More information about the apt-proxy-devel mailing list