Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added basic IO functions #2377

Closed
p6rt opened this issue Feb 26, 2011 · 4 comments
Closed

Added basic IO functions #2377

p6rt opened this issue Feb 26, 2011 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Feb 26, 2011

Migrated from rt.perl.org#84950 (status was 'resolved')

Searchable as RT84950$

@p6rt
Copy link
Author

p6rt commented Feb 26, 2011

From will@worrbase.com

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.

@p6rt
Copy link
Author

p6rt commented Feb 26, 2011

From will@worrbase.com

0001-Added-move-to-IO.pm.patch
From 581b99cdc23e474b8b4a8056328ecc013e32b754 Mon Sep 17 00:00:00 2001
From: William Orr <will@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

@p6rt
Copy link
Author

p6rt commented May 1, 2011

From @moritz

patch has long been applied, closing ticket, thank you.

@p6rt
Copy link
Author

p6rt commented May 1, 2011

@moritz - Status changed from 'new' to 'resolved'

@p6rt p6rt closed this as completed May 1, 2011
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant