Skip to content

Commit

Permalink
Item13466: Fix bootstrap issues with utf8 paths
Browse files Browse the repository at this point in the history
Also the file path checker can't handle utf8 paths
  • Loading branch information
gac410 committed Jun 21, 2015
1 parent b7ad82a commit 873f04a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
3 changes: 2 additions & 1 deletion core/lib/Foswiki/Configure/FileUtil.pm
Expand Up @@ -15,6 +15,7 @@ use warnings;

use Assert;

use Encode;
use Foswiki::Configure::Reporter ();
use File::Spec;

Expand Down Expand Up @@ -423,7 +424,7 @@ sub checkTreePerms {
or return "Directory $path is not readable.";

foreach my $e ( grep { !/^\./ } readdir($Dfh) ) {
my $p = $path . '/' . $e;
my $p = $path . '/' . Encode::decode_utf8($e);
my $subreport = checkTreePerms( $p, $perms, %options );
while ( my ( $k, $v ) = each %report ) {
if ( ref($v) eq 'ARRAY' ) {
Expand Down
10 changes: 8 additions & 2 deletions core/lib/Foswiki/Configure/Load.pm
Expand Up @@ -18,6 +18,7 @@ use strict;
use warnings;
use Cwd qw( abs_path );
use Assert;
use Encode;
use File::Basename;
use File::Spec;
use POSIX qw(locale_h);
Expand Down Expand Up @@ -412,8 +413,9 @@ sub bootstrapConfig {
$script = $1;
}

print STDERR
"AUTOCONFIG: Found Bin dir: $bin, Script name: $script using FindBin\n"
print STDERR "AUTOCONFIG: Found Bin dir: "
. Encode::decode_utf8($bin)
. ", Script name: $script using FindBin\n"
if (TRAUTO);

$Foswiki::cfg{ScriptSuffix} = ( fileparse( $script, qr/\.[^.]*/ ) )[2];
Expand Down Expand Up @@ -456,6 +458,10 @@ sub bootstrapConfig {
$Foswiki::cfg{$key} = abs_path( $Foswiki::cfg{$key} );
( $Foswiki::cfg{$key} ) = $Foswiki::cfg{$key} =~ m/^(.*)$/; # untaint

# Need to decode utf8 back to perl characters. The file path operations
# all worked with bytes, but Foswiki needs characters.
$Foswiki::cfg{$key} = Encode::decode_utf8( $Foswiki::cfg{$key} );

print STDERR "AUTOCONFIG: $key = $Foswiki::cfg{$key} \n"
if (TRAUTO);

Expand Down
25 changes: 18 additions & 7 deletions core/tools/configure
Expand Up @@ -25,6 +25,7 @@
use warnings;
use strict;

use Encode;
use Getopt::Long;
use Pod::Usage ();
use Data::Dumper ();
Expand Down Expand Up @@ -305,15 +306,25 @@ unless ( $Foswiki::cfg{isVALID} ) {
print
" The following directory settings have been guessed. Press enter to confirm each setting:\n";

_prompt( $root, '{ScriptDir}', $Foswiki::cfg{ScriptDir} );
# Note: Bootstrap will decode the bytes read from the path into utf-8 characters
# But the encoding needs to be reversed when passing it through the command prompt

_prompt( $root, '{ScriptDir}',
Encode::encode_utf8( $Foswiki::cfg{ScriptDir} ) );
_prompt( $root, '{ScriptSuffix}', $Foswiki::cfg{ScriptSuffix},
undef, 1 );
_prompt( $root, '{DataDir}', $Foswiki::cfg{DataDir} );
_prompt( $root, '{PubDir}', $Foswiki::cfg{PubDir} );
_prompt( $root, '{TemplateDir}', $Foswiki::cfg{TemplateDir} );
_prompt( $root, '{LocalesDir}', $Foswiki::cfg{LocalesDir} );
_prompt( $root, '{WorkingDir}', $Foswiki::cfg{WorkingDir} );
_prompt( $root, '{ToolsDir}', $Foswiki::cfg{ToolsDir} );
_prompt( $root, '{DataDir}',
Encode::encode_utf8( $Foswiki::cfg{DataDir} ) );
_prompt( $root, '{PubDir}',
Encode::encode_utf8( $Foswiki::cfg{PubDir} ) );
_prompt( $root, '{TemplateDir}',
Encode::encode_utf8( $Foswiki::cfg{TemplateDir} ) );
_prompt( $root, '{LocalesDir}',
Encode::encode_utf8( $Foswiki::cfg{LocalesDir} ) );
_prompt( $root, '{WorkingDir}',
Encode::encode_utf8( $Foswiki::cfg{WorkingDir} ) );
_prompt( $root, '{ToolsDir}',
Encode::encode_utf8( $Foswiki::cfg{ToolsDir} ) );
_prompt( $root, '{Store}{Implementation}',
$Foswiki::cfg{Store}{Implementation} );
_prompt( $root, '{Store}{Encoding}', $Foswiki::cfg{Store}{Encoding},
Expand Down

0 comments on commit 873f04a

Please sign in to comment.