From 671d15ef2ac4627e10c00afa1bfe43a5da196e5d Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Fri, 31 Oct 2003 13:39:19 +0000 Subject: [PATCH] Make mtree's update function update the modification time too. Submitted by: Dan Nelson PR: 53063 --- usr.sbin/mtree/compare.c | 15 ++++++++++++++- usr.sbin/mtree/mtree.8 | 5 +++-- usr.sbin/mtree/test/test02.sh | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 usr.sbin/mtree/test/test02.sh diff --git a/usr.sbin/mtree/compare.c b/usr.sbin/mtree/compare.c index 8fad8a488953..fbe9775d6ae2 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 c90cf2c8ffaa..e083b2c28431 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 000000000000..a7aa9168382c --- /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 +