Skip to content
Tcl Source Code View Ticket
Login

View Ticket

[file copy] does not accurately copy timestamps (unix)

Closed / Wont Fix2531126fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 18 years ago
Descriptionplain2009-01-23 14:00:14
Tcl's [file copy] command also copies the timestamps of the original file. However, this is not accurately done for sub-second timestamps. Example (on Linux 2.6.9):

% touch foo
% stat foo
  File: `foo'
  Size: 0               Blocks: 8          IO Block: 4096   regular empty file
Device: 307h/775d       Inode: 22429716    Links: 1
Access: (0640/-rw-r-----)  Uid: (  111/    koen)   Gid: (  101/   staff)
Access: 2009-01-23 14:57:04.725254147 +0100
Modify: 2009-01-23 14:57:04.725254147 +0100
Change: 2009-01-23 14:57:04.725254147 +0100
% file copy foo bar
% stat bar
  File: `bar'
  Size: 0               Blocks: 8          IO Block: 4096   regular empty file
Device: 307h/775d       Inode: 22429717    Links: 1
Access: (0640/-rw-r-----)  Uid: (  111/    koen)   Gid: (  101/   staff)
Access: 2009-01-23 14:57:04.000000000 +0100
Modify: 2009-01-23 14:57:04.000000000 +0100
Change: 2009-01-23 14:57:08.635771542 +0100
danckaert Ticket [2531126fff]: 1 change [History diff]2009-01-23 21:00:54
dkfplain2009-01-24 22:37:43
If time_t is an integer (of some size) on the platform (the normal case) sub-second granularity to the atime,mtime,ctime fields is a non-POSIX feature as utime(2) is only guaranteed to the granularity of time_t, and utimes(2) is deprecated. Nanosecond granularity is not guaranteed at all by any API I could find.

If you want any action on this, supply a patch. It should be possible to do by just changing the function CopyFileAtts in tclUnixFCmd.c.
danckaertplain2009-01-26 19:34:24
The new POSIX standard actually marks utime() as obsolete:
http://www.opengroup.org/onlinepubs/9699919799/functions/utime.html
It also specifies a new utimensat() function for dealing with nanosecond timestamps.
Using utimes() would only be an intermediate solution, since it can only handle microseconds, not nanoseconds.

Supporting nanosecond timestamps in Tcl should probably be part of a larger effort, also involving the [file mtime] and [file stat] etc commands. I had a look at the source code, and it seems this would be quite complicated. The problem is that Tcl always keeps pointers to the OS' native stat structure, which would require dependencies on ST_MTIM_NSEC and HAVE_UTIMENSAT spread out over the code.
It would be easier if Tcl had its own stat structure, in which the nanosecond fields could simply be set to zero if they are not supported on the OS.

In any case, it's fine for me if this item is closed.
dkfplain2009-01-26 21:14:58
We most certainly aren't going to require people to use POSIX 2008 for a while.

I'll do nothing about this without a patch written by someone else (including autogoo).
sf-robotplain2009-03-19 01:52:47
allow_comments - 1

This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).
Log in (anonymous is fine) to add a comment.