incubator-ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1143723 - in /incubator/ace/trunk/ace-obr-storage: pom.xml src/main/java/org/apache/ace/obr/storage/file/BundleFileStore.java
Date Thu, 07 Jul 2011 09:17:29 GMT
Author: marrs
Date: Thu Jul  7 09:17:29 2011
New Revision: 1143723

URL: http://svn.apache.org/viewvc?rev=1143723&view=rev
Log:
ACE-154 fixed cross volume move, used Commons IO to handle the operation.

Modified:
    incubator/ace/trunk/ace-obr-storage/pom.xml
    incubator/ace/trunk/ace-obr-storage/src/main/java/org/apache/ace/obr/storage/file/BundleFileStore.java

Modified: incubator/ace/trunk/ace-obr-storage/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-obr-storage/pom.xml?rev=1143723&r1=1143722&r2=1143723&view=diff
==============================================================================
--- incubator/ace/trunk/ace-obr-storage/pom.xml (original)
+++ incubator/ace/trunk/ace-obr-storage/pom.xml Thu Jul  7 09:17:29 2011
@@ -52,7 +52,8 @@
         </import.package>
         <private.package>
             org.apache.ace.obr.storage.file,
-            org.apache.ace.obr.storage.file.constants
+            org.apache.ace.obr.storage.file.constants,
+            org.apache.commons.io
         </private.package>
         <bundle.activator>
             org.apache.ace.obr.storage.file.Activator
@@ -80,6 +81,10 @@
             <groupId>org.apache.ace</groupId>
             <artifactId>org.apache.ace.util</artifactId>
         </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.0.1</version>
+        </dependency>
     </dependencies>
-
 </project>
\ No newline at end of file

Modified: incubator/ace/trunk/ace-obr-storage/src/main/java/org/apache/ace/obr/storage/file/BundleFileStore.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-obr-storage/src/main/java/org/apache/ace/obr/storage/file/BundleFileStore.java?rev=1143723&r1=1143722&r2=1143723&view=diff
==============================================================================
--- incubator/ace/trunk/ace-obr-storage/src/main/java/org/apache/ace/obr/storage/file/BundleFileStore.java
(original)
+++ incubator/ace/trunk/ace-obr-storage/src/main/java/org/apache/ace/obr/storage/file/BundleFileStore.java
Thu Jul  7 09:17:29 2011
@@ -30,6 +30,7 @@ import java.util.concurrent.ConcurrentHa
 import org.apache.ace.obr.metadata.MetadataGenerator;
 import org.apache.ace.obr.storage.BundleStore;
 import org.apache.ace.obr.storage.file.constants.OBRFileStoreConstants;
+import org.apache.commons.io.FileUtils;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedService;
 import org.osgi.service.log.LogService;
@@ -66,31 +67,24 @@ public class BundleFileStore implements 
 
     public synchronized boolean put(String fileName, InputStream data) throws IOException
{
         File file = new File(m_dir, fileName);
+        boolean success = false;
         if (!file.exists()) {
-            FileOutputStream output = null;
             File tempFile = null;
-            boolean success = false;
             try {
                 tempFile = File.createTempFile("obr", ".tmp");
-                output = new FileOutputStream(tempFile);
-                byte[] buffer = new byte[BUFFER_SIZE];
-                for (int count = data.read(buffer); count != -1; count = data.read(buffer))
{
-                    output.write(buffer, 0, count);
-                }
-                success = true;
-            }
-            finally {
-                if (output != null) {
-                    output.flush();
-                    output.close();
-                }
+                // the reason for first writing to a temporary file is that we want to minimize
+                // the window where someone could be looking at a "partial" file that is
still being
+                // uploaded
+                FileUtils.copyInputStreamToFile(data, tempFile);
+                FileUtils.moveFile(tempFile, file);
+            }
+            catch (IOException e) {
+                // if anything goes wrong while reading from the input stream or
+                // moving the file, delete the temporary file
+                tempFile.delete();
             }
-            if (success) {
-                tempFile.renameTo(file);
-            }
-            return success;
         }
-        return false;
+        return success;
     }
 
     public synchronized boolean remove(String fileName) throws IOException {



Mime
View raw message