On Thu, 2010-07-22 at 17:25 -0400, James Antill wrote: > > class RPMDBAdditionalDataPackage(object): > + > + # We do auto hardlink on these attributes > + _auto_hardlink_attrs = set(['from_repo', 'releasever', 'checksum_type', > + 'installed_by', 'changed_by', 'reason']) > + > def __init__(self, conf, pkgdir, yumdb_cache=None): > self._conf = conf > self._mydir = pkgdir > @@ -1497,6 +1502,41 @@ class RPMDBAdditionalDataPackage(object): > # so we make it generic. > self._yumdb_cache = yumdb_cache > > + def _auto_yumdb_cache(self, attr, value, fn, nlinks=1): > + """ Create a cache for writting yumdb data out, to use link() > instead of > + open()+write(). hardlink -c works better, but this is "free" and > + automatic. """ > + if self._yumdb_cache is None: > + return > + if nlinks <= 1 and attr not in self._auto_hardlink_attrs: > + return > + > + if attr not in self._yumdb_cache: > + self._yumdb_cache[attr] = {} > + if value in self._yumdb_cache[attr]: > + if self._yumdb_cache[attr][value][0] >= nlinks: > + # We already have a better cache file. > + return > + > + self._yumdb_cache[attr][value] = (nlinks, fn) > + > + def _auto_link_yumdb_cache(self, attr, value, fn): > + """ If we have a matching yumdb cache, link() to it instead of having > + to open()+write(). """ > + if self._yumdb_cache is None: > + return False > + if attr not in self._yumdb_cache: > + return False > + if value not in self._yumdb_cache[attr]: > + return False > + > + misc.unlink_f(fn + '.tmp') > + os.link(self._yumdb_cache[attr][value][1], fn + '.tmp') > + os.rename(fn + '.tmp', fn) > + self._read_cached_data[attr] = value > + > + return True > +
Seems like we would want to wrap the above in a try/except to catch random FS or other misc errors and do the normal write if it fails. You do treat it as a fast-path but a try/except would make it 'safer' and that'll protect us if anyone is doing something especially stupid with weird filesystems. -sv _______________________________________________ Yum-devel mailing list Yum-devel@lists.baseurl.org http://lists.baseurl.org/mailman/listinfo/yum-devel