From 6c66c1b88cb4af478a31b7e64da11fbced88ae4b Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Wed, 19 Apr 2017 18:10:53 +0000 Subject: [PATCH] Fix REPL failures with Linenoise 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. --- src/core/REPL.pm | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/src/core/REPL.pm b/src/core/REPL.pm index 15de2a29001..1b1f3b3e244 100644 --- a/src/core/REPL.pm +++ b/src/core/REPL.pm @@ -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>; @@ -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 { - IO::Path.new($*ENV) - } else { - IO::Path.new($*HOME).add('.perl6').add('rakudo-history') - } - try { - mkpath($!history-file); + $!history-file = $*ENV + ?? $*ENV.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 } } }