#39: Cleanup old releases and UI upgrades
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
# Changelog
|
||||
## 1.1.4
|
||||
* \#39: Cleanup old releases and UI upgrades
|
||||
|
||||
## 1.1.3
|
||||
* CentOS 8 support
|
||||
* Support remote send and receive timeouts
|
||||
|
||||
@@ -85,6 +85,8 @@ exports.IPC_Check_Installed_Reply = 'check_installed_reply';
|
||||
|
||||
exports.IPC_Check_Mount_Location = 'check_mount_location';
|
||||
|
||||
exports.IPC_Cleanup_Releases = 'IPC_Cleanup_Releases';
|
||||
|
||||
exports.IPC_Delete_File = 'delete_file';
|
||||
|
||||
exports.IPC_Detect_Mount = 'detect_mount';
|
||||
|
||||
@@ -87,6 +87,22 @@ const _getRepertoryExec = version => {
|
||||
};
|
||||
};
|
||||
|
||||
const _removeDirectoryRecursively = dir => {
|
||||
if (fs.existsSync(dir)) {
|
||||
fs
|
||||
.readdirSync(dir)
|
||||
.forEach(file => {
|
||||
const curPath = path.join(dir, file);
|
||||
if (fs.lstatSync(curPath).isDirectory()) {
|
||||
module.exports.removeDirectoryRecursively(curPath);
|
||||
} else {
|
||||
fs.unlinkSync(curPath);
|
||||
}
|
||||
});
|
||||
fs.rmdirSync(dir);
|
||||
}
|
||||
};
|
||||
|
||||
const _resolvePath = str => {
|
||||
if (os.platform() === 'win32') {
|
||||
return str.replace(/%([^%]+)%/g, (_, n) => {
|
||||
@@ -130,6 +146,36 @@ module.exports.checkDaemonVersion = (version, provider) => {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.cleanupOldReleases = versionList => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
if (versionList && versionList.length > 0) {
|
||||
const dataDir = _getDataDirectory();
|
||||
const directoryList = fs
|
||||
.readdirSync(dataDir, {withFileTypes: true})
|
||||
.filter(dirent => dirent.isDirectory())
|
||||
.map(dirent => dirent);
|
||||
|
||||
const removeList = directoryList
|
||||
.filter(dirent => !versionList.includes(dirent.name))
|
||||
.map(dirent => dirent.name);
|
||||
|
||||
for (const dir of removeList) {
|
||||
try {
|
||||
_removeDirectoryRecursively(path.join(dataDir, dir));
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
resolve();
|
||||
}
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.createSignatureFiles = (signature, publicKey) => {
|
||||
const fileName1 = RandomString.generate({
|
||||
length: 12,
|
||||
@@ -653,21 +699,7 @@ module.exports.performWindowsUninstall = names => {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.removeDirectoryRecursively = (p) => {
|
||||
if (fs.existsSync(p)) {
|
||||
fs
|
||||
.readdirSync(p)
|
||||
.forEach(file => {
|
||||
const curPath = path.join(p, file);
|
||||
if (fs.lstatSync(curPath).isDirectory()) {
|
||||
module.exports.removeDirectoryRecursively(curPath);
|
||||
} else {
|
||||
fs.unlinkSync(curPath);
|
||||
}
|
||||
});
|
||||
fs.rmdirSync(p);
|
||||
}
|
||||
};
|
||||
module.exports.removeDirectoryRecursively = _removeDirectoryRecursively;
|
||||
|
||||
module.exports.resolvePath = _resolvePath;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
setDismissDependencies
|
||||
} from './install_actions';
|
||||
import {unmountAll} from './mount_actions';
|
||||
import {getIPCRenderer} from '../../utils';
|
||||
|
||||
export const CLEAR_UI_UPGRADE = 'relver/clearUIUpgrade';
|
||||
export const clearUIUpgrade = () => {
|
||||
@@ -22,6 +23,17 @@ export const clearUIUpgrade = () => {
|
||||
};
|
||||
};
|
||||
|
||||
const cleanupOldReleases = versionList => {
|
||||
return dispatch => {
|
||||
const ipcRenderer = getIPCRenderer();
|
||||
if (ipcRenderer) {
|
||||
ipcRenderer.sendSync(Constants.IPC_Cleanup_Releases + '_sync', {
|
||||
version_list: versionList
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const detectUIUpgrade = () => {
|
||||
return (dispatch, getState) => {
|
||||
axios
|
||||
@@ -77,6 +89,12 @@ export const loadReleases = () => {
|
||||
dispatch(setAllowDismissDependencies(versionLookup[Constants.RELEASE_TYPES[release]].length > 1));
|
||||
}
|
||||
dispatch(checkVersionInstalled());
|
||||
|
||||
let versionList = [];
|
||||
for (const key of Object.keys(locationsLookup)) {
|
||||
versionList.push(key);
|
||||
}
|
||||
dispatch(cleanupOldReleases(versionList))
|
||||
};
|
||||
|
||||
if ((version !== state.Version) || (release !== state.Release)) {
|
||||
|
||||
@@ -29,6 +29,12 @@ const addListeners = (ipcMain, standardIPCReply) => {
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Cleanup_Releases + '_sync', (event, data) => {
|
||||
helpers.cleanupOldReleases(data.version_list);
|
||||
|
||||
event.returnValue = true;
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Extract_Release, (event, data) => {
|
||||
const destination = path.join(helpers.getDataDirectory(), data.Version);
|
||||
helpers.removeDirectoryRecursively(destination);
|
||||
|
||||
Reference in New Issue
Block a user