glocalfileinfo: Don't reset mtime tv_sec when setting tv_usec

Fix a regression that appeared after adding support for nanosecond
timestamps to set_mtime_atime(). User-visible effect: when copying a
file from a gvfs MTP mountpoint to the local filesystem, the file's
mtime is set to 0.

This behavior happens when setting G_FILE_ATTRIBUTE_TIME_MODIFIED first,
then G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC. Setting the second attribute
ends up in set_mtime_atime() with mtime_usec_value set, and mtime_value
== NULL. When mtime_value is NULL, the tv_sec part of the timestamp
should be fetched by lazy_stat(), but set_mtime_atime() fails to assign
it properly, and tv_sec stays at 0, leading to losing the main part of
the timestamp.

Fix the issue by setting times_n[1].tv_sec to the value fetched from
lazy_stat().

Fixes: b33ef610de ("Add functionality to preserve nanosecond timestamps")
Fixes: 15cb123c82 ("glocalfileinfo: don't call both utimes and utimensat")
Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>
This commit is contained in:
Maxim Mikityanskiy 2023-01-02 03:55:40 +02:00
parent 2d5d990c6a
commit a56bc06f16

View File

@ -2883,6 +2883,7 @@ set_mtime_atime (char *filename,
{
if (lazy_stat (filename, &statbuf, &got_stat) == 0)
{
times_n[1].tv_sec = statbuf.st_mtime;
#if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
times_n[1].tv_nsec = statbuf.st_mtimensec;
#elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)