ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdblaha1 <rd_bl...@hotmail.com>
Subject Re: Ant 1.7: unzip with overwrite set to 'false' is overwriting files
Date Thu, 09 Jul 2009 16:27:57 GMT

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


Mime
View raw message