|
|
|
@ -15,14 +15,11 @@ Env = {
|
|
|
|
|
limits: {
|
|
|
|
|
<unsafeKey>: <limit>,
|
|
|
|
|
},
|
|
|
|
|
config: {
|
|
|
|
|
inactiveTime: <number of days>,
|
|
|
|
|
archiveRetentionTime: <number of days>,
|
|
|
|
|
accountRetentionTime: <number of days>,
|
|
|
|
|
|
|
|
|
|
pinPath: <filesystem path>,
|
|
|
|
|
|
|
|
|
|
customLimits: <custom limits map>,
|
|
|
|
|
archiveRetentionTime: <number of days>,
|
|
|
|
|
accountRetentionTime: <number of days>,
|
|
|
|
|
inactiveTime: <number of days>,
|
|
|
|
|
paths: {
|
|
|
|
|
pin: <path to pin storage>
|
|
|
|
|
},
|
|
|
|
|
store,
|
|
|
|
|
pinStore,
|
|
|
|
@ -35,11 +32,9 @@ Env = {
|
|
|
|
|
module.exports = function (Env, cb) {
|
|
|
|
|
var complete = Util.once(Util.mkAsync(cb));
|
|
|
|
|
|
|
|
|
|
var config = Env.config;
|
|
|
|
|
|
|
|
|
|
// the administrator should have set an 'inactiveTime' in their config
|
|
|
|
|
// if they didn't, just exit.
|
|
|
|
|
if (!config.inactiveTime || typeof(config.inactiveTime) !== "number") {
|
|
|
|
|
if (!Env.inactiveTime || typeof(Env.inactiveTime) !== "number") {
|
|
|
|
|
return void complete("NO_INACTIVE_TIME");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -55,10 +50,10 @@ module.exports = function (Env, cb) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// files which have not been changed since before this date can be considered inactive
|
|
|
|
|
var inactiveTime = +new Date() - (config.inactiveTime * 24 * 3600 * 1000);
|
|
|
|
|
var inactiveTime = +new Date() - (Env.inactiveTime * 24 * 3600 * 1000);
|
|
|
|
|
|
|
|
|
|
// files which were archived before this date can be considered safe to remove
|
|
|
|
|
var retentionTime = +new Date() - (config.archiveRetentionTime * 24 * 3600 * 1000);
|
|
|
|
|
var retentionTime = +new Date() - (Env.archiveRetentionTime * 24 * 3600 * 1000);
|
|
|
|
|
|
|
|
|
|
var store;
|
|
|
|
|
var pinStore;
|
|
|
|
@ -111,7 +106,7 @@ module.exports = function (Env, cb) {
|
|
|
|
|
|
|
|
|
|
// if the admin has not set an 'archiveRetentionTime', this block makes no sense
|
|
|
|
|
// so just skip it
|
|
|
|
|
if (typeof(config.archiveRetentionTime) !== "number") { return; }
|
|
|
|
|
if (typeof(Env.archiveRetentionTime) !== "number") { return; }
|
|
|
|
|
|
|
|
|
|
// count the number of files which have been removed in this run
|
|
|
|
|
var removed = 0;
|
|
|
|
@ -165,7 +160,7 @@ module.exports = function (Env, cb) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var removeArchivedBlobProofs = function (w) {
|
|
|
|
|
if (typeof(config.archiveRetentionTime) !== "number") { return; }
|
|
|
|
|
if (typeof(Env.archiveRetentionTime) !== "number") { return; }
|
|
|
|
|
// Iterate over archive blob ownership proofs and remove them
|
|
|
|
|
// if they are older than the specified retention time
|
|
|
|
|
var removed = 0;
|
|
|
|
@ -190,7 +185,7 @@ module.exports = function (Env, cb) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var removeArchivedBlobs = function (w) {
|
|
|
|
|
if (typeof(config.archiveRetentionTime) !== "number") { return; }
|
|
|
|
|
if (typeof(Env.archiveRetentionTime) !== "number") { return; }
|
|
|
|
|
// Iterate over archived blobs and remove them
|
|
|
|
|
// if they are older than the specified retention time
|
|
|
|
|
var removed = 0;
|
|
|
|
@ -280,8 +275,8 @@ module.exports = function (Env, cb) {
|
|
|
|
|
var inactive = 0;
|
|
|
|
|
|
|
|
|
|
var accountRetentionTime;
|
|
|
|
|
if (typeof(config.accountRetentionTime) === 'number' && config.accountRetentionTime > 0) {
|
|
|
|
|
accountRetentionTime = +new Date() - (24 * 3600 * 1000 * config.accountRetentionTime);
|
|
|
|
|
if (typeof(Env.accountRetentionTime) === 'number' && Env.accountRetentionTime > 0) {
|
|
|
|
|
accountRetentionTime = +new Date() - (24 * 3600 * 1000 * Env.accountRetentionTime);
|
|
|
|
|
} else {
|
|
|
|
|
accountRetentionTime = -1;
|
|
|
|
|
}
|
|
|
|
@ -297,7 +292,7 @@ module.exports = function (Env, cb) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var accountIsActive = function (mtime, pinList, id) {
|
|
|
|
|
// console.log("id [%s] in premiumSafeKeys", id, premiumSafeKeys.indexOf(id) !== -1); // XXX
|
|
|
|
|
// console.log("id [%s] in premiumSafeKeys", id, premiumSafeKeys.indexOf(id) !== -1);
|
|
|
|
|
// if their pin log has changed recently then consider them active
|
|
|
|
|
if (mtime && mtime > accountRetentionTime) {
|
|
|
|
|
return true;
|
|
|
|
@ -360,7 +355,7 @@ module.exports = function (Env, cb) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Pins.load(w(done), {
|
|
|
|
|
pinPath: config.pinPath,
|
|
|
|
|
pinPath: Env.paths.pin,
|
|
|
|
|
handler: handler,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
@ -515,9 +510,6 @@ module.exports = function (Env, cb) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
nThen(loadStorage)
|
|
|
|
|
.nThen(function () {
|
|
|
|
|
Log.info("EVICT_TIME_TO_LOAD_PINS", msSinceStart());
|
|
|
|
|
})
|
|
|
|
|
.nThen(removeArchivedChannels)
|
|
|
|
|
.nThen(removeArchivedBlobProofs)
|
|
|
|
|
.nThen(removeArchivedBlobs)
|
|
|
|
|