ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Petar Tahchiev" <paranoia...@gmail.com>
Subject Bug In org.apache.tools.ant.util.FileUtils
Date Sat, 29 Dec 2007 19:53:22 GMT
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.

-- 
Regards, Petar!
Karlovo, Bulgaria.

EOOXML Objections
http://www.grokdoc.net/index.php/EOOXML_objections

Public PGP Key at:
https://keyserver1.pgp.com/vkd/DownloadKey.event?keyid=0x19658550C3110611
Key Fingerprint: A369 A7EE 61BC 93A3 CDFF  55A5 1965 8550 C311 0611

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message