From 4ad612b77b158c27e8fc0763467b5573350b6db1 Mon Sep 17 00:00:00 2001 From: acli Date: Fri, 4 Feb 2005 03:48:53 +0000 Subject: [PATCH] Script failed to create intermediate directories if the directory of the target does not exist and the parent of that directory does not exist either. This should fix that. --- misc/translator/tmpl_process3.pl | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/misc/translator/tmpl_process3.pl b/misc/translator/tmpl_process3.pl index 59ad0c54c6..ec241c6f17 100755 --- a/misc/translator/tmpl_process3.pl +++ b/misc/translator/tmpl_process3.pl @@ -138,6 +138,21 @@ sub listfiles ($$) { ############################################################################### +sub mkdir_recursive ($) { + my($dir) = @_; + local($`, $&, $', $1); + $dir = $` if $dir ne /^\/+$/ && $dir =~ /\/+$/; + my ($prefix, $basename) = ($dir =~ /\/([^\/]+)$/s)? ($`, $1): ('.', $dir); + mkdir_recursive($prefix) if $prefix ne '.' && !-d $prefix; + if (!-d $dir) { + print STDERR "Making directory $dir..."; + # creates with rwxrwxr-x permissions + mkdir($dir, 0775) || warn_normal "$dir: $!", undef; + } +} + +############################################################################### + sub usage ($) { my($exitcode) = @_; my $h = $exitcode? *STDERR: *STDOUT; @@ -353,11 +368,7 @@ if ($action eq 'create') { my $target = $out_dir . substr($input, length($in_dir)); my $targetdir = $` if $target =~ /[^\/]+$/s; - if (!-d $targetdir) { - print STDERR "Making directory $targetdir..."; - # creates with rwxrwxr-x permissions - mkdir($targetdir, 0775) || warn_normal "$targetdir: $!", undef; - } + mkdir_recursive($targetdir) unless -d $targetdir; print STDERR "Creating $target...\n"; open( OUTPUT, ">$target" ) || die "$target: $!\n"; text_replace( $h, *OUTPUT ); -- 2.39.5