yum-3.2.29_el66-chroot.patch (11375B)
1 Remove hardcoded '/var/lib/rpm' and use %_dbpath instead of 2 Index: yum-3.2.29/yum/rpmsack.py 3 =================================================================== 4 --- yum-3.2.29.orig/yum/rpmsack.py 5 +++ yum-3.2.29/yum/rpmsack.py 6 @@ -196,11 +196,8 @@ class RPMDBPackageSack(PackageSackBase): 7 self._loaded_gpg_keys = False 8 if cachedir is None: 9 cachedir = persistdir + "/rpmdb-indexes" 10 - self.setCacheDir(cachedir) 11 - if not os.path.normpath(persistdir).startswith(self.root): 12 - self._persistdir = root + '/' + persistdir 13 - else: 14 - self._persistdir = persistdir 15 + self._cachedir = cachedir 16 + self._persistdir = persistdir 17 self._have_cached_rpmdbv_data = None 18 self._cached_conflicts_data = None 19 # Store the result of what happens, if a transaction completes. 20 @@ -304,7 +301,7 @@ class RPMDBPackageSack(PackageSackBase): 21 22 # We are keeping some data from before, and sometimes (Eg. remove only) 23 # we never open the rpmdb again ... so get the mtime now. 24 - rpmdbfname = self.root + "/var/lib/rpm/Packages" 25 + rpmdbfname = self.root + rpm.expandMacro("%_dbpath/Packages") 26 self._cached_rpmdb_mtime = os.path.getmtime(rpmdbfname) 27 28 def _safe_del(x, y): 29 @@ -359,18 +356,6 @@ class RPMDBPackageSack(PackageSackBase): 30 pkg.yumdb_info._read_cached_data['checksum_type'] = T 31 pkg.yumdb_info._read_cached_data['checksum_data'] = D 32 33 - def setCacheDir(self, cachedir): 34 - """ Sets the internal cachedir value for the rpmdb, to be the 35 - "rpmdb-indexes" directory in the persisent yum storage. """ 36 - if not os.path.normpath(cachedir).startswith(self.root): 37 - self._cachedir = self.root + '/' + cachedir 38 - else: 39 - self._cachedir = '/' + cachedir 40 - 41 - if hasattr(self, 'yumdb'): # Need to keep this upto date, after init. 42 - version_path = os.path.normpath(self._cachedir + '/version') 43 - self.yumdb.conf.version_path = version_path 44 - 45 def readOnlyTS(self): 46 if not self.ts: 47 self.ts = initReadOnlyTransaction(root=self.root) 48 @@ -1065,7 +1050,7 @@ class RPMDBPackageSack(PackageSackBase): 49 # http://lists.rpm.org/pipermail/rpm-maint/2007-November/001719.html 50 # ...if anything gets implemented, we should change. 51 rpmdbvfname = self._cachedir + "/version" 52 - rpmdbfname = self.root + "/var/lib/rpm/Packages" 53 + rpmdbfname = self.root + rpm.expandMacro("%_dbpath/Packages") 54 55 if os.path.exists(rpmdbvfname) and os.path.exists(rpmdbfname): 56 # See if rpmdb has "changed" ... 57 @@ -1085,7 +1070,7 @@ class RPMDBPackageSack(PackageSackBase): 58 if self._cached_rpmdb_mtime is None: 59 return # We haven't loaded any packages!!! 60 61 - rpmdbfname = self.root + "/var/lib/rpm/Packages" 62 + rpmdbfname = self.root + rpm.expandMacro("%_dbpath/Packages") 63 if not os.path.exists(rpmdbfname): 64 return # haha 65 66 @@ -1307,7 +1292,7 @@ class RPMDBPackageSack(PackageSackBase): 67 self._name2pkg.setdefault(po.name, []).append(po) 68 self._tup2pkg[po.pkgtup] = po 69 if self.__cache_rpmdb__ and self._cached_rpmdb_mtime is None: 70 - rpmdbfname = self.root + "/var/lib/rpm/Packages" 71 + rpmdbfname = self.root + rpm.expandMacro("%_dbpath/Packages") 72 self._cached_rpmdb_mtime = os.path.getmtime(rpmdbfname) 73 74 return po 75 Index: yum-3.2.29/cli.py 76 =================================================================== 77 --- yum-3.2.29.orig/cli.py 78 +++ yum-3.2.29/cli.py 79 @@ -1570,13 +1570,14 @@ class YumOptionParser(OptionParser): 80 self._checkAbsInstallRoot(opts) 81 # If the conf file is inside the installroot - use that. 82 # otherwise look for it in the normal root 83 + if opts.conffile==None: 84 + opts.conffile = '/etc/yum/yum.conf' 85 + if opts.installroot: 86 + if os.access(opts.installroot+opts.conffile, os.R_OK): 87 + opts.conffile = opts.installroot+opts.conffile 88 + elif os.access(opts.installroot+'/etc/yum.conf', os.R_OK): 89 + opts.conffile = opts.installroot+'/etc/yum.conf' 90 if opts.installroot: 91 - if os.access(opts.installroot+'/'+opts.conffile, os.R_OK): 92 - opts.conffile = opts.installroot+'/'+opts.conffile 93 - elif opts.conffile == '/etc/yum/yum.conf': 94 - # check if /installroot/etc/yum.conf exists. 95 - if os.access(opts.installroot+'/etc/yum.conf', os.R_OK): 96 - opts.conffile = opts.installroot+'/etc/yum.conf' 97 root=opts.installroot 98 else: 99 root = '/' 100 @@ -1617,7 +1618,6 @@ class YumOptionParser(OptionParser): 101 action="store_true", 102 help=_("run entirely from system cache, don't update cache")) 103 group.add_option("-c", "--config", dest="conffile", 104 - default='/etc/yum/yum.conf', 105 help=_("config file location"), metavar='[config file]') 106 group.add_option("-R", "--randomwait", dest="sleeptime", type='int', 107 default=None, 108 Index: yum-3.2.29/yum/__init__.py 109 =================================================================== 110 --- yum-3.2.29.orig/yum/__init__.py 111 +++ yum-3.2.29/yum/__init__.py 112 @@ -487,8 +487,7 @@ class YumBase(depsolve.Depsolve): 113 # this check makes sure that our dirs exist properly. 114 # if they aren't in the installroot then don't prepend the installroot path 115 # if we don't do this then anaconda likes to not work. 116 - if os.path.exists(self.conf.installroot+'/'+reposdir): 117 - reposdir = self.conf.installroot + '/' + reposdir 118 + reposdir = self.conf.getRootedPath(reposdir) 119 reposdir = os.path.normpath(reposdir) 120 121 if os.path.isdir(reposdir): 122 @@ -1826,8 +1825,11 @@ much more problems). 123 exid = "yum.includepkgs.3" 124 self.pkgSack.addPackageExcluder(repo.id, exid, 'exclude.marked') 125 126 - def doLock(self, lockfile = YUM_PID_FILE): 127 + def doLock(self, lockfile = None): 128 """perform the yum locking, raise yum-based exceptions, not OSErrors""" 129 + 130 + if lockfile is None: 131 + lockfile = self.conf.lockfile 132 133 if self.conf.uid != 0: 134 # If we are a user, assume we are using the root cache ... so don't 135 @@ -1837,10 +1839,6 @@ much more problems). 136 root = self.conf.cachedir 137 # Don't want <cachedir>/var/run/yum.pid ... just: <cachedir>/yum.pid 138 lockfile = os.path.basename(lockfile) 139 - else: 140 - root = self.conf.installroot 141 - lockfile = root + '/' + lockfile # lock in the chroot 142 - lockfile = os.path.normpath(lockfile) # get rid of silly preceding extra / 143 144 mypid=str(os.getpid()) 145 while not self._lock(lockfile, mypid, 0644): 146 @@ -1890,8 +1888,7 @@ much more problems). 147 lockfile = None 148 149 if lockfile is not None: 150 - root = self.conf.installroot 151 - lockfile = root + '/' + lockfile # lock in the chroot 152 + pass 153 elif self._lockfile is None: 154 return # Don't delete other people's lock files on __del__ 155 else: 156 Index: yum-3.2.29/yum/config.py 157 =================================================================== 158 --- yum-3.2.29.orig/yum/config.py 159 +++ yum-3.2.29/yum/config.py 160 @@ -27,6 +27,7 @@ import rpm 161 import copy 162 import urlparse 163 import shlex 164 +from constants import YUM_PID_FILE 165 from parser import ConfigPreProcessor, varReplace 166 try: 167 from iniparse import INIConfig 168 @@ -624,6 +625,26 @@ class StartupConf(BaseConfig): 169 syslog_device = Option('/dev/log') 170 persistdir = Option('/var/lib/yum') 171 172 + def getRootedPath(self, path, enforce_default=False, defaults_to_host=False): 173 + instroot = getattr(self, 'installroot', None) 174 + if instroot==None: 175 + return path 176 + 177 + if path.startswith('hostfs://'): res = path[9:] 178 + elif path.startswith('chrootfs://'): res = instroot + '/' + path[11:] 179 + else: 180 + tmp = instroot + '/' + path 181 + 182 + if enforce_default: 183 + if defaults_to_host: res = path 184 + else: res = tmp 185 + else: 186 + if os.path.exists(tmp): res = tmp 187 + elif defaults_to_host: res = path 188 + else: res = tmp 189 + 190 + return res 191 + 192 class YumConf(StartupConf): 193 ''' 194 Configuration option definitions for yum.conf\'s [main] section. 195 @@ -638,6 +659,7 @@ class YumConf(StartupConf): 196 197 keepcache = BoolOption(True) 198 logfile = Option('/var/log/yum.log') 199 + lockfile = Option(YUM_PID_FILE) 200 reposdir = ListOption(['/etc/yum/repos.d', '/etc/yum.repos.d']) 201 202 commands = ListOption() 203 @@ -890,7 +912,7 @@ def readStartupConfig(configfile, root): 204 startupconf._parser = parser 205 # setup the release ver here 206 startupconf.releasever = _getsysver(startupconf.installroot, startupconf.distroverpkg) 207 - uuidfile = '%s/%s/uuid' % (startupconf.installroot, startupconf.persistdir) 208 + uuidfile = '%s/uuid' % (startupconf.persistdir,) 209 startupconf.uuid = get_uuid(uuidfile) 210 211 return startupconf 212 @@ -921,7 +943,7 @@ def readMainConfig(startupconf): 213 # Apply the installroot to directory options 214 def _apply_installroot(yumconf, option): 215 path = getattr(yumconf, option) 216 - ir_path = yumconf.installroot + path 217 + ir_path = yumconf.getRootedPath(path) 218 ir_path = ir_path.replace('//', '/') # os.path.normpath won't fix this and 219 # it annoys me 220 ir_path = varReplace(ir_path, yumvars) 221 @@ -929,7 +951,10 @@ def readMainConfig(startupconf): 222 223 # Read the FS yumvars 224 try: 225 - dir_fsvars = yumconf.installroot + "/etc/yum/vars/" 226 + if startupconf.config_file_path == '/etc/yum.conf': 227 + dir_fsvars = '/etc/yum/vars/' 228 + else: 229 + dir_fsvars = os.path.dirname(startupconf.config_file_path) + "/vars/" 230 fsvars = os.listdir(dir_fsvars) 231 except OSError: 232 fsvars = [] 233 @@ -945,7 +970,7 @@ def readMainConfig(startupconf): 234 yumvars[fsvar] = val 235 236 # These can use the above FS yumvars 237 - for option in ('cachedir', 'logfile', 'persistdir'): 238 + for option in ('cachedir', 'logfile', 'persistdir', 'lockfile'): 239 _apply_installroot(yumconf, option) 240 241 # Add in some extra attributes which aren't actually configuration values 242 Index: yum-3.2.29/yum/history.py 243 =================================================================== 244 --- yum-3.2.29.orig/yum/history.py 245 +++ yum-3.2.29/yum/history.py 246 @@ -659,10 +659,7 @@ class YumHistory: 247 self._conn = None 248 249 self.conf = yum.misc.GenericHolder() 250 - if not os.path.normpath(db_path).startswith(root): 251 - self.conf.db_path = os.path.normpath(root + '/' + db_path) 252 - else: 253 - self.conf.db_path = os.path.normpath('/' + db_path) 254 + self.conf.db_path = db_path 255 self.conf.writable = False 256 self.conf.readable = True 257