ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martijn Kruithof <...@apache.org>
Subject Re: Bug In org.apache.tools.ant.util.FileUtils
Date Fri, 04 Jan 2008 20:53:03 GMT
Hi

this change was intentional, a bugrep was filed that under certain 
circumstances the generated file name was used before it was created, 
which could indeed not be ruled out. For situations where only a name is 
needed the method createTempFileName was introduced.

I see your problem and have changed the solution to be backward 
compatible on the FileUtils. The createTempFileName method has been 
removed and a parameter has been added to the createTempFile method.

Martijn

Petar Tahchiev schreef:
> Hi guys,
>
> here is Petar Tahchiev from the Jakarta Cactus Team. I found that the
> current version of
> cactus's tasks cannot work with Ant 1.8.0alpha. When Trying to execute our
> tasks I get this
> exception:
> java.io.FileNotFoundException:
> /home/peter/workspace/Cactus/cactus13879tmp.dir/web.xml (Not a directory)
>         at java.io.FileOutputStream.open(Native Method)
>         at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
>         at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
>         at org.codehaus.cargo.module.AbstractDescriptorIo.writeDescriptor(
> AbstractDescriptorIo.java:110)
>
> We are using FileUtils from Ant to create a temporary directory to store
> some data, and the point is that
> from some time the FileUtils's method createTemFile changed its body. Now it
> is:
> ----------------------------------------------------------------------------------------------------------------------
>     public File createTempFile(String prefix, String suffix, File parentDir,
>                                boolean deleteOnExit) {
>         File result = null;
>         String parent = (parentDir == null)
>                 ? System.getProperty("java.io.tmpdir")
>                 : parentDir.getPath();
>         try {
>             result = File.createTempFile(prefix, suffix, new File(parent));
>         } catch (IOException e) {
>             throw new BuildException("Could not create tempfile in " +
> parent, e);
>         }
>         if (deleteOnExit) {
>             result.deleteOnExit();
>         }
>         return result;
>     }
> -------------------------------------------------------------------------------------------------------------------
>
> and it used to be:
>
> -------------------------------------------
>
>     public File createTempFile(String prefix, String suffix, File parentDir,
>             boolean deleteOnExit) {
>         File result = null;
>         String parent = (parentDir == null)
>             ? System.getProperty("java.io.tmpdir")
>             : parentDir.getPath();
>
>         DecimalFormat fmt = new DecimalFormat("#####");
>         synchronized (rand) {
>             do {
>             result = new File(parent,
>                            prefix + fmt.format(Math.abs(rand.nextInt()))
>                            + suffix);
>             } while (result.exists());
>         }
>         if (deleteOnExit) {
>             result.deleteOnExit();
>         }
>         return result;
>     }
> -------------------------------------------
>
> You see now the new file uses "File.createTempFile" to create the temp file.
> And here comes the
> problem, we use the createTempFile method to create directories. According
> to the Javadoc API:
>
> File.createTempFile - Creates an empty file in the default temporary-file
> directory, using the given prefix and suffix to generate its name.
>
> So every time it creates a file, instead of a directory, no matter if I say
> tempFile.mkdirs();  !!!
>
> I can implement the method I need myself, but I think that the clearer
> approach would be, you guys to bring back
> the old implementation of the method in the FileUtils, because there might
> be some other guys that use
> it to create a temporary folder.
>
> Hope I explained it well and didn't confuse you.
> Please let me know what you think, and keep me posted on CC, because I am
> not subscribed to dev@ant.apache.org.
>
> Thanks and have a good evening.
>
>   


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


Mime
View raw message