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.16 by tdb, Mon Mar 19 21:30:30 2001 UTC

# Line 36 | Line 36 | public class WebFeeder extends Thread {
36       */
37      public final int DEFAULT_AGE = 3600;
38      
39 +    /**
40 +     * The default path seperator, here for convienience
41 +     */
42 +    private final String sep = File.separator;
43 +    
44   //---STATIC METHODS---
45  
46      /**
# Line 69 | Line 74 | public class WebFeeder extends Thread {
74              // work out where things are
75              rootPath = cp.getProperty("WebFeeder", "WebFeeder.rootPath");
76              alertSubDir = cp.getProperty("WebFeeder", "WebFeeder.alertSubDir");
77 <            File alertsDir = new File(rootPath+"/"+alertSubDir);
77 >            File alertsDir = new File(rootPath, alertSubDir);
78              if(deleteContents(alertsDir)) {
79 <                _logger.write(this.toString(), Logger.DEBUG, "Deleted all files and directories from: "+rootPath+"/"+alertSubDir);
79 >                _logger.write(this.toString(), Logger.DEBUG, "Deleted all files and directories from: "+rootPath+sep+alertSubDir);
80              } else {
81 <                _logger.write(this.toString(), Logger.WARNING, "Failed to delete all files and directories from: "+rootPath+"/"+alertSubDir);
81 >                _logger.write(this.toString(), Logger.WARNING, "Failed to delete all files and directories from: "+rootPath+sep+alertSubDir);
82              }
83              // cleanup complete
84          } catch (PropertyNotFoundException e) {
# Line 141 | Line 146 | public class WebFeeder extends Thread {
146                  _logger.write(toString(), Logger.WARNING, "WebFeeder.alertDeleteOlderThan value unavailable using default of " + deleteOlderThan + " seconds");
147              }
148              
149 <            // list the files
150 <            String alertsPath = rootPath+"/"+alertSubDir;
151 <            File alertsDir = new File(alertsPath);
149 >            // list the files and delete as appropriate
150 >            File alertsDir = new File(rootPath, alertSubDir);
151 >            // get all the hostnames directories
152              File[] contents = alertsDir.listFiles();
153              for(int i=0; i < contents.length; i++) {
154 +                // get a single directory from the array..
155                  File hostdir = contents[i];
156 <                File[] hostdirContents = hostdir.listFiles();
157 <                for(int j=0; j < hostdirContents.length; j++) {
158 <                    File alertFile = hostdirContents[j];
159 <                    String filename = alertFile.getName();
160 <                    if(filename.endsWith(Alert.alertLevels[0]) ||
161 <                       filename.endsWith(Alert.alertLevels[Alert.alertLevels.length-1])) {
162 <                        // it ends with either OK or FINAL
163 <                        // ... so we can check it for deletion
164 <                        long lastModified = alertFile.lastModified();
165 <                        long age = System.currentTimeMillis() - lastModified;
166 <                        if(age > ((long) deleteOlderThan*1000)) {
167 <                            // it's also older than our age to delete older than
168 <                            if(!alertFile.delete()) {
169 <                                _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following 'old' alert file: "+alertFile.getPath());
156 >                // ..and check it's a directory
157 >                if(hostdir.isDirectory()) {
158 >                    // get all the contents of that directory
159 >                    File[] hostdirContents = hostdir.listFiles();
160 >                    for(int j=0; j < hostdirContents.length; j++) {
161 >                        File alertFile = hostdirContents[j];
162 >                        // get the filename..
163 >                        String filename = alertFile.getName();
164 >                        // ..and see if it ends with OK or FINAL
165 >                        if(filename.endsWith(Alert.alertLevels[0]) ||
166 >                           filename.endsWith(Alert.alertLevels[Alert.alertLevels.length-1])) {
167 >                            // it does end with either OK or FINAL
168 >                            // ... so we can check it for deletion
169 >                            long lastModified = alertFile.lastModified();
170 >                            long age = System.currentTimeMillis() - lastModified;
171 >                            if(age > ((long) deleteOlderThan*1000)) {
172 >                                // it's also older than our age to delete older than
173 >                                if(alertFile.delete()) {
174 >                                    // do a quick check to see if the directory is now empty
175 >                                    File[] newHostdirContents = hostdir.listFiles();
176 >                                    if(newHostdirContents.length == 0) {
177 >                                        // it does seem to be, try and delete it
178 >                                        // this will fail anyway if files still remain
179 >                                        if(!hostdir.delete()) {
180 >                                            _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following empty host directory: "+hostdir.getPath());
181 >                                        }
182 >                                    }
183 >                                }
184 >                                else {
185 >                                    _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following 'old' alert file: "+alertFile.getPath());
186 >                                }
187                              }
188                          }
189                      }
190                  }
191              }
169            // check through, deleting those passed the age barrier
192          }
193      }
194      
# Line 200 | Line 222 | public class WebFeeder extends Thread {
222          String data = packet.printAll();
223          String hostname = packet.getParam("packet.attributes.machine_name");
224          // set paths
225 <        String destDir = rootPath+"/"+latestSubDir+"/"+hostname;
226 <        File outDir = new File(destDir);
205 <        String destFile = destDir+"/"+latestFileName;
206 <        File outFile = new File(destFile);
225 >        File outDir = new File(rootPath, latestSubDir+sep+hostname);
226 >        File outFile = new File(rootPath, latestSubDir+sep+hostname+sep+latestFileName);
227          // write the data out
228          writeData(outDir, outFile, data);
229      }
# Line 232 | Line 252 | public class WebFeeder extends Thread {
252          String data = alert.printAll();
253          String hostname = alert.getSource();
254          // set paths
255 <        String destDir = rootPath+"/"+alertSubDir+"/"+hostname;
256 <        File outDir = new File(destDir);
237 <        String destFile = destDir+"/"+alertFileName+"."+String.valueOf(alert.getInitialAlertTime());
255 >        File outDir = new File(rootPath, alertSubDir+sep+hostname);
256 >        String destFile = alertSubDir+sep+hostname+sep+alertFileName+"."+String.valueOf(alert.getInitialAlertTime());
257          File outFile;
258          // check if we're at a special "end case" (OK or FINAL)
259          if(alert.getLevel()==0 || alert.getLevel()==Alert.alertLevels.length-1) {
260 <            File oldFile = new File(destFile);
261 <            outFile = new File(destFile+"."+Alert.alertLevels[alert.getLevel()]);
260 >            File oldFile = new File(rootPath, destFile);
261 >            outFile = new File(rootPath, destFile+"."+Alert.alertLevels[alert.getLevel()]);
262              if(!oldFile.renameTo(outFile)) {
263                  _logger.write(this.toString(), Logger.WARNING, "Failed to rename old file, "+oldFile.getPath()+" to new file, "+outFile.getPath());
264              }
265          } else {
266 <            outFile = new File(destFile);
266 >            outFile = new File(rootPath, destFile);
267          }
268          // write the data out
269          writeData(outDir, outFile, data);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines