#46: Fix Mount Manager unmount and mount detection

This commit is contained in:
2020-06-11 20:26:43 -05:00
parent 100f7758ce
commit 20e61be50f
2 changed files with 59 additions and 51 deletions

View File

@@ -62,6 +62,62 @@ const _vcRuntimeExists = () => {
});
};
const _detectRepertoryMounts = (version, providerList) => {
return new Promise((resolve, reject) => {
let mountState = {};
const defaultData = {};
for (const provider of providerList) {
defaultData[provider] = {
Active: false,
Location: '',
PID: -1,
};
}
const grabStatus = index => {
if (index >= providerList.length) {
resolve(mountState);
} else {
const provider = providerList[index];
const repertoryExec = _getRepertoryExec(version);
const processOptions = {
cwd: repertoryExec.working,
detached: true,
shell: false,
windowsHide: true,
};
const args = _getDefaultRepertoryArgs(provider, !Constants.PROVIDER_LIST.includes(provider));
args.push('-status');
const process = new spawn(repertoryExec.cmd, args, processOptions);
let result = '';
process.on('error', (err) => {
reject(err);
});
process.stdout.on('data', (d) => {
result += d;
});
process.on('exit', () => {
mountState[provider] = _tryParse(result, defaultData)[provider];
if (mountState[provider].Active &&
((mountState[provider].Location === 'elevating') || (mountState[provider].Location === ''))) {
setTimeout(() => {
grabStatus(index);
}, 2000);
} else {
grabStatus(++index);
}
});
process.unref();
}
};
grabStatus(0);
});
};
const _executeProcess = (command, working, args=[]) => {
return new Promise((resolve, reject) => {
let processOptions = {
@@ -253,54 +309,7 @@ module.exports.createSignatureFiles = (signature, publicKey) => {
};
};
module.exports.detectRepertoryMounts = (version, providerList) => {
return new Promise((resolve, reject) => {
let mountState = {};
const defaultData = {};
for (const provider of providerList) {
defaultData[provider] = {
Active: false,
Location: '',
PID: -1,
};
}
const grabStatus = index => {
if (index >= providerList.length) {
resolve(mountState);
} else {
const provider = providerList[index];
const repertoryExec = _getRepertoryExec(version);
const processOptions = {
cwd: repertoryExec.working,
detached: true,
shell: false,
windowsHide: true,
};
const args = _getDefaultRepertoryArgs(provider, !Constants.PROVIDER_LIST.includes(provider));
args.push('-status');
const process = new spawn(repertoryExec.cmd, args, processOptions);
let result = '';
process.on('error', (err) => {
reject(err);
});
process.stdout.on('data', (d) => {
result += d;
});
process.on('exit', () => {
mountState[provider] = _tryParse(result, defaultData)[provider];
grabStatus(++index);
});
process.unref();
}
};
grabStatus(0);
});
};
module.exports.detectRepertoryMounts = _detectRepertoryMounts;
module.exports.downloadFile = (url, destination, progressCallback, completeCallback) => {
try {