class CacheManager:
"""Manages all requests for cached objects."""
- def __init__(self, cache_dir, db, manager = None):
+ def __init__(self, cache_dir, db, other_dirs = [], manager = None):
self.cache_dir = cache_dir
+ self.other_dirs = other_dirs
+ self.all_dirs = self.other_dirs[:]
+ self.all_dirs.insert(0, self.cache_dir)
self.db = db
self.manager = manager
self.scanning = []
# Init the database, remove old files, init the HTTP dirs
- self.db.removeUntrackedFiles([self.cache_dir])
+ self.db.removeUntrackedFiles(self.all_dirs)
self.db.reconcileDirectories()
self.manager.setDirectories(self.db.getAllDirectories())
def scanDirectories(self):
"""Scan the cache directories, hashing new and rehashing changed files."""
assert not self.scanning, "a directory scan is already under way"
- self.scanning.append(self.cache_dir)
+ self.scanning = self.all_dirs[:]
self._scanDirectories()
def _scanDirectories(self, walker = None):
self.http_site = server.Site(self.http_server)
self.peers = PeerManager()
self.mirrors = MirrorManager(self.cache_dir)
- self.cache = CacheManager(self.cache_dir.child(download_dir), self.db, self)
+ other_dirs = [FilePath(f) for f in config.getstringlist('DEFAULT', 'OTHER_DIRS')]
+ self.cache = CacheManager(self.cache_dir.child(download_dir), self.db, other_dirs, self)
self.my_addr = None
def getSite(self):
# Directory to store the downloaded files in
'CACHE_DIR': home + '/.apt-dht/cache',
+ # Other directories containing packages to share with others
+ # WARNING: all files in these directories will be hashed and available
+ # for everybody to download
+ 'OTHER_DIRS': """""",
+
# User name to try and run as
'USERNAME': '',