winemaker: Fix invalid usage of {open,close}dir() in fix_file_and_directory_names(). .
Reuse our caching mechanism (get_directory_contents()), but clear the cache if we have modified a directory's content.
This commit is contained in:
parent
33d4c7c514
commit
d4fddfb4bc
|
@ -447,6 +447,14 @@ sub get_directory_contents($)
|
||||||
return $directory;
|
return $directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##
|
||||||
|
# Removes a directory from the cache.
|
||||||
|
# This is needed if one of its files or subdirectory has been renamed.
|
||||||
|
sub clear_directory_cache($)
|
||||||
|
{
|
||||||
|
my ($dirname)=@_;
|
||||||
|
delete $directories{$dirname};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#####
|
#####
|
||||||
|
@ -604,7 +612,6 @@ sub source_scan_directory($$$$)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(DIRECTORY);
|
|
||||||
|
|
||||||
if ($has_headers) {
|
if ($has_headers) {
|
||||||
push @{@$project_settings[$T_INCLUDE_PATH]},"-I.";
|
push @{@$project_settings[$T_INCLUDE_PATH]},"-I.";
|
||||||
|
@ -997,10 +1004,11 @@ sub fix_file_and_directory_names($)
|
||||||
{
|
{
|
||||||
my $dirname=$_[0];
|
my $dirname=$_[0];
|
||||||
|
|
||||||
if (opendir(DIRECTORY, "$dirname")) {
|
my $directory=get_directory_contents($dirname);
|
||||||
foreach my $dentry (readdir DIRECTORY) {
|
foreach my $dentry (@$directory)
|
||||||
|
{
|
||||||
if ($dentry =~ /^\./ or $dentry eq "CVS") {
|
if ($dentry =~ /^\./ or $dentry eq "CVS") {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
# Set $warn to 1 if the user should be warned of the renaming
|
# Set $warn to 1 if the user should be warned of the renaming
|
||||||
my $warn;
|
my $warn;
|
||||||
|
@ -1008,49 +1016,52 @@ sub fix_file_and_directory_names($)
|
||||||
|
|
||||||
if (-f "$dirname/$dentry")
|
if (-f "$dirname/$dentry")
|
||||||
{
|
{
|
||||||
# Don't rename Winemaker's makefiles
|
# Don't rename Winemaker's makefiles
|
||||||
next if ($dentry eq "Makefile" and
|
next if ($dentry eq "Makefile" and
|
||||||
`head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker/);
|
`head -n 1 "$dirname/$dentry"` =~ /Generated by Winemaker/);
|
||||||
|
|
||||||
# Leave non-source files alone
|
# Leave non-source files alone
|
||||||
next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
|
next if ($new_name !~ /(^makefile|\.(c|cpp|h|rc))$/i);
|
||||||
|
|
||||||
# Only all lowercase extensions are supported (because of
|
# Only all lowercase extensions are supported (because of
|
||||||
# rules like '.c.o:'.
|
# rules like '.c.o:'.
|
||||||
$new_name =~ s/\.C$/.c/;
|
$new_name =~ s/\.C$/.c/;
|
||||||
$new_name =~ s/\.cpp$/.cpp/i;
|
$new_name =~ s/\.cpp$/.cpp/i;
|
||||||
$warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
|
$warn=1 if ($new_name =~ s/\.cxx$/.cpp/i);
|
||||||
$new_name =~ s/\.rc$/.rc/i;
|
$new_name =~ s/\.rc$/.rc/i;
|
||||||
# And this last one is to avoid confusion then running make
|
# And this last one is to avoid confusion then running make
|
||||||
$warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
|
$warn=1 if ($new_name =~ s/^makefile$/makefile.win/i);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Adjust the case to the user's preferences
|
# Adjust the case to the user's preferences
|
||||||
if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
|
if (($opt_lower == $OPT_LOWER_ALL and $dentry =~ /[A-Z]/) or
|
||||||
($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
|
($opt_lower == $OPT_LOWER_UPPERCASE and $dentry !~ /[a-z]/)
|
||||||
) {
|
) {
|
||||||
$new_name=lc $new_name;
|
$new_name=lc $new_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
# autoconf and make don't support these characters well
|
# autoconf and make don't support these characters well
|
||||||
$new_name =~ s/[ \$]/_/g;
|
$new_name =~ s/[ \$]/_/g;
|
||||||
|
|
||||||
# And finally, perform the renaming
|
# And finally, perform the renaming
|
||||||
if ($new_name ne $dentry) {
|
if ($new_name ne $dentry)
|
||||||
if ($warn) {
|
{
|
||||||
print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
|
if ($warn) {
|
||||||
}
|
print STDERR "warning: in \"$dirname\", renaming \"$dentry\" to \"$new_name\"\n";
|
||||||
if (!rename("$dirname/$dentry","$dirname/$new_name")) {
|
}
|
||||||
print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
|
if (!rename("$dirname/$dentry","$dirname/$new_name")) {
|
||||||
print STDERR " $!\n";
|
print STDERR "error: in \"$dirname\", unable to rename \"$dentry\" to \"$new_name\"\n";
|
||||||
$new_name=$dentry;
|
print STDERR " $!\n";
|
||||||
}
|
$new_name=$dentry;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
clear_directory_cache($dirname);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (-d "$dirname/$new_name") {
|
if (-d "$dirname/$new_name") {
|
||||||
fix_file_and_directory_names("$dirname/$new_name");
|
fix_file_and_directory_names("$dirname/$new_name");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
closedir(DIRECTORY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue