summaryrefslogtreecommitdiffstats
path: root/usr.sbin/mtree
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2003-10-31 13:39:19 +0000
committerphk <phk@FreeBSD.org>2003-10-31 13:39:19 +0000
commit4ad1bf034220b7e1df9292a18160247ca8f5b2be (patch)
tree4913a6045b220629ada65dbb52134d9039d6bc9a /usr.sbin/mtree
parenta325916ce64cb9bb29e5651fb77e344176fbe28c (diff)
downloadFreeBSD-src-4ad1bf034220b7e1df9292a18160247ca8f5b2be.zip
FreeBSD-src-4ad1bf034220b7e1df9292a18160247ca8f5b2be.tar.gz
Make mtree's update function update the modification time too.
Submitted by: Dan Nelson <dnelson@allantgroup.com> PR: 53063
Diffstat (limited to 'usr.sbin/mtree')
-rw-r--r--usr.sbin/mtree/compare.c15
-rw-r--r--usr.sbin/mtree/mtree.85
-rw-r--r--usr.sbin/mtree/test/test02.sh36
3 files changed, 53 insertions, 3 deletions
diff --git a/usr.sbin/mtree/compare.c b/usr.sbin/mtree/compare.c
index 8fad8a4..fbe9775 100644
--- a/usr.sbin/mtree/compare.c
+++ b/usr.sbin/mtree/compare.c
@@ -184,8 +184,21 @@ typeerr: LABEL;
LABEL;
(void)printf("%smodification time expected %.24s ",
tab, ctime(&s->st_mtimespec.tv_sec));
- (void)printf("found %.24s\n",
+ (void)printf("found %.24s",
ctime(&p->fts_statp->st_mtimespec.tv_sec));
+ if (uflag) {
+ struct timeval tv[2];
+ tv[0].tv_sec = s->st_mtimespec.tv_sec;
+ tv[0].tv_usec = s->st_mtimespec.tv_nsec / 1000;
+ tv[1] = tv[0];
+ if (utimes(p->fts_accpath, tv))
+ (void)printf(" not modified: %s\n",
+ strerror(errno));
+ else
+ (void)printf(" modified\n");
+ } else
+ (void)printf("\n");
+
tab = "\t";
}
if (s->flags & F_CKSUM) {
diff --git a/usr.sbin/mtree/mtree.8 b/usr.sbin/mtree/mtree.8
index c90cf2c..e083b2c 100644
--- a/usr.sbin/mtree/mtree.8
+++ b/usr.sbin/mtree/mtree.8
@@ -76,8 +76,9 @@ Follow all symbolic links in the file hierarchy.
Don't follow symbolic links in the file hierarchy, instead consider
the symbolic link itself in any comparisons. This is the default.
.It Fl U
-Modify the owner, group and permissions of existing files to match
-the specification and create any missing directories or symbolic links.
+Modify the owner, group, permissions, and modification time of existing
+files to match the specification and create any missing directories or
+symbolic links.
User, group and permissions must all be specified for missing directories
to be created.
Corrected mismatches are not considered errors.
diff --git a/usr.sbin/mtree/test/test02.sh b/usr.sbin/mtree/test/test02.sh
new file mode 100644
index 0000000..a7aa916
--- /dev/null
+++ b/usr.sbin/mtree/test/test02.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# Copyright (c) 2003 Dan Nelson
+# All rights reserved.
+#
+# Please see src/share/examples/etc/bsd-style-copyright.
+#
+# $FreeBSD$
+#
+
+set -e
+
+TMP=/tmp/mtree.$$
+
+rm -rf ${TMP}
+mkdir -p ${TMP} ${TMP}/mr ${TMP}/mt
+
+touch -t 199901020304 ${TMP}/mr/oldfile
+touch ${TMP}/mt/oldfile
+
+mtree -c -p ${TMP}/mr > ${TMP}/_
+
+mtree -U -r -p ${TMP}/mt < ${TMP}/_ > /dev/null
+
+x=x`(cd ${TMP}/mr ; ls -l 2>&1) || true`
+y=x`(cd ${TMP}/mt ; ls -l 2>&1) || true`
+
+if [ "$x" != "$y" ] ; then
+ echo "ERROR Update of mtime failed" 1>&2
+ rm -rf ${TMP}
+ exit 1
+fi
+
+rm -rf ${TMP}
+exit 0
+
OpenPOWER on IntegriCloud