docs/clear_folders.js.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: clear_folders.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: clear_folders.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const fs = require('fs'),
common = require('./../../common'),
paths = common.system.paths,
join = require('path').join,
remove = require('remover');
/**
* Entry point function of old folders deletion.
* It is responsible for deleting folders with old versions and keeping the folder with the current version
* It’s called from the post-install script and applies for all OSs
* To run it you must have administrator permissions
* test in mac : ./prey config hooks post_install
* After executing the command, the node client should continue to operate without problems.
* @param {Function} cb - function
*/
exports.start = function (cb) {
var count,
last_err,
folders_removed = [];
var done = function (err) {
if (err) last_err = err;
--count || finished();
}
/**finish to remove folders */
var finished = function () {
return cb()
}
/** get folders with versions olds */
var get_folders_old_versions = function (cb) {
try {
let folders = fs.readdirSync(paths.versions);
let folders_to_delete = folders.filter(x => x !== common.version); //only remove folders with old versions
folders_to_delete = folders_to_delete.filter(x => x !== ".DS_Store"); //for test
if (folders_to_delete.length == 0) return cb(null,[])
else return cb(null, folders_to_delete)
} catch (err) {
if (err) console.log(err);
// Here you get the error when the file was not found,
// but you also get any other error
return cb(err);
}
}
/**
* @param {Array} folders - folder list to remove
*/
/** remove olds folders */
var remove_folders = function (folders) {
folders.forEach(element => {
let folder = join(paths.versions, element);
remove(folder, (err) => {
if (err) console.log(err);
if (err) return cb();
folders_removed.push(folder);
return done();
})
});
}
get_folders_old_versions(function (err, folders) {
if (err) console.log(err);
if (err) return cb();
if (folders && folders.length == 0) return cb();
count = folders.length;
remove_folders(folders)
})
}</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#start">start</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Fri Dec 30 2022 13:14:09 GMT-0300 (Chile Summer Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>