From 0689ee64ac4ecc427aa7f9fdf163c50088a5282d Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 2 Aug 2010 14:41:36 -0600 Subject: Fix how purger works It now ignores accounts that haven't been used yet and outputs the removed account names (suitable for a public purge list). --- Purger.java | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) (limited to 'Purger.java') diff --git a/Purger.java b/Purger.java index 1bb6a1b..115847e 100644 --- a/Purger.java +++ b/Purger.java @@ -11,7 +11,7 @@ import java.util.*; public static void main(String[] args) { if (args.length != 2) { - System.out.println( + System.err.println( "Usage: java Purger \n" + " - folder: is the path to account.txt and athena.txt files.\n" + " - date: accounts created before this date will be purged (dd/mm/yy or yyyy-mm-dd)."); @@ -26,11 +26,11 @@ import java.util.*; File folder = new File(args[0]); // Do some sanity checking if (!folder.exists()) { - System.out.println("Folder does not exist!"); + System.err.println("Folder does not exist!"); return; } if (!folder.isDirectory()) { - System.out.println("Folder is not a folder!"); + System.err.println("Folder is not a folder!"); return; } @@ -52,9 +52,11 @@ import java.util.*; } if (purgeDate == null) { - System.out.println("ERROR: Date format not recognized."); + System.err.println("ERROR: Date format not recognized."); return; } + + System.out.printf("Removing accounts unused since %tF\n", purgeDate); String line; @@ -75,7 +77,9 @@ import java.util.*; } else { // Server accounts should not be purged - if (!fields[4].equals("S")) { + if (fields[4].equals("S")) { + copy = true; + } else { accounts++; dateFormat = new SimpleDateFormat("yyyy-MM-dd"); try { @@ -84,21 +88,27 @@ import java.util.*; activeAccounts.add(fields[0]); copy = true; } + else + { + System.out.println("Removing " + fields[1]); + } } catch (ParseException e) { - System.out.println( - "ERROR: Wrong date format in account.txt. (" - + accounts + ": " + line + ")"); - //return; + // Ignore accounts that haven't been used yet + if (fields[3].equals("-")) { + activeAccounts.add(fields[0]); + copy = true; + } + else { + System.err.println("ERROR: Wrong date format in account.txt. (" + accounts + ": " + line + ")"); + System.out.println("Removing " + fields[1]); + } } catch (Exception e) { e.printStackTrace(); return; } } - else { - copy = true; - } } if (copy) { try { @@ -113,19 +123,16 @@ import java.util.*; output.close(); } catch (FileNotFoundException e ) { - System.out.println( - "ERROR: file " + oldAccount.getAbsolutePath() + " not found."); + System.err.println("ERROR: file " + oldAccount.getAbsolutePath() + " not found."); return; } catch (Exception e) { - System.out.println("ERROR: unable to process account.txt"); + System.err.println("ERROR: unable to process account.txt"); e.printStackTrace(); return; } - System.out.println( - "Removed " + (accounts - activeAccounts.size()) + "/" + - accounts + " accounts."); + System.out.println("Removed " + (accounts - activeAccounts.size()) + "/" + accounts + " accounts."); // Remove characters try { @@ -161,12 +168,11 @@ import java.util.*; output.close(); } catch (FileNotFoundException e ) { - System.out.println( - "ERROR: file " + oldAthena.getAbsolutePath() + " not found."); + System.err.println("ERROR: file " + oldAthena.getAbsolutePath() + " not found."); return; } catch (Exception e) { - System.out.println("ERROR: unable to process athena.txt"); + System.err.println("ERROR: unable to process athena.txt"); e.printStackTrace(); return; } -- cgit v1.2.3-60-g2f50