Skip to content

Commit

Permalink
Fix REPL failures with Linenoise
Browse files Browse the repository at this point in the history
Bug find: https://irclog.perlgeek.de/perl6/2017-04-19#i_14452772

The code for creating paths starts off by trying to `mkdir` `/` dir
and so on for each path. On OSX, this fails, despite working fine on
Linux. Also, `mkdir` used to return the list of files, but not it
returns the Failure object, 'causing the explosion.

Fix by removing all the mkpath business, because mkdir is `mkdir -p`
really. And then watch out for Failures from mkdir.
  • Loading branch information
zoffixznet committed Apr 23, 2017
1 parent 2f143f4 commit 6c66c1b
Showing 1 changed file with 9 additions and 28 deletions.
37 changes: 9 additions & 28 deletions src/core/REPL.pm
Expand Up @@ -39,18 +39,6 @@ do {
splice(@values, $insert_pos, 0, $value);
}

my sub mkpath(IO::Path $full-path --> Nil) {
my ( :$directory, *% ) := $full-path.parts;
my @parts = $*SPEC.splitdir($directory);

for [\~] @parts.map(* ~ '/') -> $path {
mkdir $path;
unless $path.IO ~~ :d {
fail "Unable to mkpath '$full-path': $path is not a directory";
}
}
}

my role ReadlineBehavior[$WHO] {
my &readline = $WHO<&readline>;
my &add_history = $WHO<&add_history>;
Expand Down Expand Up @@ -409,25 +397,18 @@ do {
}

method history-file(--> Str:D) {
return ~$!history-file if $!history-file.defined;
return $!history-file.absolute if $!history-file.defined;

$!history-file = do
if $*ENV<RAKUDO_HIST> {
IO::Path.new($*ENV<RAKUDO_HIST>)
} else {
IO::Path.new($*HOME).add('.perl6').add('rakudo-history')
}
try {
mkpath($!history-file);
$!history-file = $*ENV<RAKUDO_HIST>
?? $*ENV<RAKUDO_HIST>.IO
!! $*HOME.add('.perl6/rakudo-history');

CATCH {
when X::AdHoc & ({ .Str ~~ m:s/Unable to mkpath/ }) {
note "I ran into a problem trying to set up history: $_";
note 'Sorry, but history will not be saved at the end of your session';
}
}
without mkdir $!history-file.parent {
note "I ran into a problem trying to set up history: {.exception.message}";
note 'Sorry, but history will not be saved at the end of your session';
}
~$!history-file

$!history-file.absolute
}
}
}

0 comments on commit 6c66c1b

Please sign in to comment.