From a56bc06f1659470e081fb88c511000ee02fb080b Mon Sep 17 00:00:00 2001 From: Maxim Mikityanskiy Date: Mon, 2 Jan 2023 03:55:40 +0200 Subject: [PATCH] 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 --- gio/glocalfileinfo.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c index ae7261bfe..420e9d4b2 100644 --- a/gio/glocalfileinfo.c +++ b/gio/glocalfileinfo.c @@ -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)