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 file test methods to IO.pm #2378

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

Added file test methods to IO.pm #2378

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

Comments

@p6rt
Copy link

p6rt commented Feb 26, 2011

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

Searchable as RT84966$

@p6rt
Copy link
Author

p6rt commented Feb 26, 2011

From will@worrbase.com

I implemented several of the file test methods listed here​:
https://github.com/perl6/specs/blob/master/S32-setting-library/IO.pod

Additionally, I reimplemented IO.l in Perl6 rather than pir, and I
changed the behaviour of IO.f so that it actually matched the spec
(devices aren't normal files).

Patch also submitted as github pull request.

@p6rt
Copy link
Author

p6rt commented Feb 26, 2011

From will@worrbase.com

0001-Added-nodev-requirement-to-IO.f.patch
From ef513564a171d724d602216e48f235779753d509 Mon Sep 17 00:00:00 2001
From: William Orr <will@worrbase.com>
Date: Fri, 25 Feb 2011 23:44:27 -0500
Subject: [PATCH] Added nodev requirement to IO.f

- spec says that regular files can be neither devices or directories

Added R(), W(), X()

Added O() and o()

Changed IO.l implementation to Perl6 instead of pir

Implemented u() g() and k()
---
 src/core/IO.pm |   60 +++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/src/core/IO.pm b/src/core/IO.pm
index 12d1550..f1b91ab 100644
--- a/src/core/IO.pm
+++ b/src/core/IO.pm
@@ -147,26 +147,64 @@ class IO is Cool {
         $.stat.exists;
     }
     multi method f() {
-        self.e ?? !$.stat.isdir !! Bool;
+        self.e ?? (!$.stat.isdir and !$.stat.isdev) !! Bool;
     }
 
     multi method s() {
         self.e ?? $.stat.size !! Any;
     }
 
+    multi method R() {
+        ?pir::new__PS('OS').can_read($.path);
+    }
+
+    multi method W() {
+        ?pir::new__PS('OS').can_write($.path);
+    }
+
+    multi method X() {
+        ?pir::new__PS('OS').can_execute($.path);
+    }
+
+    # These are clones of the above functions since parrot can't determine
+    # the effective uid yet
+    multi method r() {
+        ?pir::new__PS('OS').can_read($.path);
+    }
+
+    multi method w() {
+        ?pir::new__PS('OS').can_write($.path);
+    }
+
+    multi method x() {
+        ?pir::new__PS('OS').can_execute($.path);
+    }
+
     multi method l() {
-        my $fn = $.path;
-        ? Q:PIR{
-            .local pmc filename, file
-            filename = find_lex '$fn'
-            $S0 = filename
-
-            file = root_new ['parrot';'File']
-            $I0 = file.'is_link'($S0)
-            %r = box $I0
-        }
+        $.stat.islnk;
+    }
+
+    multi method O() {
+        pir::new__PS('OS').get_user_id() ~~ $.stat.uid;
     }
 
+    # Can't get effective uid in parrot
+    multi method o() {
+        pir::new__PS('OS').get_user_id() ~~ $.stat.uid;
+    }
+
+	multi method u() {
+		?($.stat.permissions +& 0o4000);
+	}
+
+	multi method g() {
+		?($.stat.permissions +& 0o2000);
+	}
+
+	multi method k() {
+		?($.stat.permissions +& 0o1000);
+	}
+
     multi method z() {
         $.e && $.s == 0;
     }
-- 
1.7.3.4

@p6rt
Copy link
Author

p6rt commented May 1, 2011

From @moritz

This has auld lang sine been applied, thanks for the patch, closing
ticket now.

@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