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