From f83e9b0f84fdf3d3d98e7f2742a0512fd8aff7eb Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Mon, 14 Jan 2008 22:28:26 -0800 Subject: [PATCH] Added scanning of other directories for cached packages. --- apt_dht/CacheManager.py | 9 ++++++--- apt_dht/apt_dht.py | 3 ++- apt_dht/apt_dht_conf.py | 5 +++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/apt_dht/CacheManager.py b/apt_dht/CacheManager.py index 4fdcf40..c6aae89 100644 --- a/apt_dht/CacheManager.py +++ b/apt_dht/CacheManager.py @@ -147,14 +147,17 @@ class ProxyFileStream(stream.SimpleStream): 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()) @@ -162,7 +165,7 @@ class CacheManager: 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): diff --git a/apt_dht/apt_dht.py b/apt_dht/apt_dht.py index 2211c1d..9504f8a 100644 --- a/apt_dht/apt_dht.py +++ b/apt_dht/apt_dht.py @@ -34,7 +34,8 @@ class AptDHT: 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): diff --git a/apt_dht/apt_dht_conf.py b/apt_dht/apt_dht_conf.py index 98bbd88..621ef36 100644 --- a/apt_dht/apt_dht_conf.py +++ b/apt_dht/apt_dht_conf.py @@ -25,6 +25,11 @@ DEFAULTS = { # 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': '', -- 2.30.2