Linux / OS X changes

This commit is contained in:
Scott E. Graves
2018-12-09 19:27:04 -06:00
parent e95477f421
commit 642e60ce5f
5 changed files with 126 additions and 89 deletions

View File

@@ -4,6 +4,7 @@ const os = require('os');
const axios = require('axios');
const exec = require('child_process').exec;
const spawn = require('child_process').spawn;
const Constants = require('./src/constants');
const tryParse = (j, def) => {
try {
@@ -37,23 +38,15 @@ module.exports.detectRepertoryMounts = (directory, version) => {
});
process.on('exit', () => {
resolve(tryParse(result, {
Hyperspace: {
let defaultData = {};
for (const provider of Constants.PROVIDER_LIST) {
defaultData[provider] = {
Active: false,
Location: '',
PID: -1,
},
Sia: {
Active: false,
Location: '',
PID: -1,
},
SiaPrime: {
Active: false,
Location: '',
PID: -1,
},
}));
};
}
resolve(tryParse(result, defaultData));
});
process.unref();
});
@@ -163,29 +156,33 @@ module.exports.executeAsync = (command, args=[]) => {
});
};
module.exports.executeMount = (directory, version, storageType, location, exitCallback) => {
module.exports.executeMount = (directory, version, storageType, location, noConsoleSupported, exitCallback) => {
return new Promise((resolve) => {
const processOptions = {
detached: true,
detached: os.platform() === 'win32',
shell: true,
stdio: 'ignore',
};
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const args = [];
if (storageType.toLowerCase() === 'hyperspace') {
args.push('-hs');
} else if (storageType.toLowerCase() === 'siaprime') {
args.push('-sp');
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]);
}
if ((os.platform() === 'linux') || (os.platform() === 'darwin')) {
args.push('-o');
args.push('big_writes');
args.push('-f');
if (noConsoleSupported) {
args.push('-nc');
}
} else if (os.platform() === 'win32') {
args.push('-hidden');
}
args.push(location);
const process = new spawn(command, args, processOptions);
let process = new spawn(command, args, processOptions);
const pid = process.pid;
const timeout = setTimeout(() => {
@@ -196,11 +193,15 @@ module.exports.executeMount = (directory, version, storageType, location, exitCa
clearTimeout(timeout);
exitCallback(err, pid);
});
process.on('exit', (code) => {
clearTimeout(timeout);
exitCallback(code, pid);
});
process.unref();
if (os.platform() === 'win32') {
process.unref();
}
});
};
@@ -215,10 +216,8 @@ module.exports.getConfig = (directory, version, storageType) => {
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const args = [];
args.push('-dc');
if (storageType.toLowerCase() === 'hyperspace') {
args.push('-hs');
} else if (storageType.toLowerCase() === 'siaprime') {
args.push('-sp');
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]);
}
const process = new spawn(command, args, processOptions);
@@ -263,10 +262,8 @@ module.exports.getConfigTemplate = (directory, version, storageType) => {
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const args = [];
args.push('-gt');
if (storageType.toLowerCase() === 'hyperspace') {
args.push('-hs');
} else if (storageType.toLowerCase() === 'siaprime') {
args.push('-sp');
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]);
}
const process = new spawn(command, args, processOptions);
@@ -428,10 +425,8 @@ module.exports.setConfigValue = (name, value, directory, storageType, version) =
args.push('-set');
args.push(name);
args.push(value);
if (storageType.toLowerCase() === 'hyperspace') {
args.push('-hs');
} else if (storageType.toLowerCase() === 'siaprime') {
args.push('-sp');
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]);
}
const process = new spawn(command, args, processOptions);
@@ -448,23 +443,31 @@ module.exports.setConfigValue = (name, value, directory, storageType, version) =
});
};
module.exports.stopProcessByPID = pid => {
module.exports.stopMountProcess = (pid, location) => {
return new Promise((resolve, reject) => {
const processOptions = {
detached: true,
shell: false,
shell: true,
windowsHide: true,
};
const command = (os.platform() === 'win32') ? 'taskkill.exe' : 'kill';
let procName = 'kill';
if (location && location.length > 0) {
procName = 'fusermount';
}
const command = (os.platform() === 'win32') ? 'taskkill.exe' : procName;
const args = [];
if (os.platform() === 'win32') {
args.push('/PID');
}
args.push(pid);
if (procName === 'fusermount') {
args.push('-u');
args.push(location);
} else {
args.push(pid);
}
const process = new spawn(command, args, processOptions);
process.on('error', (err) => {
reject(err);
});