mirror of https://github.com/CGAL/cgal
120 lines
2.9 KiB
Perl
Executable File
120 lines
2.9 KiB
Perl
Executable File
#!/sw/bin/perl -w
|
|
|
|
use strict;
|
|
use File::Find;
|
|
|
|
my $filenames_used_file = '/projects/CGAL/admin_scripts/DATA/filenames';
|
|
my %filename_map = ();
|
|
my @conflicts=();
|
|
my ($cgal_package_name, $start_directory);
|
|
|
|
my @reserved_filenames = ('version','description.txt','changes.txt',
|
|
'long_description.txt', 'maintainer', 'submission_info');
|
|
|
|
sub usage()
|
|
{
|
|
print STDERR "$0 checks if the filenames in a package are\n";
|
|
print STDERR "not already used by another package.\n";
|
|
print STDERR "usage:\n";
|
|
print STDERR " $0 package_name directory\n";
|
|
print STDERR " package_name: the name of the package that is checked\n";
|
|
print STDERR " directory: the root directory of the package\n";
|
|
print STDERR "return values:\n";
|
|
print STDERR " 0: everything is OK\n";
|
|
print STDERR " 1: The names are OK, but the file of filenames could not be updated\n";
|
|
print STDERR " 2: There was a name clash.\n";
|
|
print STDERR " 3: Checking could not be done.\n";
|
|
}
|
|
|
|
sub my_die($)
|
|
{
|
|
print STDERR $_[0];
|
|
exit 3;
|
|
}
|
|
|
|
if ( $#ARGV != 1 ) {
|
|
usage();
|
|
exit 3;
|
|
}
|
|
|
|
|
|
|
|
$cgal_package_name = shift;
|
|
$start_directory = shift;
|
|
|
|
open(FILEMAP,$filenames_used_file) or my_die($@);
|
|
while(<FILEMAP>) {
|
|
chop;
|
|
if (/^(.*):([^:]*)$/) {
|
|
next if ($2 eq $cgal_package_name);
|
|
my $lowercasename;
|
|
$lowercasename=lc $1;
|
|
$filename_map{$lowercasename}=$_;
|
|
}
|
|
}
|
|
close FILEMAP or my_die($@);
|
|
|
|
foreach (@reserved_filenames) {
|
|
my $lowercasename = './' . lc($_);
|
|
$filename_map{$lowercasename}='reserved_name';
|
|
}
|
|
|
|
chdir $start_directory or my_die("Can't go to directory $start_directory\n");
|
|
|
|
sub add_files()
|
|
{
|
|
if ( -f $_) {
|
|
my $curfilename = $File::Find::name;
|
|
my $lowercasename;
|
|
$lowercasename = lc $curfilename;
|
|
if (exists($filename_map{$lowercasename}) ) {
|
|
if ($filename_map{$lowercasename} ne 'reserved_name') {
|
|
push @conflicts, $curfilename, $filename_map{$lowercasename};
|
|
}
|
|
} else {
|
|
if ( $curfilename !~ '^./tmpmsg.\d+$' ) {
|
|
$filename_map{$lowercasename} = "$curfilename:$cgal_package_name";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
find(\&add_files, ".");
|
|
|
|
sub write_file($)
|
|
{
|
|
my ($key, $value,$tmpfile);
|
|
$tmpfile = shift;
|
|
open(OFILE,">$tmpfile") or my_die($@);
|
|
while (($key,$value) = each %filename_map) {
|
|
if ($value ne 'reserved_name') {
|
|
print OFILE "$value\n";
|
|
}
|
|
}
|
|
close OFILE or my_die($@);
|
|
}
|
|
|
|
if ($#conflicts != -1) {
|
|
print STDOUT "In package $cgal_package_name ";
|
|
print STDOUT "the following conflicting filenames were detected:\n";
|
|
my $i;
|
|
for ($i=0; $i<$#conflicts; $i +=2) {
|
|
print STDOUT "< $conflicts[$i]\n";
|
|
print STDOUT "> $conflicts[$i+1]\n";
|
|
}
|
|
exit 2;
|
|
}
|
|
my $tmpfile = "tmp_add_pack$$";
|
|
eval "write_file(\"$tmpfile\")";
|
|
if ($@) {
|
|
print STDOUT "$0: Error while writing $tmpfile.\n";
|
|
die;
|
|
# exit 1;
|
|
}
|
|
if (system('mv',"$tmpfile","$filenames_used_file") != 0) {
|
|
print STDOUT "$0: Could not move $tmpfile to $filenames_used_file\n";
|
|
exit 1;
|
|
}
|
|
|
|
exit 0;
|