summaryrefslogtreecommitdiff
path: root/src/touch.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2008-01-06 09:54:15 +0100
committerJim Meyering <meyering@redhat.com>2008-01-06 09:54:15 +0100
commitfd12e98f36bdea018227909378f1adac8e1e1e6f (patch)
treeaab897ffec44663669eeee28fe667d50718adac0 /src/touch.c
parent6efd10462d8103208f4575f0b5edddf841c7d87c (diff)
downloadcoreutils-fd12e98f36bdea018227909378f1adac8e1e1e6f.tar.xz
touch: ignore "-d now" option, when appropriate
* src/touch.c (main): Treat "-d now" as if it were absent, if neither -a nor -m is specified. Problem reported by Dan Jacobson in: http://lists.gnu.org/archive/html/bug-coreutils/2008-01/msg00010.html
Diffstat (limited to 'src/touch.c')
-rw-r--r--src/touch.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/touch.c b/src/touch.c
index 2540558e5..205fbf6d0 100644
--- a/src/touch.c
+++ b/src/touch.c
@@ -368,9 +368,29 @@ main (int argc, char **argv)
{
if (flex_date)
{
- get_reldate (&newtime[0], flex_date, NULL);
+ struct timespec now;
+ gettime (&now);
+ get_reldate (&newtime[0], flex_date, &now);
newtime[1] = newtime[0];
date_set = true;
+
+ /* If neither -a nor -m is specified, treat "-d now" as if
+ it were absent; this lets "touch" succeed more often in
+ the presence of restrictive permissions. */
+ if (change_times == (CH_ATIME | CH_MTIME)
+ && newtime[0].tv_sec == now.tv_sec
+ && newtime[0].tv_nsec == now.tv_nsec)
+ {
+ /* Check that it really was "-d now", and not a time
+ stamp that just happens to be the current time. */
+ struct timespec notnow, notnow1;
+ notnow.tv_sec = now.tv_sec ^ 1;
+ notnow.tv_nsec = now.tv_nsec;
+ get_reldate (&notnow1, flex_date, &notnow);
+ if (notnow1.tv_sec == notnow.tv_sec
+ && notnow1.tv_nsec == notnow.tv_nsec)
+ date_set = false;
+ }
}
}