The attached patch adds an option to ttree to preserve file modification times. If I am regenerating static content then I generally want the timestamps to reflect the time that the content changed (some of the files on my site have a last modification time of November 1994 -- i.e. the archive of "Spinning the Web", which was when the book was sent to press and when the files were converted to HTML).
Note that I have made preservation of mtime separate from preservation of uid/gid/mode as this is a separate issue. Andrew -- Andrew Ford, Director Ford & Mason Ltd / Pauntley Press [EMAIL PROTECTED] South Wing, Compton House http://ford-mason.co.uk Compton Green, Redmarley Tel: +44 1531 829900 http://pauntley-press.co.uk Gloucester, GL19 3JB Fax: +44 1531 829901 http://refcards.com Great Britain Mobile: +44 7785 258278 [andrew@ariadne build]$ diff -u Template-Toolkit-2.06/bin/ttree.orig Template-Toolkit-2.06/bin/ttree --- Template-Toolkit-2.06/bin/ttree.orig Wed Nov 7 14:47:53 2001 +++ Template-Toolkit-2.06/bin/ttree Sun Jan 27 20:17:45 2002 @@ -62,6 +62,7 @@ my $verbose = $config->verbose || $dryrun; my $recurse = $config->recurse; my $preserve = $config->preserve; +my $preserve_mtime = $config->preserve_mtime; my $debug = $config->debug; my $all = $config->all; my $libdir = $config->lib; @@ -245,7 +246,7 @@ # print "proc $file => $dest\n"; # stat the source file unconditionally, so we can preserve - # mode and ownership + # mtime, mode and ownership (undef, undef, $mode, undef, $uid, $gid, undef, undef, undef, $srctime, undef, undef, undef) = stat($absfile); @@ -253,7 +254,7 @@ if (-f $dest && ! $all) { $desttime = ( stat($dest) )[9]; - if ($desttime > $srctime) { + if ($desttime >= $srctime) { printf " - %-32s (not modified)\n", $file if $verbose; return; @@ -269,9 +270,13 @@ unless ($dryrun) { copy($absfile, $dest); + if ($preserve_mtime) { + utime(time, $srctime, $dest) || warn "utime($dest): $!\n" + } if ($preserve) { chown($uid, $gid, $dest) || warn "chown($dest): $!\n"; chmod($mode, $dest) || warn "chmod($dest): $!\n"; + utime(time, $srctime, $dest) if $preserve_mtime; } } return; @@ -294,6 +299,9 @@ $template->process($file, $replace, $file) || print(" ! ", $template->error(), "\n"); + if ($preserve_mtime) { + utime(time, $srctime, $dest) || warn "utime($dest): $!\n" + } if ($preserve) { chown($uid, $gid, $dest) || warn "chown($dest): $!\n"; chmod($mode, $dest) || warn "chmod($dest): $!\n"; @@ -322,6 +330,7 @@ 'recurse|r' => { DEFAULT => 0 }, 'nothing|n' => { DEFAULT => 0 }, 'preserve|p' => { DEFAULT => 0 }, + 'preserve_mtime|t' => { DEFAULT => 0 }, 'all|a' => { DEFAULT => 0 }, 'debug|dbg' => { DEFAULT => 0 }, 'define=s%', @@ -480,6 +489,7 @@ -a (--all) Process all files, regardless of modification -r (--recurse) Recurse into sub-directories -p (--preserve) Preserve file ownership and permission + -m (--preserve_mtime) Preserve file modification time -n (--nothing) Do nothing, just print summary (enables -v) -v (--verbose) Verbose mode -h (--help) This help
