]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - apt_p2p/CacheManager.py
Use the apt_p2p_conf config import rather than passing parameters around.
[quix0rs-apt-p2p.git] / apt_p2p / CacheManager.py
index ccf13c5e308f9d105e29e003a6f43fc9019171db..24c821eda49a9d220bec462c0914122500c39b1e 100644 (file)
@@ -19,6 +19,7 @@ from twisted.web2 import stream
 from twisted.web2.http import splitHostPort
 
 from Hash import HashObject
+from apt_p2p_conf import config
 
 DECOMPRESS_EXTS = ['.gz', '.bz2']
 DECOMPRESS_FILES = ['release', 'sources', 'packages']
@@ -206,22 +207,19 @@ class CacheManager:
     @ivar scanning: all the directories that are currectly being scanned or waiting to be scanned
     """
     
-    def __init__(self, cache_dir, db, other_dirs = [], manager = None):
+    def __init__(self, cache_dir, db, manager = None):
         """Initialize the instance and remove any untracked files from the DB..
         
         @type cache_dir: L{twisted.python.filepath.FilePath}
         @param cache_dir: the directory to use for storing all files
         @type db: L{db.DB}
         @param db: the database to use for tracking files and hashes
-        @type other_dirs: C{list} of L{twisted.python.filepath.FilePath}
-        @param other_dirs: the other directories that have shared files in them
-            (optional, defaults to only using the cache directory)
         @type manager: L{apt_p2p.AptP2P}
         @param manager: the main program object to send requests to
             (optional, defaults to not calling back with cached files)
         """
         self.cache_dir = cache_dir
-        self.other_dirs = other_dirs
+        self.other_dirs = [FilePath(f) for f in config.getstringlist('DEFAULT', 'OTHER_DIRS')]
         self.all_dirs = self.other_dirs[:]
         self.all_dirs.insert(0, self.cache_dir)
         self.db = db
@@ -307,7 +305,8 @@ class CacheManager:
                 url = 'http:/' + file.path[len(self.cache_dir.path):]
                 
             # Store the hashed file in the database
-            new_hash = self.db.storeFile(file, result.digest())
+            new_hash = self.db.storeFile(file, result.digest(),
+                                         ''.join(result.pieceDigests()))
             
             # Tell the main program to handle the new cache file
             df = self.manager.new_cached_file(file, result, new_hash, url, True)
@@ -402,7 +401,8 @@ class CacheManager:
             else:
                 log.msg('Hashed file to %s: %s' % (hash.hexdigest(), url))
                 
-            new_hash = self.db.storeFile(destFile, hash.digest())
+            new_hash = self.db.storeFile(destFile, hash.digest(),
+                                         ''.join(hash.pieceDigests()))
             log.msg('now avaliable: %s' % (url))
 
             if self.manager: