fix
[yum.git] / yum-3.2.25-chroot.patch
1 diff -ur yum-3.2.25.orig/cli.py yum-3.2.25/cli.py
2 --- yum-3.2.25.orig/cli.py      2009-12-14 15:33:38.708870457 +0100
3 +++ yum-3.2.25/cli.py   2009-12-14 15:34:58.904693320 +0100
4 @@ -1257,13 +1257,14 @@
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 is 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 @@ -1302,7 +1303,7 @@
26                  help=_("be tolerant of errors"))
27          group.add_option("-C", dest="cacheonly", action="store_true",
28                  help=_("run entirely from cache, don't update cache"))
29 -        group.add_option("-c", dest="conffile", default='/etc/yum/yum.conf',
30 +        group.add_option("-c", dest="conffile", default=None,
31                  help=_("config file location"), metavar=' [config file]')
32          group.add_option("-R", dest="sleeptime", type='int', default=None,
33                  help=_("maximum command wait time"), metavar=' [minutes]')
34 diff -ur yum-3.2.25.orig/yum/config.py yum-3.2.25/yum/config.py
35 --- yum-3.2.25.orig/yum/config.py       2009-12-14 15:33:38.711856129 +0100
36 +++ yum-3.2.25/yum/config.py    2009-12-14 15:39:44.204522759 +0100
37 @@ -600,6 +600,29 @@
38      syslog_ident = Option()
39      syslog_facility = Option('LOG_DAEMON')
40  
41 +
42 +
43 +    def getRootedPath(self, path, enforce_default=False, defaults_to_host=False):
44 +        instroot = self.installroot
45 +        if instroot is None:
46 +            return path
47 +
48 +        if   path.startswith('hostfs://'):   res = path[9:]
49 +        elif path.startswith('chrootfs://'): res = instroot + '/' + path[11:]
50 +        else:
51 +            tmp = instroot + '/' + path
52 +
53 +            if enforce_default:
54 +                if defaults_to_host:    res = path
55 +                else:                   res = tmp
56 +            else:
57 +                if os.path.exists(tmp): res = tmp
58 +                elif defaults_to_host:  res = path
59 +                else:                   res = tmp
60 +
61 +        return res
62 +
63 +
64  class YumConf(StartupConf):
65      '''
66      Configuration option definitions for yum.conf\'s [main] section.
67 @@ -613,6 +636,7 @@
68      persistdir = Option('/var/lib/yum')
69      keepcache = BoolOption(True)
70      logfile = Option('/var/log/yum.log')
71 +    lockfile = Option('/var/run/yum.pid')
72      reposdir = ListOption(['/etc/yum/repos.d', '/etc/yum.repos.d'])
73  
74      commands = ListOption()
75 @@ -827,9 +851,9 @@
76      yumconf.populate(startupconf._parser, 'main')
77  
78      # Apply the installroot to directory options
79 -    for option in ('cachedir', 'logfile', 'persistdir'):
80 +    for option in ('cachedir', 'logfile', 'lockfile', 'persistdir'):
81          path = getattr(yumconf, option)
82 -        ir_path = yumconf.installroot + path
83 +        ir_path = yumconf.getRootedPath(path)
84          ir_path = ir_path.replace('//', '/') # os.path.normpath won't fix this and
85                                               # it annoys me
86          ir_path = varReplace(ir_path, yumvars)
87 diff -ur yum-3.2.25.orig/yum/__init__.py yum-3.2.25/yum/__init__.py
88 --- yum-3.2.25.orig/yum/__init__.py     2009-12-14 15:33:38.711856129 +0100
89 +++ yum-3.2.25/yum/__init__.py  2009-12-14 15:36:05.306160196 +0100
90 @@ -386,8 +386,7 @@
91              # this check makes sure that our dirs exist properly.
92              # if they aren't in the installroot then don't prepend the installroot path
93              # if we don't do this then anaconda likes to not  work.
94 -            if os.path.exists(self.conf.installroot+'/'+reposdir):
95 -                reposdir = self.conf.installroot + '/' + reposdir
96 +            reposdir = self.conf.getRootedPath(reposdir)
97  
98              if os.path.isdir(reposdir):
99                  for repofn in sorted(glob.glob('%s/*.repo' % reposdir)):
100 @@ -1266,9 +1265,8 @@
101              return
102              
103          root = self.conf.installroot
104 -        lockfile = root + '/' + lockfile # lock in the chroot
105 -        lockfile = os.path.normpath(lockfile) # get rid of silly preceding extra /
106 -        
107 +        lockfile = self.conf.lockfile
108 +
109          mypid=str(os.getpid())    
110          while not self._lock(lockfile, mypid, 0644):
111              fd = open(lockfile, 'r')