yum-2.3.2-chroot.patch (7830B)
1 --- yum-2.3.2/docs/yum.conf.5.chroot 2005-03-25 11:12:20.000000000 +0100 2 +++ yum-2.3.2/docs/yum.conf.5 2005-04-08 18:27:12.000000000 +0200 3 @@ -23,8 +23,10 @@ 4 following options: 5 6 .IP \fBcachedir\fR 7 -Directory where yum should store its cache and db files. The default is 8 -`/var/cache/yum'. 9 +Directory where yum should store its cache and db files. The default 10 +is `/var/cache/yum'. Unless the prefixes `hostfs://' or `chrootfs://' 11 +are used, some magic will be applied to determine the real path in 12 +combination with `--installroot'. 13 14 .IP \fBreposdir\fR 15 A list of directories where yum should look for .repo files which define 16 @@ -34,6 +36,10 @@ 17 repositories defined in /etc/yum.conf to form the complete set of repositories 18 that yum will use. 19 20 +Unless the prefixes `hostfs://' or `chrootfs://' are used, some magic 21 +will be applied to determine the real path in combination with 22 +`--installroot'. 23 + 24 .IP \fBdebuglevel\fR 25 Debug message output level. Practical range is 0\-10. Default is `2'. 26 27 @@ -41,7 +47,10 @@ 28 Error message output level. Practical range is 0\-10. Default is `2'. 29 30 .IP \fBlogfile\fR 31 -Full directory and file name for where yum should write its log file. 32 +Full directory and file name for where yum should write its log 33 +file. Unless the prefixes `hostfs://' or `chrootfs://' are used, 34 +some magic will be applied to determine the real path in combination 35 +with `--installroot'. 36 37 .IP \fBgpgcheck\fR 38 Either `1' or `0'. This tells yum whether or not it should perform a GPG 39 --- yum-2.3.2/yum/__init__.py.chroot 2005-04-04 20:14:18.000000000 +0200 40 +++ yum-2.3.2/yum/__init__.py 2005-04-08 20:11:06.000000000 +0200 41 @@ -97,9 +97,8 @@ 42 # read each of them in using confpp, then parse them same as any other repo 43 # section - as above. 44 for reposdir in self.conf.reposdir: 45 - if os.path.exists(self.conf.installroot + '/' + reposdir): 46 - reposdir = self.conf.installroot + '/' + reposdir 47 - 48 + reposdir = self.conf.getRootedPath(reposdir) 49 + 50 if os.path.isdir(reposdir): 51 repofn = glob.glob(reposdir+'/*.repo') 52 repofn.sort() 53 @@ -405,17 +404,20 @@ 54 self.pkgSack.excludeArchs(archlist) 55 self.log(3, 'Finished') 56 57 + def __getLockfileName(self): 58 + lockfile = self.conf.configdata['lockfile'] 59 + return self.conf.getRootedPath(lockfile, 60 + enforce_default = True, 61 + defaults_to_host = False) 62 63 - 64 - def doLock(self, lockfile): 65 + def doLock(self): 66 """perform the yum locking, raise yum-based exceptions, not OSErrors""" 67 68 # if we're not root then we don't lock - just return nicely 69 if self.conf.getConfigOption('uid') != 0: 70 return 71 - 72 - root = self.conf.installroot 73 - lockfile = root + '/' + lockfile # lock in the chroot 74 + 75 + lockfile=self.__getLockfileName() 76 77 mypid=str(os.getpid()) 78 while not self._lock(lockfile, mypid, 0644): 79 @@ -439,15 +441,14 @@ 80 msg = 'Existing lock %s: another copy is running. Aborting.' % lockfile 81 raise Errors.LockError(0, msg) 82 83 - def doUnlock(self, lockfile): 84 + def doUnlock(self): 85 """do the unlock for yum""" 86 87 # if we're not root then we don't lock - just return nicely 88 if self.conf.getConfigOption('uid') != 0: 89 return 90 91 - root = self.conf.installroot 92 - lockfile = root + '/' + lockfile # lock in the chroot 93 + lockfile=self.__getLockfileName() 94 95 self._unlock(lockfile) 96 97 --- yum-2.3.2/yum/config.py.chroot 2005-03-28 00:01:22.000000000 +0200 98 +++ yum-2.3.2/yum/config.py 2005-04-08 20:09:25.000000000 +0200 99 @@ -193,7 +193,8 @@ 100 101 #defaults -either get them or set them 102 optionstrings = [('cachedir', '/var/cache/yum'), 103 - ('logfile', '/var/log/yum.log'), 104 + ('logfile', '/var/log/yum.log'), 105 + ('lockfile', '/var/run/yum.pid'), 106 ('reposdir', ['/etc/yum/repos.d', '/etc/yum.repos.d']), 107 ('syslog_ident', None), 108 ('syslog_facility', 'LOG_USER'), 109 @@ -304,9 +305,7 @@ 110 111 # do the dirs - set the root if there is one (grumble) 112 for option in ['cachedir', 'logfile']: 113 - path = self.configdata[option] 114 - root = self.configdata['installroot'] 115 - rootedpath = root + path 116 + rootedpath = self.getRootedPath(self.configdata[option]) 117 self.configdata[option] = rootedpath 118 setattr(self, option, rootedpath) 119 120 @@ -339,6 +338,23 @@ 121 "All plugin search paths must be absolute") 122 123 124 + def getRootedPath(self, path, enforce_default=False, defaults_to_host=False): 125 + instroot = self.configdata['installroot'] 126 + if path.startswith('hostfs://'): res = path[9:] 127 + elif path.startswith('chrootfs://'): res = instroot + '/' + path[11:] 128 + else: 129 + tmp = instroot + '/' +path 130 + 131 + if enforce_default: 132 + if defaults_to_host: res = path 133 + else: res = tmp 134 + else: 135 + if os.path.exists(tmp): res = tmp 136 + elif defaults_to_host: res = path 137 + else: res = tmp 138 + 139 + return res 140 + 141 def listConfigOptions(self): 142 """return list of options available for global config""" 143 return self.configdata.keys() 144 @@ -717,9 +733,7 @@ 145 # read each of them in using confpp, then parse them same as any other repo 146 # section - as above. 147 148 - reposdir = conf.reposdir 149 - if os.path.exists(conf.installroot + '/' + reposdir): 150 - reposdir = conf.installroot + '/' + reposdir 151 + reposdir = conf.getRootedPath(conf.reposdir) 152 153 reposglob = reposdir + '/*.repo' 154 if os.path.exists(reposdir) and os.path.isdir(reposdir): 155 --- yum-2.3.2/cli.py.chroot 2005-03-28 05:18:03.000000000 +0200 156 +++ yum-2.3.2/cli.py 2005-04-08 18:27:12.000000000 +0200 157 @@ -115,7 +115,7 @@ 158 sleeptime=0 159 root = '/' 160 installroot = None 161 - conffile = '/etc/yum.conf' 162 + conffile = None 163 164 try: 165 for o,a in gopts: 166 @@ -129,12 +129,14 @@ 167 168 # if the conf file is inside the installroot - use that. 169 # otherwise look for it in the normal root 170 + if conffile==None: 171 + conffile = '/etc/yum.conf' 172 + if installroot and os.access(installroot + '/' + conffile, os.R_OK): 173 + conffile = installroot + '/' + conffile 174 + 175 if installroot: 176 - if os.access(installroot + '/' + conffile, os.R_OK): 177 - conffile = installroot + '/' + conffile 178 - 179 - root = installroot 180 - 181 + root = installroot 182 + 183 try: 184 self.doConfigSetup(fn = conffile, root = root) 185 except yum.Errors.ConfigError, e: 186 --- yum-2.3.2/yummain.py.chroot 2005-03-27 07:39:17.000000000 +0200 187 +++ yum-2.3.2/yummain.py 2005-04-08 18:27:12.000000000 +0200 188 @@ -41,7 +41,7 @@ 189 def unlock(): 190 try: 191 base.closeRpmDB() 192 - base.doUnlock('/var/run/yum.pid') 193 + base.doUnlock() 194 except Errors.LockError, e: 195 sys.exit(200) 196 197 @@ -58,7 +58,7 @@ 198 sys.exit(1) 199 200 try: 201 - base.doLock('/var/run/yum.pid') 202 + base.doLock() 203 except Errors.LockError, e: 204 base.errorlog(0,'%s' % e.msg) 205 sys.exit(200)