Skip to content

Commit 1b1535a

Browse files
committed
fix regression in chroot handling (issue #100)
1 parent bb21e29 commit 1b1535a

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/actions/rebuild.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ def main():
119119
shutil.rmtree(confdir)
120120
os.makedirs(confdir)
121121
try:
122-
misc.chroot_exec('zcat ' + initrd.lstrip(config.FILESYSTEM_DIR) + ' | ' + ' cpio --quiet -id conf/uuid.conf', shell=True)
122+
misc.chroot_exec('zcat ' + initrd.lstrip(config.FILESYSTEM_DIR) + ' | ' + ' cpio --quiet -id conf/uuid.conf', \
123+
shell=True, cwd=config.FILESYSTEM_DIR)
123124
kernel = re.search('initrd.img-*.*.*-*-(.*)', initrd).group(1)
124125
message.sub_debug('Kernel', kernel)
125126
misc.copy_file(confdir + '/uuid.conf', misc.join_paths(config.ISO_DIR, \

src/lib/misc.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def dir_current():
111111
cwd = '/'
112112
return cwd
113113

114-
def system_command(command, shell=False, cwd=None, catch=False, env=None):
114+
def system_command(command, shell=False, cwd=None, env=None):
115115
if not cwd:
116116
cwd = dir_current()
117117
elif not os.path.isdir(cwd):
@@ -120,7 +120,7 @@ def system_command(command, shell=False, cwd=None, catch=False, env=None):
120120
env = os.environ
121121
if isinstance(command, str) and not shell:
122122
command = shlex.split(command)
123-
if catch or CATCH:
123+
if CATCH:
124124
pipe = subprocess.Popen(command, stderr=subprocess.PIPE, \
125125
shell=shell, cwd=cwd, env=env)
126126
pipe.wait()
@@ -130,12 +130,16 @@ def system_command(command, shell=False, cwd=None, catch=False, env=None):
130130
else:
131131
return subprocess.check_call(command, shell=shell, cwd=cwd, env=env)
132132

133-
def chroot_exec(command, prepare=True, mount=True, output=False, xnest=False, shell=False):
133+
def chroot_exec(command, prepare=True, mount=True, output=False, xnest=False, shell=False, cwd=None):
134134
out = None
135135
mount = whereis('mount')
136136
umount = whereis('umount')
137137
chroot = whereis('chroot')
138-
chroot_command = [chroot, config.FILESYSTEM_DIR]
138+
if isinstance(command, str):
139+
chroot_command = '%s %s %s' % (chroot, config.FILESYSTEM_DIR, command)
140+
else:
141+
chroot_command = [chroot, config.FILESYSTEM_DIR]
142+
chroot_command.extend(command)
139143
try:
140144
if prepare:
141145
resolv = '%s/etc/resolv.conf' % config.FILESYSTEM_DIR
@@ -201,14 +205,11 @@ def chroot_exec(command, prepare=True, mount=True, output=False, xnest=False, sh
201205
environment['DEBCONF_NONINTERACTIVE_SEEN'] = 'true'
202206
environment['DEBCONF_NOWARNINGS'] = 'true'
203207

204-
if isinstance(command, str):
205-
command = shlex.split(command)
206-
chroot_command.extend(command)
207208
if output:
208209
out = get_output(chroot_command)
209210
else:
210211
system_command(chroot_command, shell=shell, \
211-
env=environment)
212+
env=environment, cwd=cwd)
212213
finally:
213214
if mount:
214215
for s in reversed(pseudofs):

0 commit comments

Comments
 (0)