commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joc...@apache.org
Subject svn commit: r735370 - in /commons/proper/fileupload/trunk: pom.xml src/changes/changes.xml src/java/org/apache/commons/fileupload/FileUploadBase.java
Date Sun, 18 Jan 2009 01:40:14 GMT
Author: jochen
Date: Sat Jan 17 17:40:13 2009
New Revision: 735370

URL: http://svn.apache.org/viewvc?rev=735370&view=rev
Log:
PR: FILEUPLOAD-160
Submitted-By: Stepan Koltsov <yozh@mx1.ru>
Temporary files have not been deleted, if an error
occurred in FileUploadBase.parseRequest.

Modified:
    commons/proper/fileupload/trunk/pom.xml
    commons/proper/fileupload/trunk/src/changes/changes.xml
    commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java

Modified: commons/proper/fileupload/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/pom.xml?rev=735370&r1=735369&r2=735370&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/pom.xml (original)
+++ commons/proper/fileupload/trunk/pom.xml Sat Jan 17 17:40:13 2009
@@ -101,6 +101,10 @@
       <email>ggregory@seagullsw.com</email>
     </contributor>
     <contributor>
+      <name>Stepan Koltsov</name>
+      <email>yozh@mx1.ru</email>
+    </contributor>
+    <contributor>
       <name>Michael Macaluso</name>
       <email>michael.public@wavecorp.com</email>
     </contributor>

Modified: commons/proper/fileupload/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/changes/changes.xml?rev=735370&r1=735369&r2=735370&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/changes/changes.xml (original)
+++ commons/proper/fileupload/trunk/src/changes/changes.xml Sat Jan 17 17:40:13 2009
@@ -42,7 +42,13 @@
 
   <body>
     <release version="1.3-SNAPSHOT" date="Not yet released">
+      <action dev="jochen" type="fix" issue="FILEUPLOAD-160"
+          due-to="Stepan Koltsov" due-to-email="yozh@mx1.ru">
+        Temporary files have not been deleted, if an error
+        occurred in FileUploadBase.parseRequest();
+      </action>
     </release>
+
     <release version="1.2.1" date="2008-01-18">
       <action dev="jochen" type="fix">
         Upgrade to commons-io-1.4-SNAPSHOT, in order to use the new

Modified: commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java?rev=735370&r1=735369&r2=735370&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java
(original)
+++ commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java
Sat Jan 17 17:40:13 2009
@@ -345,9 +345,10 @@
      */
     public List /* FileItem */ parseRequest(RequestContext ctx)
             throws FileUploadException {
+        List items = new ArrayList();
+        boolean successful = false;
         try {
             FileItemIterator iter = getItemIterator(ctx);
-            List items = new ArrayList();
             FileItemFactory fac = getFileItemFactory();
             if (fac == null) {
                 throw new NullPointerException(
@@ -358,6 +359,7 @@
                 FileItem fileItem = fac.createItem(item.getFieldName(),
                         item.getContentType(), item.isFormField(),
                         item.getName());
+                items.add(fileItem);
                 try {
                     Streams.copy(item.openStream(), fileItem.getOutputStream(),
                             true);
@@ -372,13 +374,24 @@
                     final FileItemHeaders fih = item.getHeaders();
                     ((FileItemHeadersSupport) fileItem).setHeaders(fih);
                 }
-                items.add(fileItem);
             }
+            successful = true;
             return items;
         } catch (FileUploadIOException e) {
             throw (FileUploadException) e.getCause();
         } catch (IOException e) {
             throw new FileUploadException(e.getMessage(), e);
+        } finally {
+            if (!successful) {
+                for (Iterator iterator = items.iterator(); iterator.hasNext();) {
+                    FileItem fileItem = (FileItem) iterator.next();
+                    try {
+                        fileItem.delete();
+                    } catch (Throwable e) {
+                        // ignore it
+                    }
+                }
+            }
         }
     }
 



Mime
View raw message