You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Diane Holt <ho...@yahoo.com> on 2000/10/02 06:49:42 UTC

unable to remove a file

What would cause <delete> to be unable to remove a file that I can 'rm' at
the command line (so it's not permission problems)? It's a file that's
generated in an earlier target, then read in by <property>, and if it
doesn't actually have a valid property-setting line in it, then the
property doesn't get set, so the target that checks whether the property
is set will echo an error message, delete the file (theoretically), then
do a <fail>. All of that works except the file deletion. The (verbose) log
snippet is:
   [...]
 [property] Loading D:\dianeh\src\nightly\build.properties
  Error: Build number not correctly set. Check your client environment.
   [delete] Deleting: D:\dianeh\src\nightly\build.properties

BUILD FAILED
build.xml:213: Unable to delete D:\dianeh\src\nightly\build.properties
Total time 3 seconds
Unable to delete file D:\dianeh\src\nightly\build.properties

So the BUILD FAILED is actually a result of the <delete> not being able to
complete, not a result of the <fail> that follows it (which never
executes, because ant exits on the <delete> failing). Reading the file in
with <property> wouldn't somehow keep the file in use, would it? 

Thanks,
Diane


=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Yahoo! Photos - 35mm Quality Prints, Now Get 15 Free!
http://photos.yahoo.com/

[PATCH] Property.java Re: unable to remove a file

Posted by Nico Seessle <ni...@seessle.de>.
Ensure the property-file is always closed after reading it - don't rely on
garbage collection.

----- Original Message -----
From: "Peter Donald" <pj...@cs.latrobe.edu.au>
To: <an...@jakarta.apache.org>
Sent: Monday, October 02, 2000 11:42 AM
Subject: Re: <delete> unable to remove a file


> >I'm not sure what Java is 'required to do' if you use something like
> >'props.load(new FileInputStream(file));' - it can immediately close the
file
> >after loading, but will it do in all cases?
>
> Nope and it is the source of much hell in developing on NT. You should
> always explictly close all file handles or else NT will not be able to
> delete them ;(
>


Re: unable to remove a file

Posted by Peter Donald <pj...@cs.latrobe.edu.au>.
At 09:31  2/10/00 +0200, you wrote:
>If it's not the propertyFile-task you may try to change 'loadFile' in
>Property.java as follows:
>
>    private void loadFile (File file) throws BuildException {
>        Properties props = new Properties();
>        log("Loading " + file.getAbsolutePath(), Project.MSG_VERBOSE);
>        try {
>            if (file.exists())
>
>                FileInputStream fis = new FileInputStream(file);
>                props.load(fis);
>                fis.close();
>                addProperties(props);
>            } else {
>                log("Unable to find " + file.getAbsolutePath(),
>                    Project.MSG_VERBOSE);
>            }
>        } catch(Exception ex) {
>            throw new BuildException(ex.getMessage(), ex, location);
>        }
>    }
>
>I'm not sure what Java is 'required to do' if you use something like
>'props.load(new FileInputStream(file));' - it can immediately close the file
>after loading, but will it do in all cases?

Nope and it is the source of much hell in developing on NT. You should
always explictly close all file handles or else NT will not be able to
delete them ;(


Cheers,

Pete

*------------------------------------------------------*
| "Nearly all men can stand adversity, but if you want |
| to test a man's character, give him power."          |
|       -Abraham Lincoln                               |
*------------------------------------------------------*

Re: unable to remove a file

Posted by Nico Seessle <ni...@seessle.de>.
----- Original Message -----
From: "Diane Holt" <ho...@yahoo.com>
To: <an...@jakarta.apache.org>
Sent: Monday, October 02, 2000 6:49 AM
Subject: <delete> unable to remove a file


> What would cause <delete> to be unable to remove a file that I can 'rm' at
> the command line (so it's not permission problems)?

You do the rm after ant fails right?

> It's a file that's
> generated in an earlier target, then read in by <property>, and if it
> doesn't actually have a valid property-setting line in it, then the
> property doesn't get set, so the target that checks whether the property
> is set will echo an error message, delete the file (theoretically), then
> do a <fail>. All of that works except the file deletion. The (verbose) log
> snippet is:

How is this file generated? Is it generated by the 'inofficial'
propertyFile-task which was send to the list? This gave me some trouble too,
but if you use the modified Version I mailed to you then it may work (I had
the same problems, seems to be too much file activity for windows somehow).

> So the BUILD FAILED is actually a result of the <delete> not being able to
> complete, not a result of the <fail> that follows it (which never
> executes, because ant exits on the <delete> failing). Reading the file in
> with <property> wouldn't somehow keep the file in use, would it?

If it's not the propertyFile-task you may try to change 'loadFile' in
Property.java as follows:

    private void loadFile (File file) throws BuildException {
        Properties props = new Properties();
        log("Loading " + file.getAbsolutePath(), Project.MSG_VERBOSE);
        try {
            if (file.exists())

                FileInputStream fis = new FileInputStream(file);
                props.load(fis);
                fis.close();
                addProperties(props);
            } else {
                log("Unable to find " + file.getAbsolutePath(),
                    Project.MSG_VERBOSE);
            }
        } catch(Exception ex) {
            throw new BuildException(ex.getMessage(), ex, location);
        }
    }

I'm not sure what Java is 'required to do' if you use something like
'props.load(new FileInputStream(file));' - it can immediately close the file
after loading, but will it do in all cases?

If this does not help also you may want (maybe) try to use the included
'sleep'task just before the delete?

Example usage:

   <taskdef name="sleep"
classname="org.apache.tools.ant.taskdefs.optional.Sleep"/>

   <target name="default">
     <echo message="1"/>
     <sleep seconds="5" gc="true"/>
     <echo message="2"/>
   </target>

Nico