]> git.mxchange.org Git - quix0rs-apt-p2p.git/commitdiff
Remove temporary files from the peer's download cache.
authorCameron Dale <camrdale@gmail.com>
Wed, 23 Apr 2008 22:50:14 +0000 (15:50 -0700)
committerCameron Dale <camrdale@gmail.com>
Wed, 23 Apr 2008 23:16:30 +0000 (16:16 -0700)
TODO
apt_p2p/PeerManager.py

diff --git a/TODO b/TODO
index 08125f3be934c556485f572b939eeb6a5086577d..10dae92ff0dfe61703d9c153c1d083e184ea3b85 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,7 +1,6 @@
 Some last few things to do before release.
 
 - Handle/investigate the HTTP client pipeline errors
-- remove files from the peer's download cache
 - update the modtime of files downloaded from peers
   - also set the Last-Modified header for the return to Apt
 
index d4c7aace9ad04dce45fceb1ac944c61803a7cc96..447e69759bcacd16f2d98f235447349479995776 100644 (file)
@@ -8,7 +8,7 @@ from binascii import b2a_hex, a2b_hex
 import sha
 
 from twisted.internet import reactor, defer
-from twisted.python import log
+from twisted.python import log, filepath
 from twisted.trial import unittest
 from twisted.web2 import stream
 from twisted.web2.http import Response, splitHostPort
@@ -91,11 +91,13 @@ class GrowingFileStream(stream.FileStream):
                     deferred.callback(b)
                 else:
                     # We're done
+                    self._close()
                     deferred = self.deferred
                     self.deferred = None
                     deferred.callback(None)
             else:
                 # We're done
+                self._close()
                 deferred = self.deferred
                 self.deferred = None
                 deferred.callback(None)
@@ -112,6 +114,7 @@ class GrowingFileStream(stream.FileStream):
         # If we don't have any available, we're done or deferred
         if readSize <= 0:
             if self.finished:
+                self._close()
                 return None
             else:
                 self.deferred = defer.Deferred()
@@ -124,6 +127,7 @@ class GrowingFileStream(stream.FileStream):
         if not bytesRead:
             # End of file was reached, we're done or deferred
             if self.finished:
+                self._close()
                 return None
             else:
                 self.deferred = defer.Deferred()
@@ -132,6 +136,12 @@ class GrowingFileStream(stream.FileStream):
             self.position += bytesRead
             return b
 
+    def _close(self):
+        """Close the temporary file and remove it."""
+        self.f.close()
+        filepath.FilePath(self.f.name).remove()
+        self.f = None
+        
 class StreamToFile:
     """Save a stream to a partial file and hash it.