diff --git a/src/mounts.js b/src/mounts.js index 25be721e8..b3ee39ca0 100644 --- a/src/mounts.js +++ b/src/mounts.js @@ -195,6 +195,20 @@ async function tryAddMount(mount, options) { if (constants.TEST) return; + // first try to mount at /mnt/volumes/-attempt + const originalHostPath = mount.hostPath; + mount.hostPath = originalHostPath + '-attempt'; + + const [attemptError] = await safe(shell.promises.sudo('addMount', [ ADD_MOUNT_CMD, renderMountFile(mount), options.timeout ], {})); + if (attemptError && attemptError.code === 2) throw new BoxError(BoxError.MOUNT_ERROR, 'Failed to unmount existing mount'); // at this point, the old mount config is still there + + const attemptStatus = await getStatus(mount.mountType, mount.hostPath); + await removeMount(mount); + if (attemptStatus.state !== 'active') throw new BoxError(BoxError.MOUNT_ERROR, `Failed to mount (${attemptStatus.state}): ${attemptStatus.message}`); + + // now create the real mount + mount.hostPath = originalHostPath; + const [error] = await safe(shell.promises.sudo('addMount', [ ADD_MOUNT_CMD, renderMountFile(mount), 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