# New Ticket Created by William Orr # Please include the string: [perl #84950] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=84950 >
rakudo didn't have the ability to rm, copy, move, chmod, or link files even though the underlying VM supports it. I added support for all of those functions, as well as adding the ability to get permissions information from IO::Stat. This patch was also submitted as a pull request on github.
>From 581b99cdc23e474b8b4a8056328ecc013e32b754 Mon Sep 17 00:00:00 2001 From: William Orr <w...@worrbase.com> Date: Thu, 24 Feb 2011 05:05:17 -0500 Subject: [PATCH] Added move to IO.pm Added chmod Can look at filesystem permissions Removed unnecessary functions - Didn't need all the stuff I wrote Implemented copy Added additional basic IO functions - added rm - added link Turns outperl6 does support octal --- src/core/IO.pm | 42 ++++++++++++++++++++++++++++++++++++++++++ src/core/IO/Stat.pm | 4 ++++ 2 files changed, 46 insertions(+), 0 deletions(-) diff --git a/src/core/IO.pm b/src/core/IO.pm index d60eff5..12d1550 100644 --- a/src/core/IO.pm +++ b/src/core/IO.pm @@ -292,4 +292,46 @@ multi sub cwd() { $! ?? fail($!) !! $pwd; } +multi sub move($src as Str, $dest as Str) { + try { + pir::new__PS('OS').rename($src, $dest); + } + $! ?? fail($!) !! True +} + +multi sub chmod($path as Str, $mode as Int) { + try { + pir::new__PS('OS').chmod($path, $mode); + } + $! ?? fail($!) !! True +} + +multi sub copy($src as Str, $dest as Str) { + try { + pir::new__PS('File').copy($src, $dest); + } + $! ?? fail($!) !! True +} + +multi sub rm($path as Str) { + try { + pir::new__PS('OS').rm($path); + } + $! ?? fail($!) !! True +} + +multi sub link($src as Str, $dest as Str, Bool :$hard = False) { + if $hard { + try { + pir::new__PS('OS').link($src, $dest); + } + $! ?? fail($!) !! return True; + } + + try { + pir::new__PS('OS').symlink($src, $dest); + } + $! ?? fail($!) !! True +} + # vim: ft=perl6 diff --git a/src/core/IO/Stat.pm b/src/core/IO/Stat.pm index dba9c86..95ab65d 100644 --- a/src/core/IO/Stat.pm +++ b/src/core/IO/Stat.pm @@ -44,6 +44,10 @@ class IO::Stat { method gid { pir::stat__isi($.path, 10); } + + method permissions { + pir::stat__isi($.path, -3) +& 0o7777; + } } # vim: ft=perl6 -- 1.7.4.1