Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove files prey in temp #713

Merged
merged 12 commits into from
Mar 15, 2023
124 changes: 124 additions & 0 deletions docs/clear_files_prey_temp.js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<!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 &amp;&amp; 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>
124 changes: 124 additions & 0 deletions docs/clear_folders.js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<!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 &amp;&amp; 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>
Binary file added docs/fonts/OpenSans-Bold-webfont.eot
Binary file not shown.
Loading