From 37bb5f6917961e9373b20cb2b4866beee7a51090 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Wed, 24 Oct 2012 16:44:12 -0700 Subject: [PATCH] io.files.info: adding checks for read, write, or execute permissions. --- basis/io/files/info/info-docs.factor | 20 +++++++++++++++++++- basis/io/files/info/info.factor | 4 ++++ basis/io/files/info/unix/unix.factor | 4 ++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/basis/io/files/info/info-docs.factor b/basis/io/files/info/info-docs.factor index 17c4c63491..9b0c7a9046 100644 --- a/basis/io/files/info/info-docs.factor +++ b/basis/io/files/info/info-docs.factor @@ -1,4 +1,4 @@ -USING: help.markup help.syntax arrays io.files ; +USING: arrays help.markup help.syntax kernel io.files ; IN: io.files.info HELP: file-info @@ -37,6 +37,18 @@ HELP: file-system-info } } ; +HELP: file-readable? +{ $values { "path" "a pathname string" } { "?" boolean } } +{ $description "Returns whether the file specified by " { $snippet "path" } " exists and is readable by the current process." } ; + +HELP: file-writable? +{ $values { "path" "a pathname string" } { "?" boolean } } +{ $description "Returns whether the file specified by " { $snippet "path" } " exists and is writable by the current process." } ; + +HELP: file-executable? +{ $values { "path" "a pathname string" } { "?" boolean } } +{ $description "Returns whether the file specified by " { $snippet "path" } " exists and is executable by the current process." } ; + ARTICLE: "io.files.info" "File system meta-data" "File meta-data:" { $subsections @@ -51,6 +63,12 @@ ARTICLE: "io.files.info" "File system meta-data" { $subsections file-system-info file-systems +} +"File permissions:" +{ $subsections + file-readable? + file-writable? + file-executable? } ; ABOUT: "io.files.info" diff --git a/basis/io/files/info/info.factor b/basis/io/files/info/info.factor index 99d0046386..10a4121289 100644 --- a/basis/io/files/info/info.factor +++ b/basis/io/files/info/info.factor @@ -25,6 +25,10 @@ available-space free-space used-space total-space ; HOOK: file-system-info os ( path -- file-system-info ) +HOOK: file-readable? os ( path -- ? ) +HOOK: file-writable? os ( path -- ? ) +HOOK: file-executable? os ( path -- ? ) + { { [ os unix? ] [ "io.files.info.unix" ] } { [ os windows? ] [ "io.files.info.windows" ] } diff --git a/basis/io/files/info/unix/unix.factor b/basis/io/files/info/unix/unix.factor index a3c82af4cf..a446221ffc 100644 --- a/basis/io/files/info/unix/unix.factor +++ b/basis/io/files/info/unix/unix.factor @@ -284,4 +284,8 @@ PRIVATE> [ drop file-type>executable ] } case ; +M: unix file-readable? flags{ F_OK R_OK } access 0 = ; +M: unix file-writable? flags{ F_OK W_OK } access 0 = ; +M: unix file-executable? flags{ F_OK X_OK } access 0 = ; + "io.files.info.unix." os name>> append require