From 49e5dcddf41d9a720d5b35c46a7cc3c31f66e344 Mon Sep 17 00:00:00 2001 From: Mercier Pierre-Olivier Date: Wed, 20 Nov 2013 00:54:01 +0100 Subject: [PATCH] Remove old .ft --- process/files/moulette_get.pl | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/process/files/moulette_get.pl b/process/files/moulette_get.pl index 0024071..c0312df 100644 --- a/process/files/moulette_get.pl +++ b/process/files/moulette_get.pl @@ -7,6 +7,7 @@ use threads; use threads::shared; use Carp; use File::Basename; +use File::Compare; use File::Copy; use File::Path qw(remove_tree mkpath); use File::Temp qw/tempfile tempdir/; @@ -153,11 +154,35 @@ sub create_testsuite jail_exec("gmake -C $tempdir/tests/"); croak "An error occurs while making the testsuite" if ($?); - my $destdir = ( prepare_dir($year, $project_id, $rendu) )[2]; + my ($workdir, $outputdir, $destdir) = prepare_dir($year, $project_id, $rendu); copy("$tempdir/tests/tests.ff", "$destdir/tests.ff") or croak "An error occurs while coping the testsuite: $!"; - copy("$tempdir/tests/test.ft", "$destdir/test.ft") or croak "An error occurs while coping test.ft: $!"; chmod 0660, "$destdir/tests.ff"; - chmod 0660, "$destdir/test.ft"; + + # Check if test.ft has changed + if (-f "$tempdir/tests/test.ft") + { + if (! -f "$destdir/test.ft" || ! compare("$tempdir/tests/test.ft", "$destdir/test.ft")) + { + log DEBUG, "test.ft has changed, update students ones."; + copy("$tempdir/tests/test.ft", "$destdir/test.ft") or croak "An error occurs while coping test.ft: $!"; + chmod 0660, "$destdir/test.ft"; + + opendir(my $dh, $workdir) or die "Can't list files in $workdir: $!"; + while (readdir($dh)) + { + if (/([a-zA-Z0-9_-]+).ft$/) + { + log DEBUG, "Remove $1.ft"; + unlink "$workdir/$1.ft"; + } + } + closedir $dh; + } + } + else { + remove_tree($tempdir); + croak "tests/test.ft not found."; + } # Clean remove_tree($tempdir); @@ -210,7 +235,7 @@ sub run_moulette close $fhout; } - copy("$filesdir/$login.ff", "$workdir/$login.ff") or croak "Cannont copy $login.ff"; + copy("$filesdir/$login.ff", "$workdir/$login.ff") or croak "Cannot copy $login.ff"; next if ($login eq "ref" && ! -f "$workdir/$login.ft"); croak "Unable to find a relevant $login.ft, abort moulette start." if (! -f "$workdir/$login.ft");