summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-08-02 14:41:36 -0600
committerJared Adams <jaxad0127@gmail.com>2010-08-02 14:41:36 -0600
commit0689ee64ac4ecc427aa7f9fdf163c50088a5282d (patch)
tree41b23488333b5912690eb2e16f59324f7e4c0ed0
parent81d5ed3b69f2935a92fd6c88eb799b8ab24a0ef1 (diff)
downloadtools-0689ee64ac4ecc427aa7f9fdf163c50088a5282d.tar.gz
tools-0689ee64ac4ecc427aa7f9fdf163c50088a5282d.tar.bz2
tools-0689ee64ac4ecc427aa7f9fdf163c50088a5282d.tar.xz
tools-0689ee64ac4ecc427aa7f9fdf163c50088a5282d.zip
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).
-rw-r--r--Purger.java48
1 files changed, 27 insertions, 21 deletions
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 <folder> <date>\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;
}