Skip to content

Commit

Permalink
fix dir(), panda now runs \o/. Also change splitpath to use :nofile p…
Browse files Browse the repository at this point in the history
…aram
  • Loading branch information
labster committed May 3, 2013
1 parent 87edfc0 commit 02c7fbb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
22 changes: 6 additions & 16 deletions src/core/IO.pm
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,4 @@
my role IO { } my role IO { }
# my class X::IO::Copy { ... }
# my class X::IO::Dir { ... }


sub print(|) { sub print(|) {
my $args := pir::perl6_current_args_rpa__P(); my $args := pir::perl6_current_args_rpa__P();
Expand Down Expand Up @@ -218,7 +216,6 @@ my class IO::Handle does IO::FileTestable {
$! ?? fail(X::IO::Copy.new(from => $.path, to => $dest, os-error => ~$!)) !! True $! ?? fail(X::IO::Copy.new(from => $.path, to => $dest, os-error => ~$!)) !! True
} }


# my class X::IO::Chmod { ... }
method chmod($mode) { method chmod($mode) {
nqp::chmod(nqp::unbox_s(~$.path), nqp::unbox_i($mode.Int)); nqp::chmod(nqp::unbox_s(~$.path), nqp::unbox_i($mode.Int));
return True; return True;
Expand Down Expand Up @@ -346,32 +343,32 @@ my class IO::Path::Win32 is IO::Path { method SPEC { IO::Spec::Win32 }; }
my class IO::Path::Cygwin is IO::Path { method SPEC { IO::Spec::Cygwin }; } my class IO::Path::Cygwin is IO::Path { method SPEC { IO::Spec::Cygwin }; }




sub dir(Cool $directory = '.', Mu :$test = none('.', '..')) { sub dir(Cool $path = '.', Mu :$test = none('.', '..')) {
my Mu $RSA := pir::new__PS('OS').readdir(nqp::unbox_s($directory.Str)); my Mu $RSA := pir::new__PS('OS').readdir(nqp::unbox_s($path.Str));
my $path = $directory.path;
my int $elems = nqp::elems($RSA); my int $elems = nqp::elems($RSA);
my @res; my @res;
my ($directory, $volume) = IO::Spec.splitpath(~$path, :nofile);
loop (my int $i = 0; $i < $elems; $i = $i + 1) { loop (my int $i = 0; $i < $elems; $i = $i + 1) {
my Str $file := nqp::p6box_s(pir::trans_encoding__Ssi( my Str $file := nqp::p6box_s(pir::trans_encoding__Ssi(
nqp::atpos_s($RSA, $i), nqp::atpos_s($RSA, $i),
pir::find_encoding__Is('utf8'))); pir::find_encoding__Is('utf8')));
if $file ~~ $test { if $file ~~ $test {
@res.push: $path.child($file); #this should be like IO::Path.child(:basename($file)) because of :volume
@res.push: IO::Path.new(:basename($file), :$directory, :$volume);
} }
} }
return @res.list; return @res.list;


CATCH { CATCH {
default { default {
X::IO::Dir.new( X::IO::Dir.new(
path => ~$directory, :$path,
os-error => .Str, os-error => .Str,
).throw; ).throw;
} }
} }
} }


# my class X::IO::Unlink { ... }
sub unlink($path) { sub unlink($path) {
nqp::unlink($path); nqp::unlink($path);
return True; return True;
Expand All @@ -385,7 +382,6 @@ sub unlink($path) {
} }
} }


# my class X::IO::Rmdir { ... }
sub rmdir($path) { sub rmdir($path) {
nqp::rmdir($path); nqp::rmdir($path);
return True; return True;
Expand Down Expand Up @@ -473,7 +469,6 @@ multi sub spurt(Cool $filename,
$fh.close; $fh.close;
} }


# my class X::IO::Cwd { ... }
proto sub cwd(|) { * } proto sub cwd(|) { * }
multi sub cwd() { multi sub cwd() {
return nqp::p6box_s( return nqp::p6box_s(
Expand All @@ -491,7 +486,6 @@ multi sub cwd() {
} }




# my class X::IO::Chdir { ... }
proto sub chdir(|) { * } proto sub chdir(|) { * }
multi sub chdir($path as Str) { multi sub chdir($path as Str) {
nqp::chdir(nqp::unbox_s($path)); nqp::chdir(nqp::unbox_s($path));
Expand All @@ -507,7 +501,6 @@ multi sub chdir($path as Str) {
} }
} }


# my class X::IO::Mkdir { ... }
proto sub mkdir(|) { * } proto sub mkdir(|) { * }
multi sub mkdir($path as Str, $mode = 0o777) { multi sub mkdir($path as Str, $mode = 0o777) {
nqp::mkdir($path, $mode); nqp::mkdir($path, $mode);
Expand All @@ -529,7 +522,6 @@ $PROCESS::ERR = IO::Handle.new;
nqp::bindattr(nqp::p6decont($PROCESS::ERR), nqp::bindattr(nqp::p6decont($PROCESS::ERR),
IO::Handle, '$!PIO', nqp::getstderr()); IO::Handle, '$!PIO', nqp::getstderr());


# my class X::IO::Rename { ... }
sub rename(Cool $from as Str, Cool $to as Str) { sub rename(Cool $from as Str, Cool $to as Str) {
nqp::rename(nqp::unbox_s($from), nqp::unbox_s($to)); nqp::rename(nqp::unbox_s($from), nqp::unbox_s($to));
return True; return True;
Expand Down Expand Up @@ -560,8 +552,6 @@ sub copy(Cool $from as Str, Cool $to as Str) {
} }
} }
} }
#my class X::IO::Symlink { ... }
#my class X::IO::Link { ... }
sub symlink(Cool $target as Str, Cool $name as Str) { sub symlink(Cool $target as Str, Cool $name as Str) {
nqp::symlink(nqp::unbox_s($target), nqp::unbox_s($name)); nqp::symlink(nqp::unbox_s($target), nqp::unbox_s($name));
return True; return True;
Expand Down
6 changes: 3 additions & 3 deletions src/core/IO/Spec/Unix.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ my class IO::Spec::Unix {
return @path return @path
} }


method splitpath( $path, $nofile = False ) { method splitpath( $path, :$nofile = False ) {
my ( $directory, $file ) = ( '', '' ); my ( $directory, $file ) = ( '', '' );


if $nofile { if $nofile {
Expand Down Expand Up @@ -130,8 +130,8 @@ my class IO::Spec::Unix {
$base = self.catdir( self.rootdir, $base ); $base = self.catdir( self.rootdir, $base );
} }


my ($path_volume, $path_directories) = self.splitpath( $path, 1 ); my ($path_volume, $path_directories) = self.splitpath( $path, :nofile );
my ($base_volume, $base_directories) = self.splitpath( $base, 1 ); my ($base_volume, $base_directories) = self.splitpath( $base, :nofile );


# Can't relativize across volumes # Can't relativize across volumes
return $path unless $path_volume eq $base_volume; return $path unless $path_volume eq $base_volume;
Expand Down
6 changes: 3 additions & 3 deletions src/core/IO/Spec/Win32.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ my class IO::Spec::Win32 is IO::Spec::Unix {
self.catpath($volume, $directory, $file); self.catpath($volume, $directory, $file);
} }


method splitpath($path as Str, $nofile as Bool = False) { method splitpath($path as Str, :$nofile = False) {


my ($volume,$directory,$file) = ('','',''); my ($volume,$directory,$file) = ('','','');
if ( $nofile ) { if ( $nofile ) {
Expand Down Expand Up @@ -148,9 +148,9 @@ my class IO::Spec::Win32 is IO::Spec::Unix {
$base = self.canonpath( $base ); $base = self.canonpath( $base );
} }


my ($path_directories, $path_file) = self.splitpath( $path, False )[1..2] ; my ($path_directories, $path_file) = self.splitpath( $path )[1..2] ;


my ($base_volume, $base_directories) = self.splitpath( $base, True ) ; my ($base_volume, $base_directories) = self.splitpath( $base, :nofile ) ;


$path = self.catpath( $path = self.catpath(
$base_volume, $base_volume,
Expand Down

0 comments on commit 02c7fbb

Please sign in to comment.