You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by David Weintraub <qa...@gmail.com> on 2009/07/08 20:05:55 UTC

Re: Ant 1.7: unzip with overwrite set to 'false' is overwriting files

Quick question: What is the timestamp on these files?

If you set the overwrite parameter to false, it may be overwriting
files that have an OLDER timestamp than the file that's replacing it.

The description of this parameter is:

    Overwrite files, even if they are newer than the corresponding entries
    in the archive (true or false, default is true).

I'll have to examine the Ant source code to see exactly what it is doing.

On Wed, Jul 8, 2009 at 11:27 AM, rdblaha1<rd...@hotmail.com> wrote:
>
> I have the following code in my xml Ant file:
>
>        <unzip dest="${APPLICATION_DIRECTORY}" overwrite="false">
>                <fileset dir="${TMP_DIR}">
>                        <include name="*.zip"/>
>                </fileset>
>        </unzip>
>
> Yet in my output I see that three files existing in my config directory are
> overwritten when the unzip occurs.
>
>    [unzip] expanding config/setup1.properties to
> c:\application\config\setup1.properties
>    [unzip] expanding config/setup2.properties to
> c:\application\config\setup2.properties
>    [unzip] expanding config/setup3.properties to
> c:\application\config\setup3.properties
>
> How is the overwrite attribute suppose to work if this syntax is correct?
>
> --
> View this message in context: http://www.nabble.com/Ant-1.7%3A--unzip-with-overwrite-set-to-%27false%27-is-overwriting-files-tp24393106p24393106.html
> Sent from the Ant - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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: Ant 1.7: unzip with overwrite set to 'false' is overwriting files

Posted by rdblaha1 <rd...@hotmail.com>.
Success!


David Weintraub wrote:
> 
> Would using the <touch> task help? Before unzipping, you can "touch"
> all the properties files that you don't want to overwrite, giving them
> a newer timestamp than the files inside the zipfile.
> 
> Of course, you'll destroy the previous dates, but it will help prevent
> overwriting.
> 

Good suggestion, but we couldn't do this as timestamp of files is important
in our implementation.



> The other possibility is to test for the config properties files, and
> if they don't exist, unzip normally. If they do exist, use the exclude
> pattern. Here's a very rough and untested way of doing it:
> 
> The unzip task now simply tests to see whether or not you have
> properties files. If you do, you do the unzip.selected and skip
> unpacking the properties files. If you don't, you use the "unzip.all"
> task and skip over the properties files.
> 

OK.  Here is a tested way of doing this and is working in initial testing. 
Hope this helps someone else too.

<target name="writeon">
<!-- This assumes that you either have all the config/setup#.properties
files or none of them -->
    <fileset id="config.files" dir="${APPLICATION_DIRECTORY}">
		<include name="config/setup1.properties"/>
		<include name="config/setup2.properties"/>
		<include name="config/setup3.properties"/>
    </fileset>

    <condition property="config.properties.exist">
        <resourcecount refid="config.files" when="greater" count="0"/>
   </condition>

    <antcall target="writeon.all"/>
    <antcall target="writeon.selected"/>
</target>

<target name="writeon.all" unless="config.properties.exist">
	<!-- unzip the package and overwrite the config/setup#.properties; they
shouldn't be there -->
	<!-- overwrite="false" only works when the timestamp is NEWER, not OLDER
-->
	<unzip dest="${APPLICATION_DIRECTORY}" overwrite="false">
		<fileset dir="${TMP_DIR}">
			<include name="*.zip"/>
		</fileset>
	</unzip>
</target>

<target name="writeon.selected" if="config.properties.exist">
	<!-- unzip the package, but don't overwrite the config/setup#.properties
-->
	<!-- overwrite="false" only works when the timestamp is NEWER, not OLDER
-->
	<unzip dest="${APPLICATION_DIRECTORY}" overwrite="false">
		<patternset>
			<exclude name="config/*.properties"/>
		</patternset>
		<fileset dir="${TMP_DIR}">
			<include name="*.zip"/>
		</fileset>
	</unzip>
</target>

-- 
View this message in context: http://www.nabble.com/Ant-1.7%3A--unzip-with-overwrite-set-to-%27false%27-is-overwriting-files-tp24393106p24413339.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: Ant 1.7: unzip with overwrite set to 'false' is overwriting files

Posted by David Weintraub <qa...@gmail.com>.
On Wed, Jul 8, 2009 at 2:22 PM, rdblaha1<rd...@hotmail.com> wrote:
>
> Thank you David for pointing out the OLDER vs. NEWER timestamp.  The
> timestamp of the existing files is always OLDER in my testing.

Would using the <touch> task help? Before unzipping, you can "touch"
all the properties files that you don't want to overwrite, giving them
a newer timestamp than the files inside the zipfile.

Of course, you'll destroy the previous dates, but it will help prevent
overwriting.

The other possibility is to test for the config properties files, and
if they don't exist, unzip normally. If they do exist, use the exclude
pattern. Here's a very rough and untested way of doing it:

The unzip task now simply tests to see whether or not you have
properties files. If you do, you do the unzip.selected and skip
unpacking the properties files. If you don't, you use the "unzip.all"
task and skip over the properties files.

Of course, this assumes that you either have all the properties files
or none of them:

<target name="unzip"
    <fileset id="config.files" dir="${TMP_DIR}/config">
          <include name="*.properties"/>
    </fileset>

    <condition property="config.properties.exist">
        <resourcecount refid="config.files" when="greater" count="0"/>
   </condition>

    depends="unzip.test">
    <antcall target=unzip.all/>
    <antcall target="unzip.selected"/>
</target>

<target name="unzip.all"
    unless="config.properties.exist">

</target>

<target name="unzip.selected">
    if="config.properties.exist>

</target>

Try the <touch> task first and see if that  will fix your issue.

>
> My problem isn't solved with the patternset as I previously thought.  If my
> config properties files don't exist in the dest directory in the first place
> I DO want them there.  The patternset will always exclude them whether they
> exist or not.   I need someway to just simply NOT overwrite them if they
> exist OLDER or NEWER timestamp.  In that case what would you suggest?
>
> Thanks again David,
> Rick Blaha
>
>
>
> David Weintraub wrote:
>>
>> Quick question: What is the timestamp on these files?
>>
>> If you set the overwrite parameter to false, it may be overwriting
>> files that have an OLDER timestamp than the file that's replacing it.
>>
>> The description of this parameter is:
>>
>>     Overwrite files, even if they are newer than the corresponding entries
>>     in the archive (true or false, default is true).
>>
>
> --
> View this message in context: http://www.nabble.com/Ant-1.7%3A--unzip-with-overwrite-set-to-%27false%27-is-overwriting-files-tp24393106p24396800.html
> Sent from the Ant - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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: Ant 1.7: unzip with overwrite set to 'false' is overwriting files

Posted by rdblaha1 <rd...@hotmail.com>.
Thank you David for pointing out the OLDER vs. NEWER timestamp.  The
timestamp of the existing files is always OLDER in my testing.

My problem isn't solved with the patternset as I previously thought.  If my
config properties files don't exist in the dest directory in the first place
I DO want them there.  The patternset will always exclude them whether they
exist or not.   I need someway to just simply NOT overwrite them if they
exist OLDER or NEWER timestamp.  In that case what would you suggest?

Thanks again David,
Rick Blaha



David Weintraub wrote:
> 
> Quick question: What is the timestamp on these files?
> 
> If you set the overwrite parameter to false, it may be overwriting
> files that have an OLDER timestamp than the file that's replacing it.
> 
> The description of this parameter is:
> 
>     Overwrite files, even if they are newer than the corresponding entries
>     in the archive (true or false, default is true).
> 

-- 
View this message in context: http://www.nabble.com/Ant-1.7%3A--unzip-with-overwrite-set-to-%27false%27-is-overwriting-files-tp24393106p24396800.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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