From 18b51aa47de571c528f8832d8d94d83cd5e25e53 Mon Sep 17 00:00:00 2001 From: Robert Ricci Date: Mon, 13 Jan 2014 22:32:34 -0700 Subject: [PATCH] Set mtime on files for 'make class' Set it to the last time the directory had a commit --- makeclass | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/makeclass b/makeclass index 28d1223..79374fe 100755 --- a/makeclass +++ b/makeclass @@ -8,6 +8,7 @@ use strict; sub transmogrify($); sub cleanup(@); +sub setmtime($$); my $CLASSDIR = "class"; @@ -19,15 +20,20 @@ my @others = ("syllabus", "schedule"); @lecturenotes = cleanup(@lecturenotes); foreach my $file (@handouts, @lecturenotes) { - my $command = "cp $file $CLASSDIR/" . transmogrify($file); + my $destfile = $CLASSDIR . "/" . transmogrify($file); + my $command = "cp $file $destfile"; print "$command\n"; system "$command"; + setmtime($destfile,$file); } foreach my $file (@others) { - my $command = "cp $file/$file.pdf $CLASSDIR/$file.pdf"; + my $sourcefile = $file . "/" . $file . ".pdf"; + my $destfile = $CLASSDIR . "/" . $file . ".pdf"; + my $command = "cp $sourcefile $destfile"; print "$command\n"; system "$command"; + setmtime($destfile,$sourcefile); } sub transmogrify($) { @@ -49,3 +55,15 @@ sub cleanup(@) { @list = grep(!/template/,@list); return @list; } + +sub setmtime($$) { + my ($file, $sourcefile) = @_; + # Find out last modified time for the directory the source file was in + my $directory = `dirname $sourcefile`; + chomp $directory; + + my $mtime = `git log -1 --format=%ct -- $directory`; + chomp $mtime; + + utime(time(),$mtime,$file); +} -- GitLab