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.12 by tdb, Thu Mar 15 22:20:41 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 71 | Line 76 | public class WebFeeder extends Thread {
76              alertSubDir = cp.getProperty("WebFeeder", "WebFeeder.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 143 | Line 148 | public class WebFeeder extends Thread {
148              
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 +                // ..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 ends with either OK or FINAL
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()) {
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                              }
# 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 <        File outDir = new File(rootPath, latestSubDir+"/"+hostname);
226 <        File outFile = new File(rootPath, latestSubDir+"/"+hostname+"/"+latestFileName);
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 230 | Line 252 | public class WebFeeder extends Thread {
252          String data = alert.printAll();
253          String hostname = alert.getSource();
254          // set paths
255 <        File outDir = new File(rootPath, alertSubDir+"/"+hostname);
256 <        String destFile = alertSubDir+"/"+hostname+"/"+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) {
# Line 241 | Line 263 | public class WebFeeder extends Thread {
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