delete old releases compatible with java 1.5 ;)

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4728 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
danielr 17 years ago
parent e90282da1c
commit 7bd8601f04

@ -38,6 +38,7 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -511,7 +512,7 @@ public final class yacyVersion implements Comparator<yacyVersion>, Comparable<ya
String[] downloaded = filesPath.list(); String[] downloaded = filesPath.list();
// parse all filenames and put them in a sorted set // parse all filenames and put them in a sorted set
TreeSet<yacyVersion> downloadedreleases = new TreeSet<yacyVersion>(); SortedSet<yacyVersion> downloadedreleases = new TreeSet<yacyVersion>();
for (int j = 0; j < downloaded.length; j++) { for (int j = 0; j < downloaded.length; j++) {
try { try {
release = new yacyVersion(downloaded[j]); release = new yacyVersion(downloaded[j]);
@ -534,18 +535,18 @@ public final class yacyVersion implements Comparator<yacyVersion>, Comparable<ya
// remove old files // remove old files
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
final long deleteAfterMillis = deleteAfterDays * 24 * 60 * 60000l; final long deleteAfterMillis = deleteAfterDays * 24 * 60 * 60000l;
final Iterator<yacyVersion> iter = downloadedreleases.descendingIterator(); String lastMain = null;
while (iter.hasNext()) { for (final yacyVersion aRelease: downloadedreleases) {
release = iter.next(); if(keepMain && aRelease.mainRelease) {
// keep this one, delete last remembered main release file
if(keepMain && release.mainRelease) { if(lastMain != null) {
// we found the latest main release aRelease.name = lastMain;
keepMain = false; }
continue; lastMain = aRelease.name;
} }
// check file age // check file age
File downloadedFile = new File(filesPath + File.separator + release.name); File downloadedFile = new File(filesPath + File.separator + aRelease.name);
if(now - downloadedFile.lastModified() > deleteAfterMillis) { if(now - downloadedFile.lastModified() > deleteAfterMillis) {
// delete file // delete file
if(!downloadedFile.delete()) { if(!downloadedFile.delete()) {

Loading…
Cancel
Save