summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-07-04 03:49:53 -0500
committerRob Landley <rob@landley.net>2015-07-04 03:49:53 -0500
commit671146c3b41460ec3ad25f64f1269be0f3924b27 (patch)
tree4715c6a272a9441d809a17b09243ac14e8c87cb8
parent0ace882af7b6b26dc1932a6aaa19c245a83765bc (diff)
downloadtoybox-671146c3b41460ec3ad25f64f1269be0f3924b27.tar.gz
toybox-671146c3b41460ec3ad25f64f1269be0f3924b27.tar.bz2
toybox-671146c3b41460ec3ad25f64f1269be0f3924b27.zip
Actually set time with touch -d and -t when you don't specify nanonseconds.
There's a nanoseconds field value that says use current time, which I set but forgot to clear in the right places. (Oops.)
-rwxr-xr-xtests/touch.test20
-rw-r--r--toys/posix/touch.c2
2 files changed, 15 insertions, 7 deletions
diff --git a/tests/touch.test b/tests/touch.test
index 03ab8ce..d6430d0 100755
--- a/tests/touch.test
+++ b/tests/touch.test
@@ -11,14 +11,20 @@ testing "touch -c" "touch -c walrus && [ -e walrus ] && echo yes" "yes\n" "" ""
testing "touch -c missing" "touch -c warrus && [ ! -e warrus ] && echo yes" \
"yes\n" "" ""
-# This isn't testing fraction of a second because I dunno how to read it back
-
testing "touch -d" \
- "touch -d 2009-02-13T23:31:30.12Z walrus && date -r walrus +%s.%N" "1234567890\n" \
- "" ""
-#testing "touch -t" "touch -t 200902132331.42
-#testing "touch -r"
+ "touch -d 2009-02-13T23:31:30Z walrus && date -r walrus +%s" \
+ "1234567890\n" "" ""
+
+testing "touch -d nanoseconds" \
+ "touch -d 2009-02-13T23:31:30.123456789Z walrus && date -r walrus +%s.%N" \
+ "1234567890.123456789\n" "" ""
+
+testing "touch -r" \
+ "touch -r walrus walrus2 && date -r walrus2 +%s.%N" \
+ "1234567890.123456789\n" "" ""
+
#testing "touch -a"
#testing "touch -m"
#testing "touch -am"
-rm walrus
+#testing "touch -t"
+rm walrus walrus2
diff --git a/toys/posix/touch.c b/toys/posix/touch.c
index c5ebbab..052448b 100644
--- a/toys/posix/touch.c
+++ b/toys/posix/touch.c
@@ -62,6 +62,7 @@ void touch_main(void)
localtime_r(&(ts->tv_sec), &tm);
}
s = strptime(date, "%Y-%m-%dT%T", &tm);
+ ts->tv_nsec = 0;
if (s && *s=='.' && isdigit(s[1]))
sscanf(s, ".%lu%n", &ts->tv_nsec, &len);
else len = 0;
@@ -79,6 +80,7 @@ void touch_main(void)
if (s) break;
toybuf[1]='y';
}
+ ts->tv_nsec = 0;
if (s && *s=='.' && sscanf(s, ".%2u%n", &(tm.tm_sec), &len) == 1) {
sscanf(s += len, "%lu%n", &ts->tv_nsec, &len);
len++;