yum-3.0.5-chroot.patch (6750B)
1 --- yum-3.0.5/docs/yum.conf.5.chroot 2007-01-31 22:41:38.000000000 +0100 2 +++ yum-3.0.5/docs/yum.conf.5 2007-03-31 10:29:52.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 \fBkeepcache\fR 15 Either `1' or `0'. Determines whether or not yum keeps the cache 16 @@ -40,6 +42,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 @@ -47,7 +53,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-3.0.5/yum/config.py.chroot 2007-01-31 22:41:38.000000000 +0100 40 +++ yum-3.0.5/yum/config.py 2007-03-31 10:29:52.000000000 +0200 41 @@ -464,6 +464,26 @@ 42 pluginpath = ListOption(['/usr/lib/yum-plugins']) 43 pluginconfpath = ListOption(['/etc/yum/pluginconf.d']) 44 45 + def getRootedPath(self, path, enforce_default=False, defaults_to_host=False): 46 + instroot = getattr(self, 'installroot', None) 47 + if instroot==None: 48 + return path 49 + 50 + if path.startswith('hostfs://'): res = path[9:] 51 + elif path.startswith('chrootfs://'): res = instroot + '/' + path[11:] 52 + else: 53 + tmp = instroot + '/' + path 54 + 55 + if enforce_default: 56 + if defaults_to_host: res = path 57 + else: res = tmp 58 + else: 59 + if os.path.exists(tmp): res = tmp 60 + elif defaults_to_host: res = path 61 + else: res = tmp 62 + 63 + return res 64 + 65 class YumConf(StartupConf): 66 ''' 67 Configuration option definitions for yum.conf\'s [main] section. 68 @@ -476,6 +496,7 @@ 69 cachedir = Option('/var/cache/yum') 70 keepcache = BoolOption(True) 71 logfile = Option('/var/log/yum.log') 72 + lockfile = Option('/var/run/yum.pid') 73 reposdir = ListOption(['/etc/yum/repos.d', '/etc/yum.repos.d']) 74 syslog_ident = Option() 75 syslog_facility = Option('LOG_DAEMON') 76 @@ -602,9 +623,9 @@ 77 yumconf.populate(startupconf._parser, 'main') 78 79 # Apply the installroot to directory options 80 - for option in ('cachedir', 'logfile'): 81 + for option in ('cachedir', 'logfile', 'lockfile'): 82 path = getattr(yumconf, option) 83 - setattr(yumconf, option, yumconf.installroot + path) 84 + setattr(yumconf, option, yumconf.getRootedPath(path)) 85 86 # Add in some extra attributes which aren't actually configuration values 87 yumconf.yumvar = yumvars 88 --- yum-3.0.5/yum/__init__.py.chroot 2007-03-14 20:49:53.000000000 +0100 89 +++ yum-3.0.5/yum/__init__.py 2007-03-31 10:29:52.000000000 +0200 90 @@ -176,8 +176,7 @@ 91 # (typically /etc/yum.repos.d and /etc/yum/repos.d) 92 parser = ConfigParser() 93 for reposdir in self.conf.reposdir: 94 - if os.path.exists(self.conf.installroot+'/'+reposdir): 95 - reposdir = self.conf.installroot + '/' + reposdir 96 + reposdir = self.conf.getRootedPath(reposdir) 97 98 if os.path.isdir(reposdir): 99 for repofn in glob.glob('%s/*.repo' % reposdir): 100 @@ -530,17 +529,15 @@ 101 102 self.verbose_logger.log(logginglevels.INFO_2, 'Finished') 103 104 - def doLock(self, lockfile = YUM_PID_FILE): 105 + def doLock(self): 106 """perform the yum locking, raise yum-based exceptions, not OSErrors""" 107 108 # if we're not root then we don't lock - just return nicely 109 if self.conf.uid != 0: 110 return 111 - 112 - root = self.conf.installroot 113 - lockfile = root + '/' + lockfile # lock in the chroot 114 - lockfile = os.path.normpath(lockfile) # get rid of silly preceding extra / 115 - 116 + 117 + lockfile = self.conf.lockfile 118 + 119 mypid=str(os.getpid()) 120 while not self._lock(lockfile, mypid, 0644): 121 fd = open(lockfile, 'r') 122 @@ -565,16 +562,15 @@ 123 msg = 'Existing lock %s: another copy is running. Aborting.' % lockfile 124 raise Errors.LockError(0, msg) 125 126 - def doUnlock(self, lockfile = YUM_PID_FILE): 127 + def doUnlock(self): 128 """do the unlock for yum""" 129 130 # if we're not root then we don't lock - just return nicely 131 if self.conf.uid != 0: 132 return 133 134 - root = self.conf.installroot 135 - lockfile = root + '/' + lockfile # lock in the chroot 136 - 137 + lockfile=self.conf.lockfile 138 + 139 self._unlock(lockfile) 140 141 def _lock(self, filename, contents='', mode=0777): 142 --- yum-3.0.5/cli.py.chroot 2007-03-12 21:35:46.000000000 +0100 143 +++ yum-3.0.5/cli.py 2007-03-31 10:31:23.000000000 +0200 144 @@ -132,7 +132,7 @@ 145 action="store_true", default=False, 146 help="run entirely from cache, don't update cache") 147 self.optparser.add_option("-c", "", dest="conffile", action="store", 148 - default='/etc/yum.conf', help="config file location", 149 + default=None, help="config file location", 150 metavar=' [config file]') 151 self.optparser.add_option("-R", "", dest="sleeptime", action="store", 152 type='int', default=None, help="maximum command wait time", 153 @@ -189,9 +189,12 @@ 154 155 # If the conf file is inside the installroot - use that. 156 # otherwise look for it in the normal root 157 - if opts.installroot: 158 - if os.access(opts.installroot+'/'+opts.conffile, os.R_OK): 159 + if opts.conffile==None: 160 + opts.conffile = '/etc/yum.conf' 161 + if opts.installroot and os.access(opts.installroot+'/'+opts.conffile, os.R_OK): 162 opts.conffile = opts.installroot+'/'+opts.conffile 163 + 164 + if opts.installroot: 165 root=opts.installroot 166 else: 167 root = '/'