You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jh...@apache.org on 2005/09/09 16:36:38 UTC
svn commit: r279784 -
/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/multipart/MultipartParser.java
Author: jheymans
Date: Fri Sep 9 07:36:34 2005
New Revision: 279784
URL: http://svn.apache.org/viewcvs?rev=279784&view=rev
Log:
Fix for bug #29712, thanks to Gunnar Brand <g....@interface-business.de>
Modified:
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/multipart/MultipartParser.java
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/multipart/MultipartParser.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/multipart/MultipartParser.java?rev=279784&r1=279783&r2=279784&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/multipart/MultipartParser.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/servlet/multipart/MultipartParser.java Fri Sep 9 07:36:34 2005
@@ -232,31 +232,38 @@
if (!allowOverwrite && !file.createNewFile()) {
if (silentlyRename) {
int c = 0;
-
do {
file = new File(filePath + c++ + "_" + fileName);
} while (!file.createNewFile());
} else {
- throw new MultipartException("Duplicate file "
- + file.getName() + ".");
+ throw new MultipartException("Duplicate file '" + file.getName()
+ + "' in '" + file.getParent() + "'");
}
}
out = new FileOutputStream(file);
}
- int read = 0;
- while (in.getState() == TokenStream.STATE_READING) { // read data
- read = in.read(buf);
- out.write(buf, 0, read);
+ try {
+ int read = 0;
+ while (in.getState() == TokenStream.STATE_READING) { // read data
+ read = in.read(buf);
+ out.write(buf, 0, read);
+ }
+ } catch (IOException ioe) {
+ // don't let incomplete file uploads pile up in the upload dir.
+ // this usually happens with aborted form submits containing very large files.
+ out.close();
+ out = null;
+ if ( file!=null ) file.delete();
+ throw ioe;
+ } finally {
+ if ( out!=null ) out.close();
}
-
- out.close();
if (file == null) {
byte[] bytes = ((ByteArrayOutputStream) out).toByteArray();
-
this.parts.put(headers.get("name"),
- new PartInMemory(headers, new ByteArrayInputStream(bytes),bytes.length));
+ new PartInMemory(headers, new ByteArrayInputStream(bytes),bytes.length));
} else {
this.parts.put(headers.get("name"), new PartOnDisk(headers, file));
}