Bug 48008 - touch task truncates timestamps
Summary: touch task truncates timestamps
Status: REOPENED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.7.1
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-15 16:34 UTC by Alexander Pogrebnyak
Modified: 2009-11-17 10:54 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Pogrebnyak 2009-10-15 16:34:16 UTC
When I use a touch task with a mapper
<touch
  mkdirs="true"
  verbose="${TALK}"
>
  <fileset dir="${orig-dir}"/>
  <globmapper from="*" to="${shadow-dir}/*"/>
</touch>

Produces empty files that are OLDER than sources.
After running this task and using ls --time-style=full-iso, I get the following timestamp for source:
   2009-09-30 07:44:26.290894100 -0400

And this timestamp for target
   2009-09-30 07:44:26.290000000 -0400

Notice that target now is older than source.

This breaks <ant-contrib:outofdate> task later on.
Comment 1 Stefan Bodewig 2009-10-20 23:22:48 UTC
Ant uses the lastModified and setLastModified methods in java.io.File http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html which doesn't allow a granularity smaller than millisecond.

I don't understand why outofdate seems to be rounding up here but as far as I can see there isn't anything touch could do differently as it set the last modified time to the one read from the source file.

CANTFIX rather than WONTFIX.
Comment 2 Alexander Pogrebnyak 2009-10-21 04:57:09 UTC
(In reply to comment #1)
> Ant uses the lastModified and setLastModified methods in java.io.File
> http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html which doesn't allow a
> granularity smaller than millisecond.
> 
> I don't understand why outofdate seems to be rounding up here but as far as I
> can see there isn't anything touch could do differently as it set the last
> modified time to the one read from the source file.
> 
> CANTFIX rather than WONTFIX.

How about setting it to
newFile.setLastModified( origFile.lastModified() + 1 )

This will definitely round it in the right direction.  Plus it would probably integrate better with the tools external to ant (e.g. make), that could have used the newly created file.
Comment 3 Alexander Pogrebnyak 2009-11-17 10:54:22 UTC
Is it possible to add "roundup" attribute to Touch task, similar in concept to one in Zip task.

Then if the attribute is set, you can do 

newFile.setLastModified( origFile.lastModified() + 1 ) as proposed in Comment 2