Actually keep all weeks, not just from the past year

Week numbers are obviously the same every year, we need to check the
year as well as the week number to determine if we should keep the
backup file or not.
This commit is contained in:
TfT_02 2013-12-07 13:18:14 +01:00
parent 3b1bb3e08a
commit 7a08343304
2 changed files with 18 additions and 7 deletions

View File

@ -23,6 +23,7 @@ Version 1.4.08-dev
= Fixed bug which prevented players from gaining Acrobatics XP when the setting 'Prevent_XP_After_Teleport' was set to false
= Fixed bug where cooldown donor perks were reducing more than expected
= Fixed bug where disabling hardcore mode for specific skills didn't work
= Fixed bug which caused the backup cleanup to delete old backups while it should've kept those
! Updated localization files
! Changed AxesCritical to CriticalHit in config file
! Changed several secondary ability permissions(deprecated versions still exist)

View File

@ -6,13 +6,14 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
public class CleanBackupsTask extends BukkitRunnable {
private static final String BACKUP_DIRECTORY = mcMMO.getMainDirectory() + "backup" + File.separator;
@ -21,7 +22,7 @@ public class CleanBackupsTask extends BukkitRunnable {
@Override
public void run() {
List<Integer> savedDays = new ArrayList<Integer>();
List<Integer> savedWeeks = new ArrayList<Integer>();
HashMap<Integer, List<Integer>> savedYearsWeeks = new HashMap<Integer, List<Integer>>();
List<File> toDelete = new ArrayList<File>();
int amountTotal = 0;
int amountDeleted = 0;
@ -51,6 +52,7 @@ public class CleanBackupsTask extends BukkitRunnable {
cal.setTime(date);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
int weekOfYear = cal.get(Calendar.WEEK_OF_YEAR);
int year = cal.get(Calendar.YEAR);
if (isPast24Hours(date) && Config.getInstance().getKeepLast24Hours()) {
// Keep all files from the last 24 hours
@ -61,11 +63,19 @@ public class CleanBackupsTask extends BukkitRunnable {
savedDays.add(dayOfWeek);
continue;
}
else if (!savedWeeks.contains(weekOfYear) && Config.getInstance().getKeepWeeklyPastMonth()) {
else {
List<Integer> savedWeeks = savedYearsWeeks.get(year);
if (savedWeeks == null) {
savedWeeks = new ArrayList<Integer>();
savedYearsWeeks.put(year, savedWeeks);
}
if (!savedWeeks.contains(weekOfYear) && Config.getInstance().getKeepWeeklyPastMonth()) {
// Keep one backup of each week
savedWeeks.add(weekOfYear);
continue;
}
}
amountDeleted++;
toDelete.add(file);