forked from I2P_Developers/i2p.i2p
Profiles: Delete old ones after saving (ticket #1328)
This commit is contained in:
@ -57,6 +57,7 @@ class PeerManager {
|
||||
*/
|
||||
private static final long REORGANIZE_TIME_LONG = 351*1000;
|
||||
private static final long STORE_TIME = 19*60*60*1000;
|
||||
private static final long EXPIRE_AGE = 3*24*60*60*1000;
|
||||
|
||||
public static final String TRACKED_CAPS = "" +
|
||||
FloodfillNetworkDatabaseFacade.CAPABILITY_FLOODFILL +
|
||||
@ -102,7 +103,8 @@ class PeerManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorganize the profiles. Also periodically store them.
|
||||
* Reorganize the profiles. Also periodically store them,
|
||||
* and delete very old ones.
|
||||
*
|
||||
* This takes too long to run on the SimpleTimer2 queue
|
||||
* @since 0.9.10
|
||||
@ -131,6 +133,7 @@ class PeerManager {
|
||||
try {
|
||||
_log.debug("Periodic profile store start");
|
||||
storeProfiles();
|
||||
_persistenceHelper.deleteOldProfiles(EXPIRE_AGE);
|
||||
_log.debug("Periodic profile store end");
|
||||
} catch (Throwable t) {
|
||||
_log.log(Log.CRIT, "Error storing profiles", t);
|
||||
|
@ -229,6 +229,26 @@ class ProfilePersistenceHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete profile files with timestamps older than 'age' ago
|
||||
* @since 0.9.28
|
||||
*/
|
||||
public void deleteOldProfiles(long age) {
|
||||
long cutoff = System.currentTimeMillis() - age;
|
||||
List<File> files = selectFiles();
|
||||
int i = 0;
|
||||
for (File f : files) {
|
||||
if (!f.isFile())
|
||||
continue;
|
||||
if (f.lastModified() < cutoff) {
|
||||
i++;
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("Deleted " + i + " old profiles");
|
||||
}
|
||||
|
||||
private boolean isExpired(long lastSentToSuccessfully) {
|
||||
long timeSince = _context.clock().now() - lastSentToSuccessfully;
|
||||
return (timeSince > EXPIRE_AGE);
|
||||
|
Reference in New Issue
Block a user