Skip to content

Commit

Permalink
Fix IO::Path.resolve to work with native refs
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoffrey Broadwell committed Mar 2, 2015
1 parent a164f30 commit ddddd07
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/core/IO/Path.pm
Expand Up @@ -148,19 +148,20 @@ my class IO::Path is Cool {
my str $up = $!SPEC.updir;
my str $empty = '';
my str $resolved = $empty;
my Mu $res-list := nqp::list();
my Mu $res-list := nqp::list_s();

my Mu $parts := nqp::split($sep, nqp::unbox_s(self.absolute));
while $parts {
fail "Resolved path too deep!" if $max-depth < $res-list + $parts;
fail "Resolved path too deep!"
if $max-depth < nqp::elems($res-list) + nqp::elems($parts);

# Grab next unprocessed part, check for '', '.', '..'
my str $part = nqp::shift($parts);

next if nqp::iseq_s($part, $empty) || nqp::iseq_s($part, $cur);
if nqp::iseq_s($part, $up) {
next unless $res-list;
nqp::pop($res-list);
nqp::pop_s($res-list);
$resolved = $res-list ?? $sep ~ nqp::join($sep, $res-list)
!! $empty;
next;
Expand All @@ -187,15 +188,16 @@ my class IO::Path is Cool {
# Symlink to absolute path
if nqp::iseq_s($link-parts[0], $empty) {
$resolved = nqp::shift($link-parts);
$res-list := nqp::list();
$res-list := nqp::list_s();
}

nqp::unshift($parts, nqp::pop($link-parts)) while $link-parts;
nqp::unshift($parts, nqp::pop($link-parts))
while $link-parts;
}
# Just a plain old path part, so append it and go on
else {
$resolved = $next;
nqp::push($res-list, $part);
nqp::push_s($res-list, $part);
}
}
$resolved = $sep unless nqp::chars($resolved);
Expand Down

0 comments on commit ddddd07

Please sign in to comment.