Boost logo

Boost Users :

Subject: Re: [Boost-users] Preserving mtime with filesystem lib
From: Brad Schick (schickb_at_[hidden])
Date: 2009-01-24 03:56:21


On 01/23/2009 10:07 PM, Brad Schick wrote:
> Is there a portable way to use the boost filesystem library to copy
> files and preserve mtimes? I am writing a tool that moves media files
> around and mtime can be significant when other sources of metadata are
> absent (like exif, iptc, xmp).
>
>

I'll answer my own question. Looking through the code I found that there
are both read and write versions of 'last_write_time'. So I can read the
source time and write it to the copy. That's in the docs also, but I
didn't notice the write version.

I still think it would be helpful if 'copy_file' took a bool to control
write time preservation, since currently the default behavior is a bit
unpredictable. On windows copy_file preserves mtime time, while under
posix it does not. Looking at the code, it is obvious why since the
posix copy_file just opens and writes the 'to' file directly. Optionally
adding a utime call after the write would be handy (and the stat info
from the source is already loaded).

-Brad


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net