You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Yves Dessertine <yv...@gmail.com> on 2009/01/26 12:36:55 UTC
Fwd: Make copy task fail if any destination file already exists?
Hi there.
It is possible with Ant to make a copy task fail if any destination
file already exists?
I found no clue in the docs (noticed only the "failonerror" param in
copy task (http://ant.apache.org/manual/CoreTasks/copy.html) and in
the condition for the "fail" task, but nothing relevant IMHO).
I know it would be possible to check the existance of an entire
folder, but this isn't suitable for my project.
I'd appreciate any help.
Thanks,
Yves Dessertine
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Make copy task fail if any destination file already exists?
Posted by David Weintraub <qa...@gmail.com>.
Sorry I didn't get back to you earlier...
One of the parameters of the <copy> task is the "overwrite" parameter.
This will prevent a file from being copied over even if the file
you're copying is a newer version. That won't fail the copy task, but
it will prevent you from overwriting existing files.
A possibility is the AntContrib <foreach> task
<http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html> combined
with the fail task which can fail on a condition. You can iterate over
the list of files in what you're copying, and then check to see if
that file already exists:
<foreach
target="file.exists.test"
param="file.name">
<fileset dir="${copy.dir}"/>
<foreach>
<target name="file.exists.test">
<fail message="${file.name} already exists">
<condition>
<available file="${file.name}"
</condition>
</target>
On Mon, Jan 26, 2009 at 6:36 AM, Yves Dessertine <yv...@gmail.com> wrote:
> Hi there.
>
> It is possible with Ant to make a copy task fail if any destination
> file already exists?
>
> I found no clue in the docs (noticed only the "failonerror" param in
> copy task (http://ant.apache.org/manual/CoreTasks/copy.html) and in
> the condition for the "fail" task, but nothing relevant IMHO).
>
> I know it would be possible to check the existance of an entire
> folder, but this isn't suitable for my project.
>
> I'd appreciate any help.
>
> Thanks,
>
> Yves Dessertine
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
--
--
David Weintraub
qazwart@gmail.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
RE: Make copy task fail if any destination file already exists?
Posted by Chun Ji <CJ...@pro-unlimited.com>.
I don't know if ant/copy can handle it, but
1. It should be very easy to check the targetDir if there is any
existing files in ANT.
2. You can do your copy reversely, from your targetDir to your
sourceDir, so that these existing files are untouched. Then move
everything from your sourceDir to your targetDir. (I guess none of the
existing files are read-only ? )
-Charlie.
-----Original Message-----
From: Yves Dessertine [mailto:yvesd.public@gmail.com]
Sent: Tuesday, January 27, 2009 9:56 AM
To: Ant Users List
Subject: Re: Make copy task fail if any destination file already exists?
Okay, the problem is, these files can be overwritten (they won't be
locked by the OS for example). I need to make sure that:
- Ant don't overwrite them
- An error is triggered, to alert the user.
2009/1/27 Chun Ji <CJ...@pro-unlimited.com>:
>
> It happens if these existing files can not be overwritten.
>
> -Charlie
>
> -----Original Message-----
> From: Yves Dessertine [mailto:yvesd.public@gmail.com]
> Sent: Tuesday, January 27, 2009 9:38 AM
> To: Ant Users List
> Subject: Re: Make copy task fail if any destination file already
exists?
>
> I'll explain a bit more.
>
> I have the following example build.xml file :
>
> <project name="fooproject" default="usage" basedir=".">
> <target name="foo">
> <copy toDir="targetTree">
> <fileset dir="sourceTree" />
> </copy>
> </target>
>
> <target name="usage">
> <echo>foo bar</echo>
> </target>
> </project>
>
>
>
> Project layout looks like this :
>
> testproj
> +--- build.xml
> +--- sourceTree
> +--- bar.txt
> +--- subdir
> +--- boo.bmp
> +--- boo1.bmp
> +--- targetDir
> +--- <any number of files here>
> +--- subdir
> +--- otherfile_only_in_target.txt
> +--- <any number of files here>
> +--- foo1.bmp <== this already exists: error!
>
> Its task is to copy any number of files from sourceDir to targetDir,
> but throwing an error if any file to be copied already exists in
> targetDir
>
> Here, I need the copy task to fail because subdir/foo1.bmp already
> exists. It is possible to do such a thing w/ ant ?
>
> Regards,
>
> Yves Dessertine
>
>
> 2009/1/26 Yves Dessertine <yv...@gmail.com>:
>> Thank you for your answer. the <available> task is interessting, but
>> it isn't what I need. What I need is to copy a directory with
>> subdirectories within another dir, with subdirs which might have the
>> same name (to merge the contents of both), but while triggering an
>> error if any file already exists in the target dir.
>>
>> This looks quite complicated to do with ant.
>>
>>
>> 2009/1/26 <Ja...@rzf.fin-nrw.de>:
>>>>It is possible with Ant to make a copy task fail if any destination
>>>>file already exists?
>>>>
>>>>I found no clue in the docs (noticed only the "failonerror" param in
>>>>copy task (http://ant.apache.org/manual/CoreTasks/copy.html) and in
>>>>the condition for the "fail" task, but nothing relevant IMHO).
>>>>
>>>>I know it would be possible to check the existance of an entire
>>>>folder, but this isn't suitable for my project.
>>>
>>>
>>> This is not <copy>s job.
>>> Try <available>.
>>>
>>>
>>> Jan
>>>
>>>
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: user-help@ant.apache.org
>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Make copy task fail if any destination file already exists?
Posted by Yves Dessertine <yv...@gmail.com>.
Okay, the problem is, these files can be overwritten (they won't be
locked by the OS for example). I need to make sure that:
- Ant don't overwrite them
- An error is triggered, to alert the user.
2009/1/27 Chun Ji <CJ...@pro-unlimited.com>:
>
> It happens if these existing files can not be overwritten.
>
> -Charlie
>
> -----Original Message-----
> From: Yves Dessertine [mailto:yvesd.public@gmail.com]
> Sent: Tuesday, January 27, 2009 9:38 AM
> To: Ant Users List
> Subject: Re: Make copy task fail if any destination file already exists?
>
> I'll explain a bit more.
>
> I have the following example build.xml file :
>
> <project name="fooproject" default="usage" basedir=".">
> <target name="foo">
> <copy toDir="targetTree">
> <fileset dir="sourceTree" />
> </copy>
> </target>
>
> <target name="usage">
> <echo>foo bar</echo>
> </target>
> </project>
>
>
>
> Project layout looks like this :
>
> testproj
> +--- build.xml
> +--- sourceTree
> +--- bar.txt
> +--- subdir
> +--- boo.bmp
> +--- boo1.bmp
> +--- targetDir
> +--- <any number of files here>
> +--- subdir
> +--- otherfile_only_in_target.txt
> +--- <any number of files here>
> +--- foo1.bmp <== this already exists: error!
>
> Its task is to copy any number of files from sourceDir to targetDir,
> but throwing an error if any file to be copied already exists in
> targetDir
>
> Here, I need the copy task to fail because subdir/foo1.bmp already
> exists. It is possible to do such a thing w/ ant ?
>
> Regards,
>
> Yves Dessertine
>
>
> 2009/1/26 Yves Dessertine <yv...@gmail.com>:
>> Thank you for your answer. the <available> task is interessting, but
>> it isn't what I need. What I need is to copy a directory with
>> subdirectories within another dir, with subdirs which might have the
>> same name (to merge the contents of both), but while triggering an
>> error if any file already exists in the target dir.
>>
>> This looks quite complicated to do with ant.
>>
>>
>> 2009/1/26 <Ja...@rzf.fin-nrw.de>:
>>>>It is possible with Ant to make a copy task fail if any destination
>>>>file already exists?
>>>>
>>>>I found no clue in the docs (noticed only the "failonerror" param in
>>>>copy task (http://ant.apache.org/manual/CoreTasks/copy.html) and in
>>>>the condition for the "fail" task, but nothing relevant IMHO).
>>>>
>>>>I know it would be possible to check the existance of an entire
>>>>folder, but this isn't suitable for my project.
>>>
>>>
>>> This is not <copy>s job.
>>> Try <available>.
>>>
>>>
>>> Jan
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: user-help@ant.apache.org
>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
RE: Make copy task fail if any destination file already exists?
Posted by Chun Ji <CJ...@pro-unlimited.com>.
It happens if these existing files can not be overwritten.
-Charlie
-----Original Message-----
From: Yves Dessertine [mailto:yvesd.public@gmail.com]
Sent: Tuesday, January 27, 2009 9:38 AM
To: Ant Users List
Subject: Re: Make copy task fail if any destination file already exists?
I'll explain a bit more.
I have the following example build.xml file :
<project name="fooproject" default="usage" basedir=".">
<target name="foo">
<copy toDir="targetTree">
<fileset dir="sourceTree" />
</copy>
</target>
<target name="usage">
<echo>foo bar</echo>
</target>
</project>
Project layout looks like this :
testproj
+--- build.xml
+--- sourceTree
+--- bar.txt
+--- subdir
+--- boo.bmp
+--- boo1.bmp
+--- targetDir
+--- <any number of files here>
+--- subdir
+--- otherfile_only_in_target.txt
+--- <any number of files here>
+--- foo1.bmp <== this already exists: error!
Its task is to copy any number of files from sourceDir to targetDir,
but throwing an error if any file to be copied already exists in
targetDir
Here, I need the copy task to fail because subdir/foo1.bmp already
exists. It is possible to do such a thing w/ ant ?
Regards,
Yves Dessertine
2009/1/26 Yves Dessertine <yv...@gmail.com>:
> Thank you for your answer. the <available> task is interessting, but
> it isn't what I need. What I need is to copy a directory with
> subdirectories within another dir, with subdirs which might have the
> same name (to merge the contents of both), but while triggering an
> error if any file already exists in the target dir.
>
> This looks quite complicated to do with ant.
>
>
> 2009/1/26 <Ja...@rzf.fin-nrw.de>:
>>>It is possible with Ant to make a copy task fail if any destination
>>>file already exists?
>>>
>>>I found no clue in the docs (noticed only the "failonerror" param in
>>>copy task (http://ant.apache.org/manual/CoreTasks/copy.html) and in
>>>the condition for the "fail" task, but nothing relevant IMHO).
>>>
>>>I know it would be possible to check the existance of an entire
>>>folder, but this isn't suitable for my project.
>>
>>
>> This is not <copy>s job.
>> Try <available>.
>>
>>
>> Jan
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Make copy task fail if any destination file already exists?
Posted by Yves Dessertine <yv...@gmail.com>.
I'll explain a bit more.
I have the following example build.xml file :
<project name="fooproject" default="usage" basedir=".">
<target name="foo">
<copy toDir="targetTree">
<fileset dir="sourceTree" />
</copy>
</target>
<target name="usage">
<echo>foo bar</echo>
</target>
</project>
Project layout looks like this :
testproj
+--- build.xml
+--- sourceTree
+--- bar.txt
+--- subdir
+--- boo.bmp
+--- boo1.bmp
+--- targetDir
+--- <any number of files here>
+--- subdir
+--- otherfile_only_in_target.txt
+--- <any number of files here>
+--- foo1.bmp <== this already exists: error!
Its task is to copy any number of files from sourceDir to targetDir,
but throwing an error if any file to be copied already exists in
targetDir
Here, I need the copy task to fail because subdir/foo1.bmp already
exists. It is possible to do such a thing w/ ant ?
Regards,
Yves Dessertine
2009/1/26 Yves Dessertine <yv...@gmail.com>:
> Thank you for your answer. the <available> task is interessting, but
> it isn't what I need. What I need is to copy a directory with
> subdirectories within another dir, with subdirs which might have the
> same name (to merge the contents of both), but while triggering an
> error if any file already exists in the target dir.
>
> This looks quite complicated to do with ant.
>
>
> 2009/1/26 <Ja...@rzf.fin-nrw.de>:
>>>It is possible with Ant to make a copy task fail if any destination
>>>file already exists?
>>>
>>>I found no clue in the docs (noticed only the "failonerror" param in
>>>copy task (http://ant.apache.org/manual/CoreTasks/copy.html) and in
>>>the condition for the "fail" task, but nothing relevant IMHO).
>>>
>>>I know it would be possible to check the existance of an entire
>>>folder, but this isn't suitable for my project.
>>
>>
>> This is not <copy>s job.
>> Try <available>.
>>
>>
>> Jan
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Make copy task fail if any destination file already exists?
Posted by Yves Dessertine <yv...@gmail.com>.
Thank you for your answer. the <available> task is interessting, but
it isn't what I need. What I need is to copy a directory with
subdirectories within another dir, with subdirs which might have the
same name (to merge the contents of both), but while triggering an
error if any file already exists in the target dir.
This looks quite complicated to do with ant.
2009/1/26 <Ja...@rzf.fin-nrw.de>:
>>It is possible with Ant to make a copy task fail if any destination
>>file already exists?
>>
>>I found no clue in the docs (noticed only the "failonerror" param in
>>copy task (http://ant.apache.org/manual/CoreTasks/copy.html) and in
>>the condition for the "fail" task, but nothing relevant IMHO).
>>
>>I know it would be possible to check the existance of an entire
>>folder, but this isn't suitable for my project.
>
>
> This is not <copy>s job.
> Try <available>.
>
>
> Jan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
AW: Make copy task fail if any destination file already exists?
Posted by Ja...@rzf.fin-nrw.de.
>It is possible with Ant to make a copy task fail if any destination
>file already exists?
>
>I found no clue in the docs (noticed only the "failonerror" param in
>copy task (http://ant.apache.org/manual/CoreTasks/copy.html) and in
>the condition for the "fail" task, but nothing relevant IMHO).
>
>I know it would be possible to check the existance of an entire
>folder, but this isn't suitable for my project.
This is not <copy>s job.
Try <available>.
Jan
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org