ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruce Atherton <>
Subject [Submit] Rounding error with dependency checking in
Date Tue, 27 Nov 2001 02:14:10 GMT
Here is an odd one. I was tryng to create a way to generate a ZIP file of 
any changes that had happened since a previous ZIP. I eventually came up 
with this:

   <target name="create-diff-zip" depends="init" >
     <delete quiet="true" includeEmptyDirs="true" >
       <fileset dir="${tempdir}" defaultexcludes="no" />
     <mkdir dir="${tempdir}" />
     <unzip src="${zipname}" dest="${tempdir}" />
     <apply executable="/usr/bin/zip" skipemptyfilesets="true" parallel="true"
               dest="${tempdir}" dir="${buildpath}" relative="true" >
       <arg value="${diffzipname}-${DSTAMP}-${TSTAMP}.zip" />
       <fileset dir="${buildpath}" >
         <include name="classes/**" />
         <include name="ejb/**" />
         <include name="static/**" />
         <include name="webapp/**" />
       <mapper type="identity" />
     <delete quiet="true" includeEmptyDirs="true" >
       <fileset dir="${tempdir}" defaultexcludes="no" />

That should do the trick so long as I avoid using JDK1.1, right? Wrong. 
Turns out that approximately half the 6000 files I am working with are 
considered "outdated" and are included in the ZIP file, even after I've 
just generated a new base ZIP. In other words, there should have been no 
difference whatsoever and the diff zip should not even be created, but is 
instead half the size of the original.

I modified SourceFileScanner to output the longs returned by 
"src.lastModified()" and "dest.lastModified()", and it turns out that all 
numbers were in even thousands, but half matched exactly and half had a 
difference of exactly 1000. I'm pretty sure it must be a rounding error 
somewhere along the line, but I have no idea where. Still, I would think it 
likely this is going to bite others and should be fixed.

So my suggested trivial fix would be as follows. I realize that there may 
be people out there who think that a 1 second error is too much for 
dependency checking but I can't think of a better solution.

   * Fix errors that can occur when rounding timestamps to the nearest 
second in org/apache/tools/ant/util/

RCS file: 
retrieving revision 1.10
diff -u -r1.10
---      2001/11/02 07:56:53     1.10
+++      2001/11/27 01:26:19
@@ -138,7 +138,7 @@
                      added = true;
-                } else if (src.lastModified() > dest.lastModified()) {
+                } else if ((src.lastModified() - 1000L) > 
dest.lastModified()) {
                      task.log(files[i]+" added as 
"+dest.getAbsolutePath()+" is outdated.",

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message