[armedbear-cvs] r13307 - trunk/abcl/src/org/armedbear/lisp

mevenson at common-lisp.net mevenson at common-lisp.net
Sat Jun 4 20:27:27 UTC 2011


Author: mevenson
Date: Mon May 30 08:12:02 2011
New Revision: 13307

Log:
SYSTEM:ZIP now preserves last modified times.

Refactored common logic between two variants into auxillary methods.

Modified:
   trunk/abcl/src/org/armedbear/lisp/zip.java

Modified: trunk/abcl/src/org/armedbear/lisp/zip.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/zip.java	Mon May 30 06:40:19 2011	(r13306)
+++ trunk/abcl/src/org/armedbear/lisp/zip.java	Mon May 30 08:12:02 2011	(r13307)
@@ -36,6 +36,7 @@
 import static org.armedbear.lisp.Lisp.*;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -83,14 +84,7 @@
                                                   pathname.writeToString()));
                 }
                 File file = new File(namestring);
-                FileInputStream in = new FileInputStream(file);
-                ZipEntry entry = new ZipEntry(file.getName());
-                out.putNextEntry(entry);
-                int n;
-                while ((n = in.read(buffer)) > 0)
-                    out.write(buffer, 0, n);
-                out.closeEntry();
-                in.close();
+		makeEntry(out, file);
                 list = list.cdr();
             }
             out.close();
@@ -105,7 +99,6 @@
     public LispObject execute(LispObject first, LispObject second, LispObject third)
     {
         Pathname zipfilePathname = coerceToPathname(first);
-        byte[] buffer = new byte[4096];
         try {
             String zipfileNamestring = zipfilePathname.getNamestring();
             if (zipfileNamestring == null)
@@ -151,14 +144,7 @@
                     list = list.cdr();
                     continue;
                 }
-                FileInputStream in = new FileInputStream(file);
-                ZipEntry entry = new ZipEntry(directory + file.getName());
-                out.putNextEntry(entry);
-                int n;
-                while ((n = in.read(buffer)) > 0)
-                    out.write(buffer, 0, n);
-                out.closeEntry();
-                in.close();
+		makeEntry(out, file, directory + file.getName());
                 list = list.cdr();
             }
             out.close();
@@ -169,6 +155,30 @@
         return zipfilePathname;
     }
 
-
     private static final Primitive zip = new zip();
+
+    private void makeEntry(ZipOutputStream zip, File file) 
+	throws FileNotFoundException, IOException
+    {
+	makeEntry(zip, file, file.getName());
+    }
+
+    private void makeEntry(ZipOutputStream zip, File file, String name) 
+	throws FileNotFoundException, IOException
+    {
+        byte[] buffer = new byte[4096];
+	long lastModified = file.lastModified();
+	FileInputStream in = new FileInputStream(file);
+	ZipEntry entry = new ZipEntry(name);
+	if (lastModified > 0) {
+	    entry.setTime(lastModified);
+	}
+	zip.putNextEntry(entry);
+	int n;
+	while ((n = in.read(buffer)) > 0)
+	    zip.write(buffer, 0, n);
+	zip.closeEntry();
+	in.close();
+    }
+	
 }




More information about the armedbear-cvs mailing list