]> gitweb.factorcode.org Git - factor.git/commitdiff
io.files.info: adding checks for read, write, or execute permissions.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 24 Oct 2012 23:44:12 +0000 (16:44 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 24 Oct 2012 23:44:12 +0000 (16:44 -0700)
basis/io/files/info/info-docs.factor
basis/io/files/info/info.factor
basis/io/files/info/unix/unix.factor

index 17c4c6349124f04406659601ac74ee684924faa3..9b0c7a90463b84fc191ee74bb6eb3b55c7166e89 100644 (file)
@@ -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"
index 99d004638671b6473bd7c232816889946192a5b6..10a4121289420c94d75f022a79c1b23f8dd50206 100644 (file)
@@ -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" ] }
index a3c82af4cf5d99a337ee7223d1821b7ad3d5f145..a446221ffcf2d2419f36e1f65433e88c6c13b498 100644 (file)
@@ -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