You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jo...@apache.org on 2003/11/08 16:36:46 UTC

cvs commit: cocoon-2.1/src/java/org/apache/cocoon/servlet/multipart MultipartParser.java

joerg       2003/11/08 07:36:46

  Modified:    src/java/org/apache/cocoon/servlet/multipart
                        MultipartParser.java
  Log:
  replaced file.exists() with !file.createNewFile() for atomic exist test + file creation operation (suggested by Stephen White, bug 24401, see JDK JavaDoc for more info)
  
  Revision  Changes    Path
  1.4       +11 -13    cocoon-2.1/src/java/org/apache/cocoon/servlet/multipart/MultipartParser.java
  
  Index: MultipartParser.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/servlet/multipart/MultipartParser.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MultipartParser.java	29 Oct 2003 19:44:21 -0000	1.3
  +++ MultipartParser.java	8 Nov 2003 15:36:46 -0000	1.4
  @@ -248,18 +248,16 @@
               fileName = new File(fileName).getName();
               file = new File(filePath + fileName);
   
  -            if (file.exists()) {
  -                if (!allowOverwrite) {
  -                    if (silentlyRename) {
  -                        int c = 0;
  +            if (!allowOverwrite && !file.createNewFile()) {
  +                if (silentlyRename) {
  +                    int c = 0;
   
  -                        do {
  -                            file = new File(filePath + c++ + "_" + fileName);
  -                        } while (file.exists());
  -                    } else {
  -                        throw new MultipartException("Duplicate file "
  -                                + file.getName() + ".");
  -                    }
  +                    do {
  +                        file = new File(filePath + c++ + "_" + fileName);
  +                    } while (!file.createNewFile());
  +                } else {
  +                    throw new MultipartException("Duplicate file "
  +                            + file.getName() + ".");
                   }
               }