commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rahul Akolkar" <rahul.akol...@gmail.com>
Subject Re: [fileupload] svn commit: r735370
Date Sun, 18 Jan 2009 03:19:32 GMT
On Sat, Jan 17, 2009 at 8:40 PM,  <jochen@apache.org> wrote:
> 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
>
<snip/>
>
> 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
> +                    }


Catch the bits that makes sense to ignore here?

-Rahul

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message