Tcl Source Code

View Ticket
Login
Ticket UUID: 2531126
Title: [file copy] does not accurately copy timestamps (unix)
Type: Bug Created on: 2009-01-23 14:00:14
Submitter: danckaert Assigned to: vincentdarley
Subsystem: 37. File System Severity:
Priority: 2 Last modified: 2009-03-19 01:52:47
Status: Closed Closed by: sf-robot
Resolution: Wont Fix Closed on: 2009-03-18 18:52:47
Version: obsolete: 8.6b1
Description:
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
User Comments:
dkf added on 2009-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.

danckaert added on 2009-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.

dkf added on 2009-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-robot added on 2009-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).