On 7 August 2011 11:37,  <[email protected]> wrote:
> Author: markt
> Date: Sun Aug  7 10:37:16 2011
> New Revision: 1154689
>
> URL: http://svn.apache.org/viewvc?rev=1154689&view=rev
> Log:
> Only try and create the dir if it doesn't already exist
>
> Modified:
>    tomcat/trunk/java/org/apache/juli/FileHandler.java
>
> Modified: tomcat/trunk/java/org/apache/juli/FileHandler.java
> URL: 
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/juli/FileHandler.java?rev=1154689&r1=1154688&r2=1154689&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/juli/FileHandler.java (original)
> +++ tomcat/trunk/java/org/apache/juli/FileHandler.java Sun Aug  7 10:37:16 
> 2011
> @@ -363,7 +363,7 @@ public class FileHandler
>
>         // Create the directory if necessary
>         File dir = new File(directory);
> -        if (!dir.mkdirs()) {
> +        if (!dir.exists() && !dir.mkdirs()) {

There's a theoretical timing window here when something else could
create the directory.
[mkdirs() returns true only if it actually created the dir. Not
entirely helpful behaviour IMO]

Reversing the order should close the window, i.e.

        // check for dir existence afterwards in case someone else created it
        if (!dir.mkdirs() && !dir.exists() ) {

If you don't want to call mkdirs() if the dir already exists, then how about:

        // check for dir existence at end in case someone else created it
        if (!dir.exists() && !dir.mkdirs() && !dir.exists() ) {

However, that is the first check done by the RI anyway.

>             reportError("Unable to create [" + dir + "]", null,
>                     ErrorManager.OPEN_FAILURE);
>             writer = null;
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to