--- projects/cms/source/server/uk/org/iscream/cms/server/client/WebFeeder.java 2001/03/15 14:30:55 1.11 +++ projects/cms/source/server/uk/org/iscream/cms/server/client/WebFeeder.java 2001/03/15 22:20:41 1.12 @@ -15,7 +15,7 @@ import java.io.*; * !! that to a file. * * @author $Author: tdb $ - * @version $Id: WebFeeder.java,v 1.11 2001/03/15 14:30:55 tdb Exp $ + * @version $Id: WebFeeder.java,v 1.12 2001/03/15 22:20:41 tdb Exp $ */ public class WebFeeder extends Thread { @@ -24,7 +24,7 @@ public class WebFeeder extends Thread { /** * The current CVS revision of this class */ - public static final String REVISION = "$Revision: 1.11 $"; + public static final String REVISION = "$Revision: 1.12 $"; /** * Default check period in seconds (30 minutes) @@ -69,7 +69,7 @@ public class WebFeeder extends Thread { // work out where things are rootPath = cp.getProperty("WebFeeder", "WebFeeder.rootPath"); alertSubDir = cp.getProperty("WebFeeder", "WebFeeder.alertSubDir"); - File alertsDir = new File(rootPath+"/"+alertSubDir); + File alertsDir = new File(rootPath, alertSubDir); if(deleteContents(alertsDir)) { _logger.write(this.toString(), Logger.DEBUG, "Deleted all files and directories from: "+rootPath+"/"+alertSubDir); } else { @@ -141,32 +141,32 @@ public class WebFeeder extends Thread { _logger.write(toString(), Logger.WARNING, "WebFeeder.alertDeleteOlderThan value unavailable using default of " + deleteOlderThan + " seconds"); } - // list the files - String alertsPath = rootPath+"/"+alertSubDir; - File alertsDir = new File(alertsPath); + // list the files and delete as appropriate + File alertsDir = new File(rootPath, alertSubDir); File[] contents = alertsDir.listFiles(); for(int i=0; i < contents.length; i++) { File hostdir = contents[i]; - File[] hostdirContents = hostdir.listFiles(); - for(int j=0; j < hostdirContents.length; j++) { - File alertFile = hostdirContents[j]; - String filename = alertFile.getName(); - if(filename.endsWith(Alert.alertLevels[0]) || - filename.endsWith(Alert.alertLevels[Alert.alertLevels.length-1])) { - // it ends with either OK or FINAL - // ... so we can check it for deletion - long lastModified = alertFile.lastModified(); - long age = System.currentTimeMillis() - lastModified; - if(age > ((long) deleteOlderThan*1000)) { - // it's also older than our age to delete older than - if(!alertFile.delete()) { - _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following 'old' alert file: "+alertFile.getPath()); + if(hostdir.isDirectory()) { + File[] hostdirContents = hostdir.listFiles(); + for(int j=0; j < hostdirContents.length; j++) { + File alertFile = hostdirContents[j]; + String filename = alertFile.getName(); + if(filename.endsWith(Alert.alertLevels[0]) || + filename.endsWith(Alert.alertLevels[Alert.alertLevels.length-1])) { + // it ends with either OK or FINAL + // ... so we can check it for deletion + long lastModified = alertFile.lastModified(); + long age = System.currentTimeMillis() - lastModified; + if(age > ((long) deleteOlderThan*1000)) { + // it's also older than our age to delete older than + if(!alertFile.delete()) { + _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following 'old' alert file: "+alertFile.getPath()); + } } } } } } - // check through, deleting those passed the age barrier } } @@ -200,10 +200,8 @@ public class WebFeeder extends Thread { String data = packet.printAll(); String hostname = packet.getParam("packet.attributes.machine_name"); // set paths - String destDir = rootPath+"/"+latestSubDir+"/"+hostname; - File outDir = new File(destDir); - String destFile = destDir+"/"+latestFileName; - File outFile = new File(destFile); + File outDir = new File(rootPath, latestSubDir+"/"+hostname); + File outFile = new File(rootPath, latestSubDir+"/"+hostname+"/"+latestFileName); // write the data out writeData(outDir, outFile, data); } @@ -232,14 +230,13 @@ public class WebFeeder extends Thread { String data = alert.printAll(); String hostname = alert.getSource(); // set paths - String destDir = rootPath+"/"+alertSubDir+"/"+hostname; - File outDir = new File(destDir); - String destFile = destDir+"/"+alertFileName+"."+String.valueOf(alert.getInitialAlertTime()); + File outDir = new File(rootPath, alertSubDir+"/"+hostname); + String destFile = alertSubDir+"/"+hostname+"/"+alertFileName+"."+String.valueOf(alert.getInitialAlertTime()); File outFile; // check if we're at a special "end case" (OK or FINAL) if(alert.getLevel()==0 || alert.getLevel()==Alert.alertLevels.length-1) { - File oldFile = new File(destFile); - outFile = new File(destFile+"."+Alert.alertLevels[alert.getLevel()]); + File oldFile = new File(rootPath, destFile); + outFile = new File(rootPath, destFile+"."+Alert.alertLevels[alert.getLevel()]); if(!oldFile.renameTo(outFile)) { _logger.write(this.toString(), Logger.WARNING, "Failed to rename old file, "+oldFile.getPath()+" to new file, "+outFile.getPath()); }