Skip to content

Commit

Permalink
fix: use bash -c because when using with flatpak-spawn it does not work
Browse files Browse the repository at this point in the history
fixes containers#4456

Signed-off-by: Florent Benoit <fbenoit@redhat.com>
  • Loading branch information
benoitf committed Oct 24, 2023
1 parent e60e031 commit 6039ab0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
11 changes: 3 additions & 8 deletions extensions/compose/src/cli-run.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,10 @@ test('success: installBinaryToSystem on linux with /usr/local/bin NOT created ye

// check called with admin being true
expect(extensionApi.process.exec).toBeCalledWith(
'exec',
'/bin/sh',
expect.arrayContaining([
'mkdir',
'-p',
'/usr/local/bin',
'&&',
'cp',
'test',
`${path.sep}usr${path.sep}local${path.sep}bin${path.sep}tmpBinary`,
'-c',
`mkdir -p /usr/local/bin && cp test ${path.sep}usr${path.sep}local${path.sep}bin${path.sep}tmpBinary`,
]),
expect.objectContaining({ isAdmin: true }),
);
Expand Down
13 changes: 11 additions & 2 deletions extensions/compose/src/cli-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,25 @@ export async function installBinaryToSystem(binaryPath: string, binaryName: stri
destinationPath = path.join(os.homedir(), 'AppData', 'Local', 'Microsoft', 'WindowsApps', `${binaryName}.exe`);
command = 'copy';
args = [`"${binaryPath}"`, `"${destinationPath}"`];
} else {
} else if (system === 'darwin') {
destinationPath = path.join(localBinDir, binaryName);
command = 'exec';
args = ['cp', binaryPath, destinationPath];
} else if (system === 'linux') {
destinationPath = path.join(localBinDir, binaryName);
command = '/bin/sh';
args = ['-c', `cp ${binaryPath} ${destinationPath}`];
}

// If on macOS or Linux, check to see if the /usr/local/bin directory exists,
// if it does not, then add mkdir -p /usr/local/bin to the start of the command when moving the binary.
if ((system === 'linux' || system === 'darwin') && !fs.existsSync(localBinDir)) {
args.unshift('mkdir', '-p', localBinDir, '&&');
if (system === 'darwin') {
args.unshift('mkdir', '-p', localBinDir, '&&');
} else {
// add mkdir -p /usr/local/bin just after the first item or args array (so it'll be in the -c shell instruction)
args[args.length - 1] = `mkdir -p /usr/local/bin && ${args[args.length - 1]}`;
}
}

try {
Expand Down

0 comments on commit 6039ab0

Please sign in to comment.