[git commit] touch: fix atime set from reference file

Denys Vlasenko vda.linux at googlemail.com
Mon Apr 12 18:05:48 UTC 2021


commit: https://git.busybox.net/busybox/commit/?id=de1a49cb419d931a62500eaddb7c888ee011eefe
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

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 at gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 coreutils/touch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/coreutils/touch.c b/coreutils/touch.c
index dff68cb00..68fb625fe 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.


More information about the busybox-cvs mailing list