jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cko...@apache.org
Subject svn commit: r1358543 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/data/db/ main/java/org/apache/jackrabbit/core/util/db/ test/java/org/apache/jackrabbit/core/data/
Date Sat, 07 Jul 2012 11:26:15 GMT
Author: ckoell
Date: Sat Jul  7 11:26:15 2012
New Revision: 1358543

URL: http://svn.apache.org/viewvc?rev=1358543&view=rev
Log:
JCR-3377 DataStore Temp-Files will not be deleted as side effect of JCR-3318

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/TempFileInputStream.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/StreamWrapper.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TempFileInputStreamTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java?rev=1358543&r1=1358542&r2=1358543&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
Sat Jul  7 11:26:15 2012
@@ -347,7 +347,7 @@ public class DbDataStore implements Data
             } else if (STORE_TEMP_FILE.equals(storeStream)) {
                 File temp = moveToTempFile(in);
                 long length = temp.length();
-                wrapper = new StreamWrapper(new TempFileInputStream(temp), length);
+                wrapper = new StreamWrapper(new TempFileInputStream(temp, true), length);
             } else {
                 throw new DataStoreException("Unsupported stream store algorithm: " + storeStream);
             }
@@ -578,7 +578,7 @@ public class DbDataStore implements Data
             } else if (copyWhenReading) {
                 // If we copy while reading, create a temp file and close the stream
                 File temp = moveToTempFile(stream);
-                stream = new BufferedInputStream(new TempFileInputStream(temp));
+                stream = new BufferedInputStream(new TempFileInputStream(temp, false));
                 DbUtility.close(rs);
             } else {
                 stream = new BufferedInputStream(stream);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/TempFileInputStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/TempFileInputStream.java?rev=1358543&r1=1358542&r2=1358543&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/TempFileInputStream.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/TempFileInputStream.java
Sat Jul  7 11:26:15 2012
@@ -39,6 +39,7 @@ public class TempFileInputStream extends
 
     private final File file;
     private boolean closed;
+    private boolean delayedResourceCleanup = true;
 
     /**
      * Copy the data to a file and close the input stream afterwards.
@@ -57,14 +58,17 @@ public class TempFileInputStream extends
 
     /**
      * Construct a new temporary file input stream.
-     * The file is deleted if the input stream is closed or fully read.
+     * The file is deleted if the input stream is closed or fully read and 
+     * delayedResourceCleanup was set to true. Otherwise you must call {@link #deleteFile()}.
      * Deleting is only attempted once.
      *
      * @param file the temporary file
+     * @param delayedResourceCleanup
      */
-    public TempFileInputStream(File file) throws FileNotFoundException {
+    public TempFileInputStream(File file, boolean delayedResourceCleanup) throws FileNotFoundException
{
         super(new BufferedInputStream(new FileInputStream(file)));
         this.file = file;
+        this.delayedResourceCleanup = delayedResourceCleanup;
     }
 
     public File getFile() {
@@ -85,6 +89,9 @@ public class TempFileInputStream extends
     public void close() throws IOException {
         if (!closed) {
             in.close();
+            if (!delayedResourceCleanup) {
+            	deleteFile();
+            }
             closed = true;
         }
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/StreamWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/StreamWrapper.java?rev=1358543&r1=1358542&r2=1358543&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/StreamWrapper.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/StreamWrapper.java
Sat Jul  7 11:26:15 2012
@@ -85,7 +85,7 @@ public class StreamWrapper {
 	    		TempFileInputStream tempFileInputStream = (TempFileInputStream) stream;
 	    		// Close it if it is not already closed ...
 	    		tempFileInputStream.close();
-    			stream = new TempFileInputStream(tempFileInputStream.getFile());
+    			stream = new TempFileInputStream(tempFileInputStream.getFile(), true);
     			return true;
     		} catch (Exception e) {
     			log.warn("Failed to create a new TempFileInputStream", e);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TempFileInputStreamTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TempFileInputStreamTest.java?rev=1358543&r1=1358542&r2=1358543&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TempFileInputStreamTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TempFileInputStreamTest.java
Sat Jul  7 11:26:15 2012
@@ -33,7 +33,7 @@ public class TempFileInputStreamTest ext
     public void testReadPastEOF() throws IOException {
         File temp = File.createTempFile("test", null);
         TempFileInputStream.writeToFileAndClose(new ByteArrayInputStream(new byte[1]), temp);
-        TempFileInputStream in = new TempFileInputStream(temp);
+        TempFileInputStream in = new TempFileInputStream(temp, false);
         assertEquals(0, in.read());
         assertEquals(-1, in.read());
         assertEquals(-1, in.read());
@@ -44,7 +44,7 @@ public class TempFileInputStreamTest ext
     public void testMarkReset() throws IOException {
         File temp = File.createTempFile("test", null);
         TempFileInputStream.writeToFileAndClose(new ByteArrayInputStream(new byte[10]), temp);
-        InputStream in = new BufferedInputStream(new TempFileInputStream(temp));
+        InputStream in = new BufferedInputStream(new TempFileInputStream(temp, false));
         in.mark(100);
         for (int i = 0; i < 10; i++) {
             assertEquals(0, in.read());



Mime
View raw message