util-vserver-0.30.208
[util-vserver.git] / contrib / yum-2.3.3-chroot.patch
diff --git a/contrib/yum-2.3.3-chroot.patch b/contrib/yum-2.3.3-chroot.patch
new file mode 100644 (file)
index 0000000..a12b73b
--- /dev/null
@@ -0,0 +1,200 @@
+--- yum-2.3.3/docs/yum.conf.5.chroot
++++ yum-2.3.3/docs/yum.conf.5
+@@ -23,8 +23,10 @@
+ following options:
+ .IP \fBcachedir\fR
+-Directory where yum should store its cache and db files. The default is
+-`/var/cache/yum'.
++Directory where yum should store its cache and db files. The default
++is `/var/cache/yum'. Unless the prefixes `hostfs://' or `chrootfs://'
++are used, some magic will be applied to determine the real path in
++combination with `--installroot'.
+ .IP \fBreposdir\fR
+ A list of directories where yum should look for .repo files which define
+@@ -34,6 +36,10 @@
+ repositories defined in /etc/yum.conf to form the complete set of repositories
+ that yum will use.
++Unless the prefixes `hostfs://' or `chrootfs://' are used, some magic
++will be applied to determine the real path in combination with
++`--installroot'.
++
+ .IP \fBdebuglevel\fR
+ Debug message output level. Practical range is 0\-10. Default is `2'.
+@@ -41,7 +47,10 @@
+ Error message output level. Practical range is 0\-10. Default is `2'.
+ .IP \fBlogfile\fR
+-Full directory and file name for where yum should write its log file.
++Full directory and file name for where yum should write its log
++file. Unless the prefixes `hostfs://' or `chrootfs://' are used,
++some magic will be applied to determine the real path in combination
++with `--installroot'.
+ .IP \fBgpgcheck\fR
+ Either `1' or `0'. This tells yum whether or not it should perform a GPG
+--- yum-2.3.3/yum/__init__.py.chroot
++++ yum-2.3.3/yum/__init__.py
+@@ -101,9 +101,8 @@
+         # read each of them in using confpp, then parse them same as any other repo
+         # section - as above.
+         for reposdir in self.conf.reposdir:
+-            if os.path.exists(self.conf.installroot + '/' + reposdir):
+-                reposdir = self.conf.installroot + '/' + reposdir
+-            
++            reposdir  = self.conf.getRootedPath(reposdir)
++
+             if os.path.isdir(reposdir):
+                 repofn = glob.glob(reposdir+'/*.repo')
+                 repofn.sort()
+@@ -425,17 +424,20 @@
+         self.pkgSack.excludeArchs(archlist)
+         self.log(3, 'Finished')
+         
++    def __getLockfileName(self):
++        lockfile = self.conf.configdata['lockfile']
++        return self.conf.getRootedPath(lockfile,
++                                       enforce_default  = True,
++                                       defaults_to_host = False)
+         
+-        
+-    def doLock(self, lockfile):
++    def doLock(self):
+         """perform the yum locking, raise yum-based exceptions, not OSErrors"""
+         
+         # if we're not root then we don't lock - just return nicely
+         if self.conf.getConfigOption('uid') != 0:
+             return
+-            
+-        root = self.conf.installroot
+-        lockfile = root + '/' + lockfile # lock in the chroot
++
++        lockfile=self.__getLockfileName()
+         
+         mypid=str(os.getpid())    
+         while not self._lock(lockfile, mypid, 0644):
+@@ -459,15 +461,14 @@
+                     msg = 'Existing lock %s: another copy is running. Aborting.' % lockfile
+                     raise Errors.LockError(0, msg)
+     
+-    def doUnlock(self, lockfile):
++    def doUnlock(self):
+         """do the unlock for yum"""
+         
+         # if we're not root then we don't lock - just return nicely
+         if self.conf.getConfigOption('uid') != 0:
+             return
+         
+-        root = self.conf.installroot
+-        lockfile = root + '/' + lockfile # lock in the chroot
++        lockfile=self.__getLockfileName()
+         
+         self._unlock(lockfile)
+         
+--- yum-2.3.3/yum/config.py.chroot
++++ yum-2.3.3/yum/config.py
+@@ -193,7 +193,8 @@
+                       
+         #defaults -either get them or set them
+         optionstrings = [('cachedir', '/var/cache/yum'), 
+-                         ('logfile', '/var/log/yum.log'), 
++                         ('logfile', '/var/log/yum.log'),
++                         ('lockfile', '/var/run/yum.pid'),
+                          ('reposdir', ['/etc/yum/repos.d', '/etc/yum.repos.d']),
+                          ('syslog_ident', None),
+                          ('syslog_facility', 'LOG_USER'),
+@@ -305,9 +306,7 @@
+         # do the dirs - set the root if there is one (grumble)
+         for option in ['cachedir', 'logfile']:
+-            path = self.configdata[option]
+-            root = self.configdata['installroot']
+-            rootedpath = root + path
++            rootedpath = self.getRootedPath(self.configdata[option])
+             self.configdata[option] = rootedpath
+             setattr(self, option, rootedpath)
+         
+@@ -340,6 +339,23 @@
+                         "All plugin search paths must be absolute")
++    def getRootedPath(self, path, enforce_default=False, defaults_to_host=False):
++      instroot = self.configdata['installroot']
++        if   path.startswith('hostfs://'):   res = path[9:]
++        elif path.startswith('chrootfs://'): res = instroot + '/' + path[11:]
++        else:
++          tmp = instroot + '/' +path
++
++            if enforce_default:
++                if defaults_to_host:    res = path
++                else:                   res = tmp
++            else:
++                if os.path.exists(tmp): res = tmp
++                elif defaults_to_host:  res = path
++                else:                   res = tmp
++
++      return res
++
+     def listConfigOptions(self):
+         """return list of options available for global config"""
+         return self.configdata.keys()
+@@ -719,9 +735,7 @@
+     # read each of them in using confpp, then parse them same as any other repo
+     # section - as above.
+-    reposdir = conf.reposdir
+-    if os.path.exists(conf.installroot + '/' + reposdir):
+-        reposdir = conf.installroot + '/' + reposdir
++    reposdir  = conf.getRootedPath(conf.reposdir)
+     
+     reposglob = reposdir + '/*.repo'
+     if os.path.exists(reposdir) and os.path.isdir(reposdir):
+--- yum-2.3.3/cli.py.chroot
++++ yum-2.3.3/cli.py
+@@ -108,7 +108,7 @@
+                 action="store_true", default=False, 
+                 help="run entirely from cache, don't update cache")
+         self.optparser.add_option("-c", "", dest="conffile", action="store", 
+-                default='/etc/yum.conf', help="config file location", 
++                default=None, help="config file location", 
+                 metavar=' [config file]')
+         self.optparser.add_option("-R", "", dest="sleeptime", action="store", 
+                 type='int', default=None, help="maximum command wait time",
+@@ -161,9 +161,12 @@
+         try: 
+             # If the conf file is inside the  installroot - use that.
+             # otherwise look for it in the normal root
+-            if opts.installroot:
+-                if os.access(opts.installroot+'/'+opts.conffile, os.R_OK):
++            if opts.conffile==None:
++                opts.conffile = '/etc/yum.conf'
++                if opts.installroot and os.access(opts.installroot+'/'+opts.conffile, os.R_OK):
+                     opts.conffile = opts.installroot+'/'+opts.conffile
++
++            if opts.installroot:
+                 root=opts.installroot
+             else:
+                 root = '/'
+--- yum-2.3.3/yummain.py.chroot
++++ yum-2.3.3/yummain.py
+@@ -60,7 +60,7 @@
+     def unlock():
+         try:
+             base.closeRpmDB()
+-            base.doUnlock(YUM_PID_FILE)
++            base.doUnlock()
+         except Errors.LockError, e:
+             sys.exit(200)
+@@ -78,7 +78,7 @@
+     except Errors.YumBaseError, e:
+         exFatal(e)
+     try:
+-        base.doLock(YUM_PID_FILE)
++        base.doLock()
+     except Errors.LockError, e:
+         base.errorlog(0,'%s' % e.msg)
+         sys.exit(200)