momo33 has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

I can set a timestamp using utime(time, time, $file). This works fine on Windows XP but not on Windows 7: on Windows 7 the timestamp is not updated, no error-messages (I use Win32::UTCFileTime too). Is something special needed for Windows 7 or is this not supported?

Thanks!

Replies are listed 'Best First'.
Re: file timestamp and Windows 7
by mjscott2702 (Pilgrim) on Jan 05, 2011 at 08:59 UTC
    On a Windows 7 machine with NTFS, modification time was successfully updated using:

    Cygwin

    $ ls -goc dummy.txt; perl -e 'utime undef, undef, "dummy.txt"'; ls -go +c dummy.txt -rw-r--r--+ 1 0 2011-01-05 08:44 dummy.txt -rw-r--r--+ 1 0 2011-01-05 08:49 dummy.txt

    and ActiveState perl:

    >dir dummy.txt 05/01/2011 08:49 0 dummy.txt >perl -e "utime undef, undef, 'dummy.txt'" >dir dummy.txt 05/01/2011 08:53 0 dummy.txt

    I think the file system format (NTFS here) may be significant - also make sure you have write permission on the files you are updating.

Re: file timestamp and Windows 7
by Anonymous Monk on Jan 05, 2011 at 07:34 UTC
    This works fine on Windows XP but not on Windows 7 (I use Win32::UTCFileTime too).

    How does it fail, whats the error message?

    Is something special needed for Windows 7 or is this not supported?

    perlport says
    utime
    Only the modification time is updated. (BeOS, VMS, RISC OS)

    May not behave as expected. Behavior depends on the C runtime library's implementation of utime(), and the filesystem being used. The FAT filesystem typically does not support an "access time" field, and it may limit timestamps to a granularity of two seconds. (Win32)

    An examination of the source reveals, just like perlport says, behaviour depends on the c runtimes utime, so I expect it to work much like microsoft says it should :)
      Sorry, my mistake: On Windows 7 the file timestamp is not updated as it is updated on Windows XP.
        Sorry, my mistake: On Windows 7 the file timestamp is not updated as it is updated on Windows XP.

        When it fails to update the timestamp, it should set errno, so what is errno set to?

        utime(time, time, $file) or die sprintf "ERRRR(%d)(%s)(%d)(%s)", $!,$!,$^E,$^E;
Re: file timestamp and Windows 7
by locked_user sundialsvc4 (Abbot) on Jan 05, 2011 at 13:40 UTC

    I know that, say, on Unix/Linux, some filesystems do not routinely support the updating of file timestamps.   The calls appear to work but do not actually do anything.   The stated reason is efficiency:   updating file labels involves a lot of disk I/O and creates “hot spots” in those areas, forcing networked systems to do a lot of cache-invalidation for essentially no good purpose.   Usually, this behavior is configurable through some kind of knob.   My educated guess is that such a thing might be happening here.

      I know that is true for last access time, but last mod time? How would you do backups by date? That's a pretty standard sysadmin activity. Scary if it is true. Do you know of specific examples where *last mod time* is not tracked by the file system?