added updated patches for yum. The yum-3.2.0 one is untested.
[util-vserver.git] / contrib / yum-3.2.0-chroot.patch
1 --- yum-3.2.0/yum/config.py.chroot
2 +++ yum-3.2.0/yum/config.py
3 @@ -464,6 +464,26 @@
4      pluginpath = ListOption(['/usr/share/yum-plugins', '/usr/lib/yum-plugins'])
5      pluginconfpath = ListOption(['/etc/yum/pluginconf.d'])
6  
7 +    def getRootedPath(self, path, enforce_default=False, defaults_to_host=False):
8 +        instroot = getattr(self, 'installroot', None)
9 +        if instroot==None:
10 +            return path
11 +
12 +        if   path.startswith('hostfs://'):   res = path[9:]
13 +        elif path.startswith('chrootfs://'): res = instroot + '/' + path[11:]
14 +        else:
15 +            tmp = instroot + '/' + path
16 +
17 +            if enforce_default:
18 +                if defaults_to_host:    res = path
19 +                else:                   res = tmp
20 +            else:
21 +                if os.path.exists(tmp): res = tmp
22 +                elif defaults_to_host:  res = path
23 +                else:                   res = tmp
24 +
25 +        return res
26 +
27  class YumConf(StartupConf):
28      '''
29      Configuration option definitions for yum.conf\'s [main] section.
30 @@ -476,6 +496,7 @@
31      cachedir = Option('/var/cache/yum')
32      keepcache = BoolOption(True)
33      logfile = Option('/var/log/yum.log')
34 +    lockfile = Option('/var/run/yum.pid')
35      reposdir = ListOption(['/etc/yum/repos.d', '/etc/yum.repos.d'])
36      syslog_ident = Option()
37      syslog_facility = Option('LOG_DAEMON')
38 @@ -605,9 +626,9 @@
39      yumconf.populate(startupconf._parser, 'main')
40  
41      # Apply the installroot to directory options
42 -    for option in ('cachedir', 'logfile'):
43 +    for option in ('cachedir', 'logfile', 'lockfile'):
44          path = getattr(yumconf, option)
45 -        setattr(yumconf, option, yumconf.installroot + path)
46 +        setattr(yumconf, option, yumconf.getRootedPath(path))
47      
48      # Add in some extra attributes which aren't actually configuration values 
49      yumconf.yumvar = yumvars
50 --- yum-3.2.0/yum/__init__.py.chroot
51 +++ yum-3.2.0/yum/__init__.py
52 @@ -201,8 +201,7 @@
53          # (typically /etc/yum/repos.d)
54          parser = ConfigParser()
55          for reposdir in self.conf.reposdir:
56 -            if os.path.exists(self.conf.installroot+'/'+reposdir):
57 -                reposdir = self.conf.installroot + '/' + reposdir
58 +            reposdir  = self.conf.getRootedPath(reposdir)
59  
60              if os.path.isdir(reposdir):
61                  for repofn in glob.glob('%s/*.repo' % reposdir):
62 @@ -632,17 +631,15 @@
63              
64          self.verbose_logger.log(logginglevels.INFO_2, 'Finished')
65          
66 -    def doLock(self, lockfile = YUM_PID_FILE):
67 +    def doLock(self):
68          """perform the yum locking, raise yum-based exceptions, not OSErrors"""
69          
70          # if we're not root then we don't lock - just return nicely
71          if self.conf.uid != 0:
72              return
73 -            
74 -        root = self.conf.installroot
75 -        lockfile = root + '/' + lockfile # lock in the chroot
76 -        lockfile = os.path.normpath(lockfile) # get rid of silly preceding extra /
77 -        
78 +
79 +        lockfile = self.conf.lockfile
80 +
81          mypid=str(os.getpid())    
82          while not self._lock(lockfile, mypid, 0644):
83              fd = open(lockfile, 'r')
84 @@ -667,16 +664,15 @@
85                      msg = 'Existing lock %s: another copy is running as pid %s. Aborting.' % (lockfile, oldpid)
86                      raise Errors.LockError(0, msg)
87      
88 -    def doUnlock(self, lockfile = YUM_PID_FILE):
89 +    def doUnlock(self):
90          """do the unlock for yum"""
91          
92          # if we're not root then we don't lock - just return nicely
93          if self.conf.uid != 0:
94              return
95          
96 -        root = self.conf.installroot
97 -        lockfile = root + '/' + lockfile # lock in the chroot
98 -        
99 +        lockfile=self.conf.lockfile
100 +
101          self._unlock(lockfile)
102          
103      def _lock(self, filename, contents='', mode=0777):
104 --- yum-3.2.0/docs/yum.conf.5.chroot
105 +++ yum-3.2.0/docs/yum.conf.5
106 @@ -23,8 +23,10 @@
107  following options:
108  
109  .IP \fBcachedir\fR
110 -Directory where yum should store its cache and db files. The default is
111 -`/var/cache/yum'.
112 +Directory where yum should store its cache and db files. The default
113 +is `/var/cache/yum'. Unless the prefixes `hostfs://' or `chrootfs://'
114 +are used, some magic will be applied to determine the real path in
115 +combination with `--installroot'.
116  
117  .IP \fBkeepcache\fR
118  Either `1' or `0'. Determines whether or not yum keeps the cache
119 @@ -40,6 +42,10 @@
120  repositories defined in /etc/yum/yum.conf to form the complete set of
121  repositories that yum will use.
122  
123 +Unless the prefixes `hostfs://' or `chrootfs://' are used, some magic
124 +will be applied to determine the real path in combination with
125 +`--installroot'.
126 +
127  .IP \fBdebuglevel\fR
128  Debug message output level. Practical range is 0\-10. Default is `2'.
129  
130 @@ -47,7 +53,10 @@
131  Error message output level. Practical range is 0\-10. Default is `2'.
132  
133  .IP \fBlogfile\fR
134 -Full directory and file name for where yum should write its log file.
135 +Full directory and file name for where yum should write its log
136 +file. Unless the prefixes `hostfs://' or `chrootfs://' are used,
137 +some magic will be applied to determine the real path in combination
138 +with `--installroot'.
139  
140  .IP \fBgpgcheck\fR
141  Either `1' or `0'. This tells yum whether or not it should perform a GPG
142 --- yum-3.2.0/cli.py.chroot
143 +++ yum-3.2.0/cli.py
144 @@ -1166,13 +1166,16 @@
145      def getRoot(self,opts):
146          # If the conf file is inside the  installroot - use that.
147          # otherwise look for it in the normal root
148 -        if opts.installroot:
149 -            if os.access(opts.installroot+'/'+opts.conffile, os.R_OK):
150 +        if opts.conffile==None:
151 +            opts.conffile = '/etc/yum.conf'
152 +            if opts.installroot and os.access(opts.installroot+'/'+opts.conffile, os.R_OK):
153                  opts.conffile = opts.installroot+'/'+opts.conffile
154              elif opts.conffile == '/etc/yum/yum.conf':
155                  # check if /installroot/etc/yum.conf exists.
156                  if os.access(opts.installroot+'/etc/yum.conf', os.R_OK):
157                      opts.conffile = opts.installroot+'/etc/yum.conf'         
158 +
159 +        if opts.installroot:
160              root=opts.installroot
161          else:
162              root = '/'
163 @@ -1195,7 +1198,7 @@
164                  action="store_true", default=False,
165                  help="run entirely from cache, don't update cache")
166          self.add_option("-c", "", dest="conffile", action="store", 
167 -                default='/etc/yum/yum.conf', help="config file location",
168 +                default=None, help="config file location",
169                  metavar=' [config file]')
170          self.add_option("-R", "", dest="sleeptime", action="store",
171                  type='int', default=None, help="maximum command wait time",