mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-11-25 10:20:16 -06:00
SEARCH-539
- Check disk space before enabling Electron-Search
This commit is contained in:
parent
3aa0d8b06f
commit
15dc549610
@ -87,6 +87,13 @@
|
||||
<div>
|
||||
<label for="batchNumber">Get Latest Message Timestamp</label>
|
||||
<button id='getLatestMessageTimestamp'>Click</button>
|
||||
</div>
|
||||
<br>
|
||||
<div>
|
||||
<label>Check Free Space: </label>
|
||||
<button id='checkFreeSpace'>Click</button>
|
||||
</div>
|
||||
<div>
|
||||
<div>
|
||||
<p>Results:</p>
|
||||
<p id="results"></p>
|
||||
@ -103,7 +110,8 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var search = new ssf.Search("16149077034436", "RSDFOiuVqF3WmY1pC4MP145qPOpUP6A4if27WG9y3fY=");
|
||||
var search = new ssf.Search("12345678910112", "jjjshdncbsjkieoalskcjdhsnahsadndfnusdfsdfsd=");
|
||||
var searchUtils = new ssf.SearchUtils();
|
||||
var buttonEl = document.getElementById('search');
|
||||
var merge = document.getElementById('merge');
|
||||
var buttonIndex = document.getElementById('index');
|
||||
@ -122,6 +130,7 @@
|
||||
var batchNumber = document.getElementById('batchNumber');
|
||||
var timestamp = document.getElementById('getLatestMessageTimestamp');
|
||||
var has = document.getElementById('has');
|
||||
var checkFreeSpace = document.getElementById('checkFreeSpace');
|
||||
|
||||
|
||||
buttonIndex.addEventListener('click', function () {
|
||||
@ -216,6 +225,14 @@
|
||||
resultsEl.innerHTML = 'Error: ' + err;
|
||||
});
|
||||
});
|
||||
|
||||
checkFreeSpace.addEventListener('click', function () {
|
||||
searchUtils.checkFreeSpace().then(function (res) {
|
||||
resultsEl.innerHTML = res ? "Free Disk Space Available" : "Insufficient Disk Space";
|
||||
}).catch(function (err) {
|
||||
resultsEl.innerHTML = err;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -136,6 +136,13 @@ function createAPI() {
|
||||
*/
|
||||
Search: remote.require('./search/search.js').Search,
|
||||
|
||||
/**
|
||||
* Provides api for search module utils
|
||||
* like checking free space / search user config data to the client app
|
||||
* details in ./search/searchUtils.js & ./search/searchConfig.js
|
||||
*/
|
||||
SearchUtils: remote.require('./search/searchUtils.js').SearchUtils,
|
||||
|
||||
/**
|
||||
* Function to clear the user index data
|
||||
*/
|
||||
|
@ -3,8 +3,7 @@ const app = electron.app;
|
||||
const path = require('path');
|
||||
const userData = path.join(app.getPath('userData'));
|
||||
const execPath = path.dirname(app.getPath('exe'));
|
||||
const isDevEnv = require('../utils/misc.js').isDevEnv;
|
||||
const isMac = require('../utils/misc.js').isMac;
|
||||
const { isDevEnv, isMac } = require('../utils/misc.js');
|
||||
|
||||
const INDEX_FOLDER_NAME = 'data';
|
||||
|
||||
@ -53,7 +52,8 @@ const searchConfig = {
|
||||
BATCH_RANDOM_INDEX_PATH_LENGTH: 20,
|
||||
LIBRARY_CONSTANTS: libraryPaths,
|
||||
FOLDERS_CONSTANTS: folderPaths,
|
||||
TAR_LZ4_EXT: '.tar.lz4'
|
||||
TAR_LZ4_EXT: '.tar.lz4',
|
||||
MINIMUM_DISK_SPACE: 300000000 // in bytes
|
||||
};
|
||||
|
||||
module.exports = searchConfig;
|
||||
|
30
js/search/searchUtils.js
Normal file
30
js/search/searchUtils.js
Normal file
@ -0,0 +1,30 @@
|
||||
const { checkDiskSpace } = require('./utils/checkDiskSpace.js');
|
||||
const searchConfig = require('./searchConfig.js');
|
||||
const { isMac } = require('../utils/misc.js');
|
||||
|
||||
class SearchUtils {
|
||||
|
||||
constructor() {
|
||||
this.path = searchConfig.FOLDERS_CONSTANTS.USER_DATA_PATH;
|
||||
}
|
||||
|
||||
checkFreeSpace() {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!isMac) {
|
||||
this.path = this.path.substring(0, 2);
|
||||
}
|
||||
checkDiskSpace(this.path, function (error, res) {
|
||||
|
||||
if (error) {
|
||||
return reject(new Error(error));
|
||||
}
|
||||
|
||||
return resolve(res >= searchConfig.MINIMUM_DISK_SPACE);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
SearchUtils: SearchUtils
|
||||
};
|
44
js/search/utils/checkDiskSpace.js
Normal file
44
js/search/utils/checkDiskSpace.js
Normal file
@ -0,0 +1,44 @@
|
||||
const { exec } = require('child_process');
|
||||
const { isMac } = require('../../utils/misc');
|
||||
|
||||
function checkDiskSpace(path, callback) {
|
||||
if (!path) {
|
||||
return "Please provide path"
|
||||
}
|
||||
|
||||
if (isMac) {
|
||||
exec("df -k '" + path.replace(/'/g,"'\\''") + "'", (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
if (stderr.indexOf("No such file or directory") !== -1) {
|
||||
return callback("No such file or directory : " + error)
|
||||
}
|
||||
return callback("Error : " + error)
|
||||
}
|
||||
|
||||
let data = stdout.trim().split("\n");
|
||||
|
||||
let disk_info_str = data[data.length - 1].replace( /[\s\n\r]+/g,' ');
|
||||
let freeSpace = disk_info_str.split(' ');
|
||||
return callback(null, freeSpace[3] * 1024);
|
||||
});
|
||||
} else {
|
||||
exec(`fsutil volume diskfree ${path}`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
if (stderr.indexOf("No such file or directory") !== -1) {
|
||||
return callback("No such file or directory : " + error)
|
||||
}
|
||||
return callback("Error : " + error)
|
||||
}
|
||||
let data = stdout.trim().split("\n");
|
||||
|
||||
let disk_info_str = data[data.length - 1].split(':');
|
||||
return callback(null, disk_info_str[1] * 1024);
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkDiskSpace: checkDiskSpace
|
||||
};
|
Loading…
Reference in New Issue
Block a user