mounts: always return message when getting status
This commit is contained in:
@@ -189,15 +189,18 @@ async function getStatus(mountType, hostPath) {
|
||||
assert.strictEqual(typeof mountType, 'string');
|
||||
assert.strictEqual(typeof hostPath, 'string');
|
||||
|
||||
if (mountType === exports.MOUNT_TYPE_FILESYSTEM) return { state: 'active', message: 'Mounted' };
|
||||
if (mountType === exports.MOUNT_TYPE_FILESYSTEM) {
|
||||
const exists = safe.fs.existsSync(hostPath);
|
||||
return { state: exists ? 'active' : 'inactive', message: exists ? '' : `${hostPath} not found: ${safe.error.message}` };
|
||||
}
|
||||
|
||||
const [error] = await safe(shell.spawn('mountpoint', [ '-q', '--', hostPath ], { timeout: 5000, encoding: 'utf8' }));
|
||||
const state = error ? 'inactive' : 'active';
|
||||
|
||||
if (mountType === 'mountpoint') return { state, message: state === 'active' ? 'Mounted' : 'Not mounted' };
|
||||
if (mountType === 'mountpoint') return { state, message: state === 'active' ? '' : 'Not mounted' };
|
||||
|
||||
// we used to rely on "systemctl show -p ActiveState" output before but some mounts like sshfs.fuse show the status as "active" event though the mount commant failed (on ubuntu 18)
|
||||
let message;
|
||||
let message = '';
|
||||
|
||||
if (state !== 'active') { // find why it failed
|
||||
const unitName = await shell.spawn('systemd-escape', ['-p', '--suffix=mount', hostPath], { encoding: 'utf8' });
|
||||
@@ -221,8 +224,6 @@ async function getStatus(mountType, hostPath) {
|
||||
if (end !== -1) message = lines.slice(start, end+1).map(line => line['MESSAGE']).join('\n');
|
||||
}
|
||||
if (!message) message = `Could not determine mount failure reason. ${safe.error ? safe.error.message : ''}`;
|
||||
} else {
|
||||
message = 'Mounted';
|
||||
}
|
||||
|
||||
return { state, message };
|
||||
|
||||
Reference in New Issue
Block a user