shell: add explicit bash() function

This commit is contained in:
Girish Ramakrishnan
2024-10-16 10:25:07 +02:00
parent d66db8ca40
commit df5ba25010
10 changed files with 46 additions and 63 deletions

View File

@@ -80,7 +80,7 @@ async function clear() {
await fs.promises.writeFile('/tmp/extra.cnf', `[client]\nhost=${gDatabase.hostname}\nuser=${gDatabase.username}\npassword=${gDatabase.password}\ndatabase=${gDatabase.name}`, 'utf8');
const cmd = 'mysql --defaults-extra-file=/tmp/extra.cnf -Nse "SHOW TABLES" | grep -v "^migrations$" | while read table; do mysql --defaults-extra-file=/tmp/extra.cnf -e "SET FOREIGN_KEY_CHECKS = 0; TRUNCATE TABLE $table"; done';
await shell.exec(cmd, { shell: '/bin/bash' });
await shell.bash(cmd, {});
}
async function query() {
@@ -136,9 +136,8 @@ async function importFromFile(file) {
assert.strictEqual(typeof file, 'string');
const cmd = `/usr/bin/mysql -h "${gDatabase.hostname}" -u ${gDatabase.username} -p${gDatabase.password} ${gDatabase.name} < ${file}`;
await query('CREATE DATABASE IF NOT EXISTS box');
const [error] = await safe(shell.exec(cmd, { shell: '/bin/bash' }));
const [error] = await safe(shell.bash(cmd, {}));
if (error) throw new BoxError(BoxError.DATABASE_ERROR, error);
}
@@ -152,6 +151,6 @@ async function exportToFile(file) {
const cmd = `/usr/bin/mysqldump -h "${gDatabase.hostname}" -u root -p${gDatabase.password} ${colStats} --single-transaction --routines --triggers ${gDatabase.name} > "${file}"`;
const [error] = await safe(shell.exec(cmd, { shell: '/bin/bash' }));
const [error] = await safe(shell.bash(cmd, {}));
if (error) throw new BoxError(BoxError.DATABASE_ERROR, error);
}