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