When using a file's times as reference, use both atime and mtime for the files
to be modified.

Signed-off-by: Xabier Oneca <xon...@gmail.com>
---
 coreutils/touch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/coreutils/touch.c b/coreutils/touch.c
index 641a7366..db5076f1 100644
--- a/coreutils/touch.c
+++ b/coreutils/touch.c
@@ -147,7 +147,8 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
     if (reference_file) {
         struct stat stbuf;
         xstat(reference_file, &stbuf);
-        timebuf[1].tv_sec = timebuf[0].tv_sec = stbuf.st_mtime;
+        timebuf[0].tv_sec = stbuf.st_atime;
+        timebuf[1].tv_sec = stbuf.st_mtime;
         /* Can use .st_mtim.tv_nsec
          * (or is it .st_mtimensec?? see date.c)
          * to set microseconds too.
--
2.30.2
From 55b854887c2233806e91eb7459aec1fa666de348 Mon Sep 17 00:00:00 2001
From: Xabier Oneca <xoneca@gmail.com>
Date: Thu, 8 Apr 2021 02:05:37 +0200
Subject: [PATCH 2/3] touch: fix atime set from reference file

When using a file's times as reference, use both atime and mtime for the files
to be modified.

Signed-off-by: Xabier Oneca <xoneca@gmail.com>
---
 coreutils/touch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/coreutils/touch.c b/coreutils/touch.c
index 641a7366..db5076f1 100644
--- a/coreutils/touch.c
+++ b/coreutils/touch.c
@@ -147,7 +147,8 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
 	if (reference_file) {
 		struct stat stbuf;
 		xstat(reference_file, &stbuf);
-		timebuf[1].tv_sec = timebuf[0].tv_sec = stbuf.st_mtime;
+		timebuf[0].tv_sec = stbuf.st_atime;
+		timebuf[1].tv_sec = stbuf.st_mtime;
 		/* Can use .st_mtim.tv_nsec
 		 * (or is it .st_mtimensec?? see date.c)
 		 * to set microseconds too.
-- 
2.30.2

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to