skip duplicate util-vserver dir
[util-vserver.git] / contrib / yum-2.6.0-chroot.patch
1 --- yum-2.6.0/docs/yum.conf.5.chroot    2006-03-07 04:40:08.000000000 +0100
2 +++ yum-2.6.0/docs/yum.conf.5   2006-03-26 13:21:35.000000000 +0200
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 \fBkeepcache\fR
15  Either `1' or `0'. Determines whether or not yum keeps the cache
16 @@ -40,6 +42,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 @@ -47,7 +53,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.6.0/yum/__init__.py.chroot    2006-03-07 05:38:00.000000000 +0100
40 +++ yum-2.6.0/yum/__init__.py   2006-03-26 13:21:35.000000000 +0200
41 @@ -125,8 +125,7 @@
42          # (typically /etc/yum.repos.d and /etc/yum/repos.d)
43          parser = config.IncludedDirConfigParser(vars=self.yumvar)
44          for reposdir in self.conf.reposdir:
45 -            if os.path.exists(self.conf.installroot+'/'+reposdir):
46 -                reposdir = self.conf.installroot + '/' + reposdir
47 +            reposdir  = self.conf.getRootedPath(reposdir)
48  
49              if os.path.isdir(reposdir):
50                  #XXX: why can't we just pass the list of files?
51 @@ -482,16 +481,20 @@
52              
53          self.log(2, 'Finished')
54          
55 -    def doLock(self, lockfile):
56 +    def __getLockfileName(self):
57 +        lockfile = self.conf.lockfile
58 +        return self.conf.getRootedPath(lockfile,
59 +                                       enforce_default  = True,
60 +                                       defaults_to_host = False)
61 +        
62 +    def doLock(self):
63          """perform the yum locking, raise yum-based exceptions, not OSErrors"""
64          
65          # if we're not root then we don't lock - just return nicely
66          if self.conf.uid != 0:
67              return
68              
69 -        root = self.conf.installroot
70 -        lockfile = root + '/' + lockfile # lock in the chroot
71 -        lockfile = os.path.normpath(lockfile) # get rid of silly preceding extra /
72 +        lockfile = self.__getLockfileName()
73          
74          mypid=str(os.getpid())    
75          while not self._lock(lockfile, mypid, 0644):
76 @@ -515,15 +518,14 @@
77                      msg = 'Existing lock %s: another copy is running. Aborting.' % lockfile
78                      raise Errors.LockError(0, msg)
79      
80 -    def doUnlock(self, lockfile):
81 +    def doUnlock(self):
82          """do the unlock for yum"""
83          
84          # if we're not root then we don't lock - just return nicely
85          if self.conf.uid != 0:
86              return
87          
88 -        root = self.conf.installroot
89 -        lockfile = root + '/' + lockfile # lock in the chroot
90 +        lockfile=self.__getLockfileName()
91          
92          self._unlock(lockfile)
93          
94 --- yum-2.6.0/yum/config.py.chroot      2006-03-07 04:40:08.000000000 +0100
95 +++ yum-2.6.0/yum/config.py     2006-03-26 13:22:41.000000000 +0200
96 @@ -450,6 +450,27 @@
97          else:
98              raise Errors.ConfigError, 'No such option %s' % option
99  
100 +    def getRootedPath(self, path, enforce_default=False, defaults_to_host=False):
101 +       instroot = getattr(self, 'installroot', None)
102 +        if instroot==None:
103 +            return path
104 +
105 +        if   path.startswith('hostfs://'):   res = path[9:]
106 +        elif path.startswith('chrootfs://'): res = instroot + '/' + path[11:]
107 +        else:
108 +           tmp = instroot + '/' +path
109 +
110 +            if enforce_default:
111 +                if defaults_to_host:    res = path
112 +                else:                   res = tmp
113 +            else:
114 +                if os.path.exists(tmp): res = tmp
115 +                elif defaults_to_host:  res = path
116 +                else:                   res = tmp
117 +
118 +       return res
119
120
121  class EarlyConf(BaseConfig):
122      '''
123      Configuration option definitions for yum.conf's [main] section that are
124 @@ -474,6 +495,7 @@
125      cachedir = Option('/var/cache/yum')
126      keepcache = BoolOption(True)
127      logfile = Option('/var/log/yum.log')
128 +    lockfile = Option('/var/run/yum.pid')
129      reposdir = ListOption(['/etc/yum/repos.d', '/etc/yum.repos.d'])
130      syslog_ident = Option()
131      syslog_facility = Option('LOG_DAEMON')
132 @@ -580,9 +602,9 @@
133      yumconf.populate(confparser, 'main')
134  
135      # Apply the installroot to directory options
136 -    for option in ('cachedir', 'logfile'):
137 +    for option in ('cachedir', 'logfile', 'lockfile'):
138          path = getattr(yumconf, option)
139 -        setattr(yumconf, option, yumconf.installroot + path)
140 +        setattr(yumconf, option, yumconf.getRootedPath(path))
141      
142      # Check that plugin paths are all absolute
143      for path in yumconf.pluginpath:
144 --- yum-2.6.0/cli.py.chroot     2006-02-22 22:16:13.000000000 +0100
145 +++ yum-2.6.0/cli.py    2006-03-26 13:21:35.000000000 +0200
146 @@ -112,7 +112,7 @@
147                  action="store_true", default=False, 
148                  help="run entirely from cache, don't update cache")
149          self.optparser.add_option("-c", "", dest="conffile", action="store", 
150 -                default='/etc/yum.conf', help="config file location", 
151 +                default=None, help="config file location", 
152                  metavar=' [config file]')
153          self.optparser.add_option("-R", "", dest="sleeptime", action="store", 
154                  type='int', default=None, help="maximum command wait time",
155 @@ -165,9 +165,12 @@
156          try: 
157              # If the conf file is inside the  installroot - use that.
158              # otherwise look for it in the normal root
159 -            if opts.installroot:
160 -                if os.access(opts.installroot+'/'+opts.conffile, os.R_OK):
161 +            if opts.conffile==None:
162 +                opts.conffile = '/etc/yum.conf'
163 +                if opts.installroot and os.access(opts.installroot+'/'+opts.conffile, os.R_OK):
164                      opts.conffile = opts.installroot+'/'+opts.conffile
165 +
166 +            if opts.installroot:
167                  root=opts.installroot
168              else:
169                  root = '/'
170 --- yum-2.6.0/yummain.py.chroot 2005-12-13 09:35:41.000000000 +0100
171 +++ yum-2.6.0/yummain.py        2006-03-26 13:21:35.000000000 +0200
172 @@ -60,7 +60,7 @@
173      def unlock():
174          try:
175              base.closeRpmDB()
176 -            base.doUnlock(YUM_PID_FILE)
177 +            base.doUnlock()
178          except Errors.LockError, e:
179              sys.exit(200)
180  
181 @@ -83,7 +83,7 @@
182      except Errors.YumBaseError, e:
183          exFatal(e)
184      try:
185 -        base.doLock(YUM_PID_FILE)
186 +        base.doLock()
187      except Errors.LockError, e:
188          base.errorlog(0,'%s' % e.msg)
189          sys.exit(200)