[git commit] touch: fix -am

Denys Vlasenko vda.linux at googlemail.com
Tue Apr 13 23:01:20 UTC 2021


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

function                                             old     new   delta
touch_main                                           414     424     +10

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 coreutils/touch.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/coreutils/touch.c b/coreutils/touch.c
index 6c0201374..4c7362acd 100644
--- a/coreutils/touch.c
+++ b/coreutils/touch.c
@@ -153,11 +153,14 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
 		timebuf[1].tv_sec = timebuf[0].tv_sec = t;
 		timebuf[1].tv_nsec = timebuf[0].tv_nsec = 0;
 	}
-	if (opts & OPT_a) {
-		timebuf[1].tv_nsec = UTIME_OMIT;
-	}
-	if (opts & OPT_m) {
-		timebuf[0].tv_nsec = UTIME_OMIT;
+	/* If both -a and -m specified, both times should be set.
+	 * IOW: set OMIT only if one, not both, of them is given!
+	 */
+	if ((opts & (OPT_a|OPT_m)) != (OPT_a|OPT_m)) {
+		if (opts & OPT_a)
+			timebuf[1].tv_nsec = UTIME_OMIT;
+		if (opts & OPT_m)
+			timebuf[0].tv_nsec = UTIME_OMIT;
 	}
 
 	argv += optind;


More information about the busybox-cvs mailing list