Commit 75017750 authored by Sven Sandberg's avatar Sven Sandberg

BUG#41959: mtr: error message when mkpath() fails and the file exists but is not directory

Problem: when mtr tries to create a directory, and the target
exists but is a file instead of directory, it tries several times
to create the directory again before it fails.
Fix: make it check if the target exists and is a non-directory.


mysql-test/lib/My/File/Path.pm:
  mkpath() now stops with appropriate error message if the target
  exists but is a non-directory.
parent f0f68e71
...@@ -61,6 +61,9 @@ sub rmtree { ...@@ -61,6 +61,9 @@ sub rmtree {
sub mkpath { sub mkpath {
my $path; my $path;
die "Usage: mkpath(<path>)" unless @_ == 1;
foreach my $dir ( File::Spec->splitdir( @_ ) ) { foreach my $dir ( File::Spec->splitdir( @_ ) ) {
#print "dir: $dir\n"; #print "dir: $dir\n";
if ($dir =~ /^[a-z]:/i){ if ($dir =~ /^[a-z]:/i){
...@@ -72,8 +75,9 @@ sub mkpath { ...@@ -72,8 +75,9 @@ sub mkpath {
$path= File::Spec->catdir($path, $dir); $path= File::Spec->catdir($path, $dir);
#print "path: $path\n"; #print "path: $path\n";
next if -d $path; # Path already exist next if -d $path; # Path already exists and is a directory
next if mkdir($path); # mkdir worked croak("File already exists but is not a directory: '$path'") if -e $path;
next if mkdir($path);
# mkdir failed, try one more time # mkdir failed, try one more time
next if mkdir($path); next if mkdir($path);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment