[yum-commits] 5 commits - docs/yum.conf.5 yum/config.py yum/__init__.py yum/packages.py yum/yumRepo.py

James Antill james at osuosl.org
Wed Apr 1 02:43:34 UTC 2015


 docs/yum.conf.5 |    7 +++++++
 yum/__init__.py |   12 ++++++++++++
 yum/config.py   |    5 +++++
 yum/packages.py |   29 ++++++++++++++++++++++++++++-
 yum/yumRepo.py  |   33 ++++++++++++++++++++++++++++++++-
 5 files changed, 84 insertions(+), 2 deletions(-)

New commits:
commit 4b4ae28c12ab96aa50ed0d29b47dc2c80236dadf
Merge: 6ea8a6c aceebbb
Author: James Antill <james at and.org>
Date:   Tue Mar 31 22:43:30 2015 -0400

    Merge branch 'master' of github.com:james-antill/yum
    
    * 'master' of github.com:james-antill/yum: (4 commits)
      Change config. for cashe, and add man page entry.
      ...

commit aceebbba446f14b8eb824e597436bf5efd9f962d
Author: James Antill <james at and.org>
Date:   Tue Mar 31 22:41:56 2015 -0400

    Change config. for cashe, and add man page entry.

diff --git a/docs/yum.conf.5 b/docs/yum.conf.5
index 62aa78e..22701e0 100644
--- a/docs/yum.conf.5
+++ b/docs/yum.conf.5
@@ -28,6 +28,13 @@ Directory where yum should store its cache and db files. The default is
 `/var/cache/yum'.
 
 .IP
+\fBcashe_root_dir\fR
+Directory where yum would initialize the cashe, should almost certainly be left
+at the default. The default is`/var/cache/CAShe'. Note that unlike all other
+configuration, this does not change with installroot, the reason is so that
+multiple install root can share the same data. See man cashe for more info.
+
+.IP
 \fBpersistdir\fR
 Directory where yum should store information that should persist over multiple
 runs. The default is `/var/lib/yum'.
diff --git a/yum/__init__.py b/yum/__init__.py
index ec59cd6..48956e9 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -404,7 +404,7 @@ class YumBase(depsolve.Depsolve):
 
         self._cashe = None
         if cashe is not None:
-            self._cashe = cashe.CAShe(self.conf.cashedir)
+            self._cashe = cashe.CAShe(self.conf.cashe_root_dir)
 
         # run the postconfig plugin hook
         self.plugins.run('postconfig')
diff --git a/yum/config.py b/yum/config.py
index fc1bdc4..529fd70 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -740,7 +740,11 @@ class YumConf(StartupConf):
     reset_nice = BoolOption(True)
 
     cachedir = Option('/var/cache/yum')
-    cashedir = Option('/var/cache/CAShe')
+
+    #  Name it differently from above, to avoid confusion.
+    #  Also probably not a good idea to change this anyway, much like above,
+    # so don't name it small.
+    cashe_root_dir = Option('/var/cache/CAShe')
 
     keepcache = BoolOption(True)
     logfile = Option('/var/log/yum.log')
commit 2f53727d3f3c47e794c95a4331c059ae8be9cbbc
Author: James Antill <james at and.org>
Date:   Tue Mar 31 22:41:33 2015 -0400

    Protect from failures on CAShe save.

diff --git a/yum/packages.py b/yum/packages.py
index 864d7c4..0856d12 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -1015,7 +1015,10 @@ class YumAvailablePackage(PackageObject, RpmBase):
         
         self._verify_local_pkg_cache = nst
         if self._cashe is not None and not self._cashe.exists:
-            self._cashe.save(self.localPkg())
+            try:
+                self._cashe.save(self.localPkg())
+            except:
+                pass
 
         return True
 
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index dc1d7db..3dd0646 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -2029,7 +2029,10 @@ Insufficient space in download directory %s
         obj = self._cashe.get(checksum_type, checksum_data)
         if obj.exists:
             return True
-        return obj.save(filename)
+        try:
+            return obj.save(filename)
+        except:
+            return None
 
     def _preload_from_cashe(self, checksum_type, checksum_data, filename):
         if not hasattr(self, '_cashe') or self._cashe is None:
commit e17424b34ed8409803b5e702b24f6d0051ca99ca
Author: James Antill <james at and.org>
Date:   Wed Mar 18 02:41:28 2015 -0400

    Add auto cashe cleanup, and fix package cashe saving in verify.

diff --git a/yum/__init__.py b/yum/__init__.py
index c62af2c..ec59cd6 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -1893,6 +1893,8 @@ much more problems).
                           
         if not self.ts.isTsFlagSet(rpm.RPMTRANS_FLAG_TEST):
             self.cleanUsedHeadersPackages()
+            if not self.conf.keepcache and self._cashe:
+                self._cashe.cleanup()
         
         for i in ('ts_all_fn', 'ts_done_fn'):
             if hasattr(cb, i):
diff --git a/yum/packages.py b/yum/packages.py
index 8365f16..864d7c4 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -972,7 +972,7 @@ class YumAvailablePackage(PackageObject, RpmBase):
 
         return self.hdrpath
     
-    def verifyLocalPkg(self, from_cashe=False):
+    def verifyLocalPkg(self, from_cashe=None):
         """check the package checksum vs the localPkg
            return True if pkg is good, False if not"""
 
@@ -1002,20 +1002,20 @@ class YumAvailablePackage(PackageObject, RpmBase):
         except Errors.MiscError:
             if from_cashe:
                 self._cashe.unlink()
-            elif nst.st_size >= self.packagesize:
-                return self.verifyLocalPkg() # Try: cashe
+            elif from_cashe is None and nst.st_size >= self.packagesize:
+                return self.verifyLocalPkg(from_cashe=False) # Try: cashe
             return False
         
         if filesum != csum:
             if from_cashe:
                 self._cashe.unlink()
-            elif nst.st_size >= self.packagesize:
-                return self.verifyLocalPkg() # Try: cashe
+            elif from_cashe is None and nst.st_size >= self.packagesize:
+                return self.verifyLocalPkg(from_cashe=False) # Try: cashe
             return False
         
         self._verify_local_pkg_cache = nst
-        if not from_cashe and self._cashe and not self._cashe.exists:
-                self._cashe.save(self.localPkg())
+        if self._cashe is not None and not self._cashe.exists:
+            self._cashe.save(self.localPkg())
 
         return True
 
commit f86643eda3f961d6fcfa0adde7717fb29d2f276a
Author: James Antill <james at and.org>
Date:   Tue Feb 24 01:22:38 2015 -0500

    Add CAShe config. and objects, use it for MD and packages.

diff --git a/yum/__init__.py b/yum/__init__.py
index 347aa7c..c62af2c 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -102,6 +102,11 @@ from weakref import proxy as weakref
 
 from urlgrabber.grabber import default_grabber
 
+try:
+    import cashe
+except ImportError:
+    cashe = None
+
 __version__ = '3.4.3'
 __version_info__ = tuple([ int(num) for num in __version__.split('.')])
 
@@ -397,6 +402,10 @@ class YumBase(depsolve.Depsolve):
         for pkgname in self.conf.history_record_packages:
             self.run_with_package_names.add(pkgname)
 
+        self._cashe = None
+        if cashe is not None:
+            self._cashe = cashe.CAShe(self.conf.cashedir)
+
         # run the postconfig plugin hook
         self.plugins.run('postconfig')
         #  Note that Pungi has historically replaced _getConfig(), and it sets
@@ -600,6 +609,7 @@ class YumBase(depsolve.Depsolve):
         repo.old_base_cache_dir = getattr(self, '_old_cachedir', '')
         repo.basecachedir = self.conf.cachedir
         repo.yumvar.update(self.conf.yumvar)
+        repo._cashe = self._cashe
         repo.cfg = parser
         # Enable parallel downloading
         repo._async = repo.async
diff --git a/yum/config.py b/yum/config.py
index efe7be9..fc1bdc4 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -740,6 +740,7 @@ class YumConf(StartupConf):
     reset_nice = BoolOption(True)
 
     cachedir = Option('/var/cache/yum')
+    cashedir = Option('/var/cache/CAShe')
 
     keepcache = BoolOption(True)
     logfile = Option('/var/log/yum.log')
diff --git a/yum/packages.py b/yum/packages.py
index b219ada..8365f16 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -905,6 +905,17 @@ class YumAvailablePackage(PackageObject, RpmBase):
         return self.checksums[0][1]
     checksum = property(_checksum)
 
+
+    def _get_cashe(self):
+        if not hasattr(self, '_cashe_obj'):
+            if hasattr(self.repo, '_cashe') and self.repo._cashe is not None:
+                (csum_type, csum) = self.returnIdSum()
+                self._cashe_obj = self.repo._cashe.get(csum_type, csum)
+            else:
+                self._cashe_obj = None
+        return self._cashe_obj
+    _cashe = property(_get_cashe)
+
     def getDiscNum(self):
         if self.basepath is None:
             return None
@@ -961,7 +972,7 @@ class YumAvailablePackage(PackageObject, RpmBase):
 
         return self.hdrpath
     
-    def verifyLocalPkg(self):
+    def verifyLocalPkg(self, from_cashe=False):
         """check the package checksum vs the localPkg
            return True if pkg is good, False if not"""
 
@@ -970,7 +981,10 @@ class YumAvailablePackage(PackageObject, RpmBase):
         try:
             nst = os.stat(self.localPkg())
         except OSError, e:
+            if self._cashe and self._cashe.load(self.localPkg()):
+                return self.verifyLocalPkg(from_cashe=True)
             return False
+
         if (hasattr(self, '_verify_local_pkg_cache') and
             self._verify_local_pkg_cache):
             ost = self._verify_local_pkg_cache
@@ -986,12 +1000,22 @@ class YumAvailablePackage(PackageObject, RpmBase):
             filesum = misc.checksum(csum_type, self.localPkg(),
                                     datasize=self.packagesize)
         except Errors.MiscError:
+            if from_cashe:
+                self._cashe.unlink()
+            elif nst.st_size >= self.packagesize:
+                return self.verifyLocalPkg() # Try: cashe
             return False
         
         if filesum != csum:
+            if from_cashe:
+                self._cashe.unlink()
+            elif nst.st_size >= self.packagesize:
+                return self.verifyLocalPkg() # Try: cashe
             return False
         
         self._verify_local_pkg_cache = nst
+        if not from_cashe and self._cashe and not self._cashe.exists:
+                self._cashe.save(self.localPkg())
 
         return True
 
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index b95b333..dc1d7db 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -1766,8 +1766,12 @@ Insufficient space in download directory %s
             fsize = misc.stat_f(file)
             if fsize is not None: # We just got an xattr, so it should be there
                 if size is None and l_csum == r_csum and fsize.st_size > 0:
+                    if not openchecksum:
+                        self._preload_to_cashe(r_ctype, r_csum, file)
                     return 1
                 if size == fsize.st_size and l_csum == r_csum:
+                    if not openchecksum:
+                        self._preload_to_cashe(r_ctype, r_csum, file)
                     return 1
             # Anything goes wrong, run the checksums as normal...
 
@@ -1780,6 +1784,8 @@ Insufficient space in download directory %s
 
         if l_csum == r_csum:
             _xattr_set_chksum(file, r_ctype, l_csum)
+            if not openchecksum:
+                self._preload_to_cashe(r_ctype, r_csum, file)
             return 1
         else:
             if check_can_fail:
@@ -1809,7 +1815,8 @@ Insufficient space in download directory %s
             return local
 
         if (os.path.exists(local) or
-            self._preload_md_from_system_cache(os.path.basename(local))):
+            self._preload_md_from_system_cache(os.path.basename(local)) or 
+            self._preload_md_from_cashe(mdtype, local)):
             if self._checkMD(local, mdtype, check_can_fail=True):
                 self.retrieved[mdtype] = 1
                 return local # it's the same return the local one
@@ -2016,6 +2023,27 @@ Insufficient space in download directory %s
            if possible"""
         return self._preload_file_from_system_cache(filename)
     
+    def _preload_to_cashe(self, checksum_type, checksum_data, filename):
+        if not hasattr(self, '_cashe') or self._cashe is None:
+            return False
+        obj = self._cashe.get(checksum_type, checksum_data)
+        if obj.exists:
+            return True
+        return obj.save(filename)
+
+    def _preload_from_cashe(self, checksum_type, checksum_data, filename):
+        if not hasattr(self, '_cashe') or self._cashe is None:
+            return False
+        obj = self._cashe.get(checksum_type, checksum_data)
+        return obj.load(filename)
+
+    def _preload_md_from_cashe(self, mdtype, filename):
+        """attempts to copy the metadata file from the system-wide cache,
+           if possible"""
+        thisdata = self.repoXML.getData(mdtype)
+        (checksum_type, checksum_data) = thisdata.checksum
+        return self._preload_from_cashe(checksum_type, checksum_data, filename)
+
     def _preload_pkg_from_system_cache(self, pkg):
         """attempts to copy the package from the system-wide cache,
            if possible"""


More information about the Yum-commits mailing list