docs/clear_files_prey_temp.js.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: clear_files_prey_temp.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_files_prey_temp.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 files deletion.
* It is responsible for deleting files with prey-config
* 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,
files_removed = [];
var done = function (err) {
if (err) last_err = err;
--count || finished();
}
/**finish to remove files */
var finished = function () {
return cb()
}
/** get files with prey-config */
var get_files_prey_in_temp = function (cb) {
try {
let files = fs.readdirSync(paths.temp);
let files_to_delete = files.filter(x => x.includes("prey-config-")); //only remove files prey-config-%%%%%
files_to_delete = files_to_delete.filter(x => x !== ".DS_Store"); //for test
if (files_to_delete.length == 0) return cb(null,[])
else return cb(null, files_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} files - list files to remove
*/
/** remove files prey-config */
var remove_files = function (files) {
files.forEach(element => {
let file = join(paths.temp, element);
fs.unlink(file, (err) => {
if (err) console.log(err);
if (err) return cb();
files_removed.push(file);
return done();
})
});
}
get_files_prey_in_temp(function (err, files) {
if (err) console.log(err);
if (err) return cb();
if (files && files.length == 0) return cb();
count = files.length;
remove_files(files)
})
} </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 Thu Feb 02 2023 09:50:26 GMT-0300 (Chile Summer Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>