diff options
author | Maxim Mikityanskiy <maxtram95@gmail.com> | 2023-01-02 03:55:40 +0200 |
---|---|---|
committer | Philip Withnall <pwithnall@endlessos.org> | 2023-01-05 14:41:14 +0000 |
commit | b8cd4298e5b9a8ccb542131474deec41d0d33b0c (patch) | |
tree | eceedd4a040b03c995dee5c1a0d31d81b69779a3 | |
parent | 433464b3f9b12d2e42f85bb7af96574573d85816 (diff) | |
download | glib-b8cd4298e5b9a8ccb542131474deec41d0d33b0c.tar.gz |
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: b33ef610deef ("Add functionality to preserve nanosecond timestamps")
Fixes: 15cb123c824c ("glocalfileinfo: don't call both utimes and utimensat")
Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>
-rw-r--r-- | gio/glocalfileinfo.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c index 661d2266a..2958225c5 100644 --- a/gio/glocalfileinfo.c +++ b/gio/glocalfileinfo.c @@ -2759,6 +2759,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) |