added patch for yum-3.2.4
[util-vserver.git] / contrib / yum-3.2.4-chroot.patch
1 --- yum-3.2.4/yum/__init__.py.chroot
2 +++ yum-3.2.4/yum/__init__.py
3 @@ -214,8 +214,7 @@ class YumBase(depsolve.Depsolve):
4          repo_config_age = self.conf.config_file_age
5          
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 @@ -664,11 +663,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 @@ -700,9 +697,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.4/yum/config.py.chroot
41 +++ yum-3.2.4/yum/config.py
42 @@ -469,6 +469,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 @@ -482,6 +502,7 @@ class YumConf(StartupConf):
70      persistdir = Option('/var/lib/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 @@ -615,7 +636,7 @@ def readMainConfig(startupconf):
78      yumconf.populate(startupconf._parser, 'main')
79  
80      # Apply the installroot to directory options
81 -    for option in ('cachedir', 'logfile', 'persistdir'):
82 +    for option in ('cachedir', 'logfile', 'persistdir', 'lockfile'):
83          path = getattr(yumconf, option)
84          setattr(yumconf, option, yumconf.installroot + path)
85      
86 --- yum-3.2.4/docs/yum.conf.5.chroot
87 +++ yum-3.2.4/docs/yum.conf.5
88 @@ -23,8 +23,10 @@ The [main] section must exist for yum to
89  following options:
90  
91  .IP \fBcachedir\fR
92 -Directory where yum should store its cache and db files. The default is
93 -`/var/cache/yum'.
94 +Directory where yum should store its cache and db files. The default
95 +is `/var/cache/yum'. Unless the prefixes `hostfs://' or `chrootfs://'
96 +are used, some magic will be applied to determine the real path in
97 +combination with `--installroot'.
98  
99  .IP \fBpersistdir\fR
100  Directory where yum should store information that should persist over multiple
101 @@ -44,6 +46,10 @@ documented in \fB[repository] options\fR
102  repositories defined in /etc/yum/yum.conf to form the complete set of
103  repositories that yum will use.
104  
105 +Unless the prefixes `hostfs://' or `chrootfs://' are used, some magic
106 +will be applied to determine the real path in combination with
107 +`--installroot'.
108 +
109  .IP \fBdebuglevel\fR
110  Debug message output level. Practical range is 0\-10. Default is `2'.
111  
112 @@ -51,7 +57,10 @@ Debug message output level. Practical ra
113  Error message output level. Practical range is 0\-10. Default is `2'.
114  
115  .IP \fBlogfile\fR
116 -Full directory and file name for where yum should write its log file.
117 +Full directory and file name for where yum should write its log
118 +file. Unless the prefixes `hostfs://' or `chrootfs://' are used,
119 +some magic will be applied to determine the real path in combination
120 +with `--installroot'.
121  
122  .IP \fBgpgcheck\fR
123  Either `1' or `0'. This tells yum whether or not it should perform a GPG
124 --- yum-3.2.4/cli.py.chroot
125 +++ yum-3.2.4/cli.py
126 @@ -1204,13 +1204,14 @@ class YumOptionParser(OptionParser):
127      def getRoot(self,opts):
128          # If the conf file is inside the  installroot - use that.
129          # otherwise look for it in the normal root
130 +        if opts.conffile==None:
131 +            opts.conffile = '/etc/yum/yum.conf'
132 +            if opts.installroot:
133 +                if os.access(opts.installroot+opts.conffile, os.R_OK):
134 +                    opts.conffile = opts.installroot+opts.conffile
135 +                elif os.access(opts.installroot+'/etc/yum.conf', os.R_OK):
136 +                    opts.conffile = opts.installroot+'/etc/yum.conf'
137          if opts.installroot:
138 -            if os.access(opts.installroot+'/'+opts.conffile, os.R_OK):
139 -                opts.conffile = opts.installroot+'/'+opts.conffile
140 -            elif opts.conffile == '/etc/yum/yum.conf':
141 -                # check if /installroot/etc/yum.conf exists.
142 -                if os.access(opts.installroot+'/etc/yum.conf', os.R_OK):
143 -                    opts.conffile = opts.installroot+'/etc/yum.conf'         
144              root=opts.installroot
145          else:
146              root = '/'
147 @@ -1231,7 +1232,7 @@ class YumOptionParser(OptionParser):
148                  help="be tolerant of errors")
149          self.add_option("-C", dest="cacheonly", action="store_true",
150                  help="run entirely from cache, don't update cache")
151 -        self.add_option("-c", dest="conffile", default='/etc/yum/yum.conf',
152 +        self.add_option("-c", dest="conffile", default=None,
153                  help="config file location", metavar=' [config file]')
154          self.add_option("-R", dest="sleeptime", type='int', default=None,
155                  help="maximum command wait time", metavar=' [minutes]')