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