#!/usr/bin/perl5

$patchsetDir = "/patches/ftp/support/patchset/.allrecpatch";
$testDir = "/patches/ftp/pub/test/.allrecpatch";

opendir(PATCHSETDIR, "$patchsetDir");

@tardistList_patchset = sort grep /tardist/, readdir PATCHSETDIR;

opendir (TESTDIR, "$testDir");
@tardistList_test = sort grep /tardist/, readdir TESTDIR;

foreach $file (@tardistList_patchset) {
	#print "file is $file\n";
        if (&isInTestDir($file, @tardistList_test)) {
		$full_file = $patchsetDir . "/" . $file;
		$substitute_file = $testDir . "/" . $file;
		system("rm -fr $full_file");
		print "rm -fr $full_file\n";
		system("ln -s $substitute_file $full_file");
		print  "ln -s $substitute_file $full_file\n";
		print "$file is removed and a new link is created\n";
	}
}

sub isInTestDir {

        my ($tardistFile , @list ) = @_;

        foreach (@list) {
		#print "\t test file is $_|\n";
                if ($tardistFile eq $_) {
                        return 1;
                }
        }
        return 0;
}

