Author: syoung
Date: 2006-04-12 03:30:18 +0000 (Wed, 12 Apr 2006)
New Revision: 8526

Modified:
   trunk/freenet/src/freenet/client/ArchiveManager.java
   trunk/freenet/src/freenet/client/events/ClientEvent.java
   trunk/freenet/src/freenet/keys/ClientCHKBlock.java
   trunk/freenet/src/freenet/node/Version.java
   trunk/freenet/src/freenet/support/FileLoggerHook.java
Log:
FileLoggerHook: Was comparing a File to a String when looking for old log files.
ArchiveManager: ArchiveManager was not closing the ZIP input stream, just the 
underlying stream.
ClientCHKBlock: decode(ClientKey,BucketFactory,int) was an infinite loop, but 
it was fortunately not used.

Modified: trunk/freenet/src/freenet/client/ArchiveManager.java
===================================================================
--- trunk/freenet/src/freenet/client/ArchiveManager.java        2006-04-11 
21:12:14 UTC (rev 8525)
+++ trunk/freenet/src/freenet/client/ArchiveManager.java        2006-04-12 
03:30:18 UTC (rev 8526)
@@ -3,7 +3,6 @@
 import java.io.DataOutputStream;
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -183,14 +182,18 @@
                        throw new ArchiveFailureException("Archive too big");
                if(archiveType != Metadata.ARCHIVE_ZIP)
                        throw new ArchiveFailureException("Unknown or 
unsupported archive algorithm "+archiveType);
-               InputStream is = null;
+               
+               ZipInputStream zis = null;
                try {
-                       is = data.getInputStream();
-                       ZipInputStream zis = new ZipInputStream(is);
+                       zis = new ZipInputStream(data.getInputStream());
+                       
+                       // MINOR: Assumes the first entry in the zip is a 
directory. 
                        ZipEntry entry =  zis.getNextEntry();
+                       
                        byte[] buf = new byte[4096];
                        HashSet names = new HashSet();
                        boolean gotMetadata = false;
+                       
 outer:         while(entry != null) {
                                entry = zis.getNextEntry();
                                String name = entry.getName();
@@ -207,6 +210,7 @@
                                        TempStoreElement temp = 
makeTempStoreBucket(size);
                                        Bucket output = temp.bucket;
                                        OutputStream out = 
output.getOutputStream();
+
                                        int readBytes;
 inner:                         while((readBytes = zis.read(buf)) > 0) {
                                                out.write(buf, 0, readBytes);
@@ -218,6 +222,7 @@
                                                        continue outer;
                                                }
                                        }
+
                                        out.close();
                                        if(name.equals(".metadata"))
                                                gotMetadata = true;
@@ -225,6 +230,7 @@
                                        names.add(name);
                                }
                        }
+
                        // If no metadata, generate some
                        if(!gotMetadata) {
                                generateMetadata(ctx, key, names);
@@ -233,9 +239,9 @@
                } catch (IOException e) {
                        throw new ArchiveFailureException("Error reading 
archive: "+e.getMessage(), e);
                } finally {
-                       if(is != null) {
+                       if(zis != null) {
                                try {
-                                       is.close();
+                                       zis.close();
                                } catch (IOException e) {
                                        Logger.error(this, "Failed to close 
stream: "+e, e);
                                }

Modified: trunk/freenet/src/freenet/client/events/ClientEvent.java
===================================================================
--- trunk/freenet/src/freenet/client/events/ClientEvent.java    2006-04-11 
21:12:14 UTC (rev 8525)
+++ trunk/freenet/src/freenet/client/events/ClientEvent.java    2006-04-12 
03:30:18 UTC (rev 8526)
@@ -1,20 +1,20 @@
 package freenet.client.events;
+
 /**
- * Event handeling for clients.
- *
+ * Event handling for clients.
+ * 
  * @author oskar
- **/
-
+ */
 public interface ClientEvent {

-    /**
-     * Returns a string descriping the event.
-     **/
-    public String getDescription();
+       /**
+        * Returns a string describing the event.
+        */
+       public String getDescription();

-    /**
-     * Returns a code for this event.
-     **/
-    public int getCode();
+       /**
+        * Returns a unique code for this event.
+        */
+       public int getCode();

 }

Modified: trunk/freenet/src/freenet/keys/ClientCHKBlock.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientCHKBlock.java  2006-04-11 21:12:14 UTC 
(rev 8525)
+++ trunk/freenet/src/freenet/keys/ClientCHKBlock.java  2006-04-12 03:30:18 UTC 
(rev 8526)
@@ -65,13 +65,7 @@
                        throw new Error(e);
                }
        }
-       
-    public Bucket decode(ClientKey key, BucketFactory bf, int maxLength) 
throws KeyDecodeException, IOException {
-       if(!(key instanceof ClientCHK))
-               throw new KeyDecodeException("Not a CHK!: "+key);
-       return decode((ClientCHK)key, bf, maxLength);
-    }
-    
+
     /**
      * Decode the CHK and recover the original data
      * @return the original data

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-04-11 21:12:14 UTC (rev 
8525)
+++ trunk/freenet/src/freenet/node/Version.java 2006-04-12 03:30:18 UTC (rev 
8526)
@@ -20,7 +20,7 @@
        public static final String protocolVersion = "1.0";

        /** The build number of the current revision */
-       private static final int buildNumber = 634;
+       private static final int buildNumber = 635;

        /** Oldest build of Fred we will talk to */
        private static final int lastGoodBuild = 591;

Modified: trunk/freenet/src/freenet/support/FileLoggerHook.java
===================================================================
--- trunk/freenet/src/freenet/support/FileLoggerHook.java       2006-04-11 
21:12:14 UTC (rev 8525)
+++ trunk/freenet/src/freenet/support/FileLoggerHook.java       2006-04-12 
03:30:18 UTC (rev 8526)
@@ -77,8 +77,8 @@
        /* Base filename for rotating logs */
        protected String baseFilename = null;

-       protected File latestFilename;
-       protected File previousFilename;
+       protected File latestFile;
+       protected File previousFile;

        /* Whether to redirect stdout */
        protected boolean redirectStdOut = false;
@@ -156,6 +156,8 @@

        public class IntervalParseException extends Exception {

+               private static final long serialVersionUID = 69847854744673572L;
+
                public IntervalParseException(String string) {
                        super(string);
                }
@@ -206,8 +208,8 @@
                        GregorianCalendar gc = null;
                        String filename = null;
                        if (baseFilename != null) {
-                               latestFilename = new 
File(baseFilename+"-latest.log");
-                               previousFilename = new 
File(baseFilename+"-previous.log");
+                               latestFile = new 
File(baseFilename+"-latest.log");
+                               previousFile = new 
File(baseFilename+"-previous.log");
                                findOldLogFiles();
                                gc = new GregorianCalendar();
                                switch (INTERVAL) {
@@ -236,8 +238,8 @@
                                        logFiles.removeLast();
                                }
                                logStream = openNewLogFile(currentFilename, 
true);
-                               if(latestFilename != null) {
-                                       altLogStream = 
openNewLogFile(latestFilename, false);
+                               if(latestFile != null) {
+                                       altLogStream = 
openNewLogFile(latestFile, false);
                                }
                                System.err.println("Created log files");
                                startTime = gc.getTimeInMillis();
@@ -265,7 +267,6 @@
                                                                
System.err.println(
                                                                                
"Closing on change caught " + e);
                                                        }
-                                                       String oldFilename = 
filename;
                                                        long length = 
currentFilename.length();
                                                        OldLogFile olf = new 
OldLogFile(currentFilename, lastTime, nextHour, length);
                                                        lastTime = nextHour;
@@ -278,21 +279,21 @@
                                                        filename = 
getHourLogName(gc, true);
                                                        currentFilename = new 
File(filename);
                                                        logStream = 
openNewLogFile(new File(filename), true);
-                                                       if(latestFilename != 
null) {
+                                                       if(latestFile != null) {
                                                                try {
                                                                        
altLogStream.close();
                                                                } catch 
(IOException e) {
                                                                        
System.err.println(
                                                                                
        "Closing alt on change caught " + e);
                                                                }
-                                                               
if(previousFilename != null) {
-                                                                       
previousFilename.delete();
-                                                                       
latestFilename.renameTo(previousFilename);
-                                                                       
latestFilename.delete();
+                                                               if(previousFile 
!= null) {
+                                                                       
previousFile.delete();
+                                                                       
latestFile.renameTo(previousFile);
+                                                                       
latestFile.delete();
                                                                } else {
-                                                                       
latestFilename.delete();
+                                                                       
latestFile.delete();
                                                                }
-                                                               altLogStream = 
openNewLogFile(latestFilename, false);
+                                                               altLogStream = 
openNewLogFile(latestFile, false);
                                                        }
                                                        
System.err.println("Rotated log files: "+filename);
                                                        
//System.err.println("Almost rotated");
@@ -483,14 +484,15 @@
                java.util.Arrays.sort(files);
                long lastStartTime = -1;
                File oldFile = null;
-               previousFilename.delete();
-               latestFilename.renameTo(previousFilename);
+               previousFile.delete();
+               latestFile.renameTo(previousFile);
                for(int i=0;i<files.length;i++) {
                        File f = files[i];
                        String name = f.getName();
                        if(name.toLowerCase().startsWith(prefix)) {
-                               if(name.equals(previousFilename) || 
name.equals(latestFilename))
+                               if(name.equals(previousFile.getName()) || 
name.equals(latestFile.getName())) {
                                        continue;
+                               }
                                if(!name.endsWith(".log.gz")) {
                                        Logger.minor(this, "Does not end in 
.log.gz: "+name);
                                        f.delete();
@@ -548,7 +550,7 @@
                                oldFile = f;
                        } else {
                                // Nothing to do with us
-                               Logger.normal(this, "Unknown file: "+name+" in 
our log directory");
+                               Logger.normal(this, "Unknown file: "+name+" in 
the log directory");
                        }
                }
                if(oldFile != null) {


Reply via email to