#39: Cleanup old releases and UI upgrades
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user