ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/client/WebFeeder.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/WebFeeder.java (file contents):
Revision 1.11 by tdb, Thu Mar 15 14:30:55 2001 UTC vs.
Revision 1.12 by tdb, Thu Mar 15 22:20:41 2001 UTC

# Line 69 | Line 69 | public class WebFeeder extends Thread {
69              // work out where things are
70              rootPath = cp.getProperty("WebFeeder", "WebFeeder.rootPath");
71              alertSubDir = cp.getProperty("WebFeeder", "WebFeeder.alertSubDir");
72 <            File alertsDir = new File(rootPath+"/"+alertSubDir);
72 >            File alertsDir = new File(rootPath, alertSubDir);
73              if(deleteContents(alertsDir)) {
74                  _logger.write(this.toString(), Logger.DEBUG, "Deleted all files and directories from: "+rootPath+"/"+alertSubDir);
75              } else {
# Line 141 | Line 141 | public class WebFeeder extends Thread {
141                  _logger.write(toString(), Logger.WARNING, "WebFeeder.alertDeleteOlderThan value unavailable using default of " + deleteOlderThan + " seconds");
142              }
143              
144 <            // list the files
145 <            String alertsPath = rootPath+"/"+alertSubDir;
146 <            File alertsDir = new File(alertsPath);
144 >            // list the files and delete as appropriate
145 >            File alertsDir = new File(rootPath, alertSubDir);
146              File[] contents = alertsDir.listFiles();
147              for(int i=0; i < contents.length; i++) {
148                  File hostdir = contents[i];
149 <                File[] hostdirContents = hostdir.listFiles();
150 <                for(int j=0; j < hostdirContents.length; j++) {
151 <                    File alertFile = hostdirContents[j];
152 <                    String filename = alertFile.getName();
153 <                    if(filename.endsWith(Alert.alertLevels[0]) ||
154 <                       filename.endsWith(Alert.alertLevels[Alert.alertLevels.length-1])) {
155 <                        // it ends with either OK or FINAL
156 <                        // ... so we can check it for deletion
157 <                        long lastModified = alertFile.lastModified();
158 <                        long age = System.currentTimeMillis() - lastModified;
159 <                        if(age > ((long) deleteOlderThan*1000)) {
160 <                            // it's also older than our age to delete older than
161 <                            if(!alertFile.delete()) {
162 <                                _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following 'old' alert file: "+alertFile.getPath());
149 >                if(hostdir.isDirectory()) {
150 >                    File[] hostdirContents = hostdir.listFiles();
151 >                    for(int j=0; j < hostdirContents.length; j++) {
152 >                        File alertFile = hostdirContents[j];
153 >                        String filename = alertFile.getName();
154 >                        if(filename.endsWith(Alert.alertLevels[0]) ||
155 >                           filename.endsWith(Alert.alertLevels[Alert.alertLevels.length-1])) {
156 >                            // it ends with either OK or FINAL
157 >                            // ... so we can check it for deletion
158 >                            long lastModified = alertFile.lastModified();
159 >                            long age = System.currentTimeMillis() - lastModified;
160 >                            if(age > ((long) deleteOlderThan*1000)) {
161 >                                // it's also older than our age to delete older than
162 >                                if(!alertFile.delete()) {
163 >                                    _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following 'old' alert file: "+alertFile.getPath());
164 >                                }
165                              }
166                          }
167                      }
168                  }
169              }
169            // check through, deleting those passed the age barrier
170          }
171      }
172      
# Line 200 | Line 200 | public class WebFeeder extends Thread {
200          String data = packet.printAll();
201          String hostname = packet.getParam("packet.attributes.machine_name");
202          // set paths
203 <        String destDir = rootPath+"/"+latestSubDir+"/"+hostname;
204 <        File outDir = new File(destDir);
205 <        String destFile = destDir+"/"+latestFileName;
206 <        File outFile = new File(destFile);
203 >        File outDir = new File(rootPath, latestSubDir+"/"+hostname);
204 >        File outFile = new File(rootPath, latestSubDir+"/"+hostname+"/"+latestFileName);
205          // write the data out
206          writeData(outDir, outFile, data);
207      }
# Line 232 | Line 230 | public class WebFeeder extends Thread {
230          String data = alert.printAll();
231          String hostname = alert.getSource();
232          // set paths
233 <        String destDir = rootPath+"/"+alertSubDir+"/"+hostname;
234 <        File outDir = new File(destDir);
237 <        String destFile = destDir+"/"+alertFileName+"."+String.valueOf(alert.getInitialAlertTime());
233 >        File outDir = new File(rootPath, alertSubDir+"/"+hostname);
234 >        String destFile = alertSubDir+"/"+hostname+"/"+alertFileName+"."+String.valueOf(alert.getInitialAlertTime());
235          File outFile;
236          // check if we're at a special "end case" (OK or FINAL)
237          if(alert.getLevel()==0 || alert.getLevel()==Alert.alertLevels.length-1) {
238 <            File oldFile = new File(destFile);
239 <            outFile = new File(destFile+"."+Alert.alertLevels[alert.getLevel()]);
238 >            File oldFile = new File(rootPath, destFile);
239 >            outFile = new File(rootPath, destFile+"."+Alert.alertLevels[alert.getLevel()]);
240              if(!oldFile.renameTo(outFile)) {
241                  _logger.write(this.toString(), Logger.WARNING, "Failed to rename old file, "+oldFile.getPath()+" to new file, "+outFile.getPath());
242              }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines