Skip to content

Commit

Permalink
[io grant] Fix $*CWD inside IO::Path.dir's :test Callable
Browse files Browse the repository at this point in the history
Fixes two issues:
1) When user passes :CWD arg, the expectation would be that
    :CWD is available as $*CWD inside :test
2) Because we use `gather` by the time we get to run the :test
    Callable, we might already be outside even a user-set $*CWD,
    such us when using `&indir`, so the $*CWD used will be wrong

Fix by giving `gather` its own $*CWD to use. We use a temp var to
avoid issues with .IO coerser using an empty $*CWD for :$!CWD
param and we don't use `temp` because it's 2x slower than a temp var.

Bug find: https://irclog.perlgeek.de/perl6-dev/2017-04-21#i_14462573
  • Loading branch information
zoffixznet committed Apr 21, 2017
1 parent 736be4d commit b2a64a1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/IO/Path.pm
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,14 @@ my class IO::Path is Cool does IO {

my Mu $dirh := nqp::opendir(nqp::unbox_s($.absolute));
gather {
# set $*CWD inside gather for $test.ACCEPTS to use correct
# $*CWD the user gave us, instead of whatever $*CWD is
# when the gather is actually evaluated. We use a temp var
# so that .IO coercer doesn't use the nulled `$*CWD` for
# $!CWD attribute and we don't use `temp` for this, because
# it's about 2x slower than using a temp var.
my $cwd = $CWD.IO;
{ my $*CWD = $cwd;
#?if jvm
for <. ..> -> $elem {
if $test.ACCEPTS($elem) {
Expand Down Expand Up @@ -595,6 +603,7 @@ my class IO::Path is Cool does IO {
)
);
nqp::closedir($dirh);
}
}
}

Expand Down

0 comments on commit b2a64a1

Please sign in to comment.