convert more execSync to async
This commit is contained in:
+6
-7
@@ -71,7 +71,7 @@ function isManagedProvider(provider) {
|
||||
// nfs - no_root_squash is mode on server to map all root to 'nobody' user. all_squash does this for all users (making it like ftp)
|
||||
// sshfs - supports users/permissions
|
||||
// cifs - does not support permissions
|
||||
function renderMountFile(mount) {
|
||||
async function renderMountFile(mount) {
|
||||
assert.strictEqual(typeof mount, 'object');
|
||||
|
||||
const { name, hostPath, mountType, mountOptions } = mount;
|
||||
@@ -79,8 +79,7 @@ function renderMountFile(mount) {
|
||||
let options, what, type;
|
||||
switch (mountType) {
|
||||
case 'cifs': {
|
||||
const out = safe.child_process.execSync(`systemd-escape -p '${hostPath}'`, { encoding: 'utf8' }); // this ensures uniqueness of creds file
|
||||
if (!out) throw new BoxError(BoxError.FS_ERROR, `Could not determine credentials file name: ${safe.error.message}`);
|
||||
const out = shell.promises.exec('renderMountFile', `systemd-escape -p '${hostPath}'`, { encoding: 'utf8' }); // this ensures uniqueness of creds file
|
||||
const credentialsFilePath = path.join(paths.CIFS_CREDENTIALS_DIR, `${out.trim()}.cred`);
|
||||
if (!safe.fs.writeFileSync(credentialsFilePath, `username=${mountOptions.username}\npassword=${mountOptions.password}\n`, { mode: 0o600 })) throw new BoxError(BoxError.FS_ERROR, `Could not write credentials file: ${safe.error.message}`);
|
||||
|
||||
@@ -139,8 +138,7 @@ async function removeMount(mount) {
|
||||
const keyFilePath = path.join(paths.SSHFS_KEYS_DIR, `id_rsa_${mountOptions.host}`);
|
||||
safe.fs.unlinkSync(keyFilePath);
|
||||
} else if (mountType === 'cifs') {
|
||||
const out = safe.child_process.execSync(`systemd-escape -p '${hostPath}'`, { encoding: 'utf8' });
|
||||
if (!out) return;
|
||||
const out = await shell.promises.exec('removeMount', `systemd-escape -p '${hostPath}'`, { encoding: 'utf8' });
|
||||
const credentialsFilePath = path.join(paths.CIFS_CREDENTIALS_DIR, `${out.trim()}.cred`);
|
||||
safe.fs.unlinkSync(credentialsFilePath);
|
||||
}
|
||||
@@ -161,7 +159,7 @@ async function getStatus(mountType, hostPath) {
|
||||
let message;
|
||||
|
||||
if (state !== 'active') { // find why it failed
|
||||
const logsJson = safe.child_process.execSync(`journalctl -u $(systemd-escape -p --suffix=mount ${hostPath}) -n 10 --no-pager -o json`, { encoding: 'utf8' });
|
||||
const logsJson = await shell.promises.exec('getStatus', `journalctl -u $(systemd-escape -p --suffix=mount ${hostPath}) -n 10 --no-pager -o json`, { encoding: 'utf8' });
|
||||
|
||||
if (logsJson) {
|
||||
const lines = logsJson.trim().split('\n').map(l => JSON.parse(l)); // array of json
|
||||
@@ -196,7 +194,8 @@ async function tryAddMount(mount, options) {
|
||||
|
||||
if (constants.TEST) return;
|
||||
|
||||
const [error] = await safe(shell.promises.sudo('addMount', [ ADD_MOUNT_CMD, renderMountFile(mount), options.timeout ], {}));
|
||||
const mountFileContents = await renderMountFile(mount);
|
||||
const [error] = await safe(shell.promises.sudo('addMount', [ ADD_MOUNT_CMD, mountFileContents, options.timeout ], {}));
|
||||
if (error && error.code === 2) throw new BoxError(BoxError.MOUNT_ERROR, 'Failed to unmount existing mount'); // at this point, the old mount config is still there
|
||||
|
||||
if (options.skipCleanup) return;
|
||||
|
||||
Reference in New Issue
Block a user