r360 - in /debtorrent/trunk/DebTorrent/BT1: AptListener.py makemetafile.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Sun Jan 27 08:48:05 UTC 2008


Author: camrdale-guest
Date: Sun Jan 27 08:48:05 2008
New Revision: 360

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=360
Log:
Check the Release file headers before using sub-piece and piece ordering data.

Modified:
    debtorrent/trunk/DebTorrent/BT1/AptListener.py
    debtorrent/trunk/DebTorrent/BT1/makemetafile.py

Modified: debtorrent/trunk/DebTorrent/BT1/AptListener.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/AptListener.py?rev=360&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/AptListener.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/AptListener.py Sun Jan 27 08:48:05 2008
@@ -30,6 +30,7 @@
 from DebTorrent.HTTPCache import HTTPCache
 import os, logging
 from DebTorrent.__init__ import version, product_name,version_short
+from debian_bundle import deb822
 
 logger = logging.getLogger('DebTorrent.BT1.AptListener')
 
@@ -90,6 +91,10 @@
         from the cache. Keys are strings that are the path being requested, values
         are lists of L{DebTorrent.HTTPHandler.HTTPConnection} objects which are the
         requests that are pending for that path.
+    @type identifiers: C{dictionary}
+    @ivar identifiers: keys are the files found in Release files, and values
+        are the identifiers found in the Release file
+        (currently (C{string}, C{string}), the 'Origin' and 'Label' fields)
     @type request_queue: C{dictionary}
     @ivar request_queue: the pending HTTP package requests that are waiting for download.
         Keys are the file names (including mirror) requested, values are dictionaries
@@ -144,6 +149,7 @@
         else:
             self.Cache = HTTPCache(rawserver, self.handler.configdir.home_dir)
         self.cache_waiting = {}
+        self.identifiers = {}
         
         self.request_queue = {}
         rawserver.add_task(self.process_queue, 1)
@@ -367,9 +373,14 @@
                     self.Cache.download_get(path, self.get_cached_callback)
                     return None
             
+            # Save the identifiers from Release files
+            if path[-1] == 'Release':
+                self.save_identifiers(path, filename)
+                
             if path[-1] in ('Packages', 'Packages.gz', 'Packages.bz2'):
                 TorrentCreator(path, filename, self.start_torrent, 
-                               self.rawserver.add_task, self.Cache, self.config)
+                               self.rawserver.add_task, self.Cache, self.config,
+                               self.identifiers.get('/'.join(path), None))
 
             # Returning a file, so open the file to be returned
             if r[0] != 304:
@@ -405,10 +416,15 @@
             logger.warning('no connection exists to return the cached file on')
             return
 
+        # Save the identifiers from Release files
+        if r[0] in [200, 304] and path[-1] == 'Release':
+            self.save_identifiers(path, filename)
+                
         # If it's a torrent file, start it
-        if r[0] == 200 and path[-1] in ('Packages', 'Packages.gz', 'Packages.bz2'):
+        if r[0] in [200, 304] and path[-1] in ('Packages', 'Packages.gz', 'Packages.bz2'):
             TorrentCreator(path, filename, self.start_torrent,
-                           self.rawserver.add_task, self.Cache, self.config)
+                           self.rawserver.add_task, self.Cache, self.config,
+                           self.identifiers.get('/'.join(path), None))
             
         if filename and r[0] != 304:
             # Returning a file, so open the file to be returned
@@ -421,6 +437,29 @@
                 continue
             
             connection.answer(r, httpreq)
+
+    def save_identifiers(self, path, filename):
+        """Save the identifiers from a Release file for later downloads.
+        
+        @type path: C{list} of C{string}
+        @param path: the path of the Release file to download, starting with the mirror name
+        @type filename: C{string}
+        @param filename: the file containing the successfully downloaded Release file
+        
+        """
+
+        f = open(filename, 'r')
+        rel = deb822.Release(f)
+        identifier = (rel.get('Origin', ''), rel.get('Label', ''))
+
+        # Read the Packages file names
+        for file in rel.get('MD5Sum', []):
+            self.identifiers['/'.join(path[:-1]) + '/' + file['name']] = identifier
+        for file in rel.get('SHA1', []):
+            self.identifiers['/'.join(path[:-1]) + '/' + file['name']] = identifier
+        for file in rel.get('SHA256', []):
+            self.identifiers['/'.join(path[:-1]) + '/' + file['name']] = identifier
+        f.close()
             
     def get_package(self, connection, path, httpreq):
         """Download a package file from a torrent.

Modified: debtorrent/trunk/DebTorrent/BT1/makemetafile.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/makemetafile.py?rev=360&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/makemetafile.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/makemetafile.py Sun Jan 27 08:48:05 2008
@@ -670,7 +670,7 @@
     
     """
     
-    def __init__(self, path, filename, callback, sched, cache, config):
+    def __init__(self, path, filename, callback, sched, cache, config, identifier):
         """Process a downloaded Packages file and start the torrent making thread.
         
         @type path: C{list} of C{string}
@@ -685,6 +685,8 @@
         @param cache: the cache of downloaded files
         @type config: C{dictionary}
         @param config: the configuration parameters
+        @type identifier: C{string}
+        @param identifier: an identifier of the origin and label of the repository
         
         """
 
@@ -704,7 +706,7 @@
         self.torrent_file = None
         self.torrent_all_file = None
         
-        if 'dists' in self.path:
+        if identifier == ('Debian', 'Debian') and 'dists' in self.path:
             parts = self.path[:]
             try:
                 parts[parts.index('stable', parts.index('dists'))] = 'etch'




More information about the Debtorrent-commits mailing list