[yum-git] yum/misc.py yum/repos.py yum/yumRepo.py
Seth Vidal
skvidal at linux.duke.edu
Sat Feb 16 08:56:52 UTC 2008
yum/misc.py | 2 +-
yum/repos.py | 2 ++
yum/yumRepo.py | 36 +++++++++++++++++++++++++++++++++++-
3 files changed, 38 insertions(+), 2 deletions(-)
New commits:
commit 39f8447a7a71130d3f8025bbb3dc9e117ad9d9fb
Author: Seth Vidal <skvidal at fedoraproject.org>
Date: Sat Feb 16 03:46:38 2008 -0500
when we're running as a user or using a set cachedir
then we should attempt to make a copy of anything we can
from the systemwide cache dir. Essentially, we're making
an opportunistic grab of the md files which are on disk
for the yum-utils that can be run as a user
diff --git a/yum/misc.py b/yum/misc.py
index 710b006..4ee1b63 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -321,7 +321,7 @@ def getCacheDir(tmpdir='/var/tmp'):
# make the dir (tempfile.mkdtemp())
cachedir = tempfile.mkdtemp(prefix=prefix, dir=tmpdir)
return cachedir
-
+
def sortPkgObj(pkg1 ,pkg2):
"""sorts a list of yum package objects by name"""
if pkg1.name > pkg2.name:
diff --git a/yum/repos.py b/yum/repos.py
index 20a6a33..c356911 100644
--- a/yum/repos.py
+++ b/yum/repos.py
@@ -174,7 +174,9 @@ class RepoStorage:
"""sets the cachedir value in all repos"""
for repo in self.repos.values():
+ repo.old_base_cache_dir = repo.basecachedir
repo.basecachedir = cachedir
+
def setProgressBar(self, obj):
"""sets the progress bar for downloading files from repos"""
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index 269475f..8585510 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -42,6 +42,7 @@ import warnings
import glob
import shutil
+import stat
warnings.simplefilter("ignore", Errors.YumFutureDeprecationWarning)
@@ -478,7 +479,13 @@ class YumRepository(Repository, config.RepoConf):
if not os.path.exists(dir):
raise Errors.RepoError, \
"Cannot access repository dir %s" % dir
-
+ # if we're using a cachedir that's not the system one, copy over these
+ # basic items from the system one
+ self._preload_md_from_system_cache('repomd.xml')
+ self._preload_md_from_system_cache('cachecookie')
+ self._preload_md_from_system_cache('mirrorlist.txt')
+
+
def baseurlSetup(self):
warnings.warn('baseurlSetup() will go away in a future version of Yum.\n',
Errors.YumFutureDeprecationWarning, stacklevel=2)
@@ -923,6 +930,8 @@ class YumRepository(Repository, config.RepoConf):
if not os.path.exists(local):
local = local.replace('.bz2', '')
compressed = True
+ # if we can, make a copy of the system-wide-cache version of this file
+ self._preload_md_from_system_cache(os.path.basename(local))
if not self._checkMD(local, dbmdtype, openchecksum=compressed,
data=data, check_can_fail=True):
return None
@@ -1240,6 +1249,31 @@ class YumRepository(Repository, config.RepoConf):
return returnlist
+ def _preload_md_from_system_cache(self, filename):
+ """attempts to download the file from the system-wide cache, if possible"""
+ if not hasattr(self, 'old_base_cache_dir'):
+ return
+ if self.old_base_cache_dir == "":
+ return
+
+ glob_repo_cache_dir=os.path.join(self.old_base_cache_dir, self.id)
+ if not os.path.exists(glob_repo_cache_dir):
+ return
+ if os.path.normpath(glob_repo_cache_dir) == os.path.normpath(self.cachedir):
+ return
+
+ # copy repomd.xml, cachecookie and mirrorlist.txt
+ fn = glob_repo_cache_dir + '/' + filename
+ destfn = self.cachedir + '/' + os.path.basename(filename)
+ # don't copy it if the copy in our users dir is newer or equal
+ if not os.path.exists(fn):
+ return
+ if os.path.exists(destfn):
+ if os.stat(fn)[stat.ST_CTIME] <= os.stat(destfn)[stat.ST_CTIME]:
+ return
+ #print 'copying %s to %s' % (fn, destfn)
+ shutil.copy2(fn, destfn)
+
def getMirrorList(mirrorlist, pdict = None):
warnings.warn('getMirrorList() will go away in a future version of Yum.\n',
More information about the Yum-cvs-commits
mailing list