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 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 cooldown donor perks were reducing more than expected
= Fixed bug where disabling hardcore mode for specific skills didn't work = 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 ! Updated localization files
! Changed AxesCritical to CriticalHit in config file ! Changed AxesCritical to CriticalHit in config file
! Changed several secondary ability permissions(deprecated versions still exist) ! 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.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
public class CleanBackupsTask extends BukkitRunnable { public class CleanBackupsTask extends BukkitRunnable {
private static final String BACKUP_DIRECTORY = mcMMO.getMainDirectory() + "backup" + File.separator; private static final String BACKUP_DIRECTORY = mcMMO.getMainDirectory() + "backup" + File.separator;
@ -21,7 +22,7 @@ public class CleanBackupsTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
List<Integer> savedDays = new ArrayList<Integer>(); 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>(); List<File> toDelete = new ArrayList<File>();
int amountTotal = 0; int amountTotal = 0;
int amountDeleted = 0; int amountDeleted = 0;
@ -51,20 +52,29 @@ public class CleanBackupsTask extends BukkitRunnable {
cal.setTime(date); cal.setTime(date);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
int weekOfYear = cal.get(Calendar.WEEK_OF_YEAR); int weekOfYear = cal.get(Calendar.WEEK_OF_YEAR);
int year = cal.get(Calendar.YEAR);
if (isPast24Hours(date) && Config.getInstance().getKeepLast24Hours()) { if (isPast24Hours(date) && Config.getInstance().getKeepLast24Hours()) {
// Keep all files from the last 24 hours // Keep all files from the last 24 hours
continue; continue;
} }
else if (isLastWeek(date) && !savedDays.contains(dayOfWeek) && Config.getInstance().getKeepDailyLastWeek()) { else if (isLastWeek(date) && !savedDays.contains(dayOfWeek) && Config.getInstance().getKeepDailyLastWeek()) {
// Keep daily backups of the past week // Keep daily backups of the past week
savedDays.add(dayOfWeek); savedDays.add(dayOfWeek);
continue; continue;
} }
else if (!savedWeeks.contains(weekOfYear) && Config.getInstance().getKeepWeeklyPastMonth()) { else {
// Keep one backup of each week List<Integer> savedWeeks = savedYearsWeeks.get(year);
savedWeeks.add(weekOfYear); if (savedWeeks == null) {
continue; 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++; amountDeleted++;