gentoo: use /var/run for new /run compatibility
[util-vserver.git] / contrib / yum-2.3.4-chroot.patch
1 --- yum-2.3.4/docs/yum.conf.5.chroot
2 +++ yum-2.3.4/docs/yum.conf.5
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.4/yum/__init__.py.chroot
40 +++ yum-2.3.4/yum/__init__.py
41 @@ -102,9 +102,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 @@ -426,18 +425,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 -        lockfile = os.path.normpath(lockfile) # get rid of silly preceding extra /
75 +        lockfile = self.__getLockfileName()
76          
77          mypid=str(os.getpid())    
78          while not self._lock(lockfile, mypid, 0644):
79 @@ -461,15 +462,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.4/yum/config.py.chroot
98 +++ yum-2.3.4/yum/config.py
99 @@ -205,7 +205,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 @@ -318,9 +319,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 @@ -358,6 +357,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 @@ -749,8 +765,7 @@
145  
146      reposdirs = []
147      for dir in conf.reposdir:
148 -        if os.path.exists(conf.installroot + '/' + dir):
149 -            reposdirs.append(conf.installroot + '/' + dir)
150 +        reposdirs.append(conf.getRootedPath(dir))
151  
152      repofn = []
153      for reposdir in reposdirs:
154 --- yum-2.3.4/cli.py.chroot
155 +++ yum-2.3.4/cli.py
156 @@ -105,7 +105,7 @@
157                  action="store_true", default=False, 
158                  help="run entirely from cache, don't update cache")
159          self.optparser.add_option("-c", "", dest="conffile", action="store", 
160 -                default='/etc/yum.conf', help="config file location", 
161 +                default=None, help="config file location", 
162                  metavar=' [config file]')
163          self.optparser.add_option("-R", "", dest="sleeptime", action="store", 
164                  type='int', default=None, help="maximum command wait time",
165 @@ -158,9 +158,12 @@
166          try: 
167              # If the conf file is inside the  installroot - use that.
168              # otherwise look for it in the normal root
169 -            if opts.installroot:
170 -                if os.access(opts.installroot+'/'+opts.conffile, os.R_OK):
171 +            if opts.conffile==None:
172 +                opts.conffile = '/etc/yum.conf'
173 +                if opts.installroot and os.access(opts.installroot+'/'+opts.conffile, os.R_OK):
174                      opts.conffile = opts.installroot+'/'+opts.conffile
175 +
176 +            if opts.installroot:
177                  root=opts.installroot
178              else:
179                  root = '/'
180 --- yum-2.3.4/yummain.py.chroot
181 +++ yum-2.3.4/yummain.py
182 @@ -60,7 +60,7 @@
183      def unlock():
184          try:
185              base.closeRpmDB()
186 -            base.doUnlock(YUM_PID_FILE)
187 +            base.doUnlock()
188          except Errors.LockError, e:
189              sys.exit(200)
190  
191 @@ -78,7 +78,7 @@
192      except Errors.YumBaseError, e:
193          exFatal(e)
194      try:
195 -        base.doLock(YUM_PID_FILE)
196 +        base.doLock()
197      except Errors.LockError, e:
198          base.errorlog(0,'%s' % e.msg)
199          sys.exit(200)