]> gitweb.factorcode.org Git - factor.git/commitdiff
add canonicalize-path, fix a bug in file-extension
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 18 Feb 2009 19:33:55 +0000 (13:33 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 18 Feb 2009 19:33:55 +0000 (13:33 -0600)
core/io/pathnames/pathnames-docs.factor
core/io/pathnames/pathnames-tests.factor
core/io/pathnames/pathnames.factor

index a4f261391a131289a29d56a6f0bbb7e39b50574d..f5ad6e533b317754b6b23b2b23a1a05ea58c2ea5 100644 (file)
@@ -1,4 +1,5 @@
-USING: help.markup help.syntax io.backend io.files strings ;
+USING: help.markup help.syntax io.backend io.files strings
+sequences ;
 IN: io.pathnames
 
 HELP: path-separator?
@@ -22,6 +23,10 @@ HELP: file-name
     { $example "USING: io.pathnames prettyprint ;" "\"/usr/libexec/awk/\" file-name ." "\"awk\"" }
 } ;
 
+HELP: path-components
+{ $values { "path" "a pathnames string" } { "seq" sequence } }
+{ $description "Splits a pathname on the " { $link path-separator } " into its its component strings." } ;
+
 HELP: append-path
 { $values { "str1" "a string" } { "str2" "a string" } { "str" "a string" } }
 { $description "Appends " { $snippet "str1" } " and " { $snippet "str2" } " to form a pathname." } ;
@@ -57,6 +62,10 @@ HELP: normalize-path
 { $values { "str" "a pathname string" } { "newstr" "a new pathname string" } }
 { $description "Called by words such as " { $link <file-reader> } " and " { $link <file-writer> } " to prepare a pathname before passing it to underlying code." } ;
 
+HELP: canonicalize-path
+{ $values { "path" "a pathname string" } { "path'" "a new pathname string" } }
+{ $description "Returns an canonical name for a path. The canonical name is an absolute path containing no symlinks." } ;
+
 HELP: <pathname>
 { $values { "string" "a pathname string" } { "pathname" pathname } }
 { $description "Creates a new " { $link pathname } "." } ;
@@ -74,9 +83,12 @@ ARTICLE: "io.pathnames" "Pathname manipulation"
 { $subsection POSTPONE: P" }
 "Pathname manipulation:"
 { $subsection normalize-path }
+{ $subsection canonicalize-path }
 { $subsection parent-directory }
 { $subsection file-name }
 { $subsection last-path-separator }
+{ $subsection path-components }
+{ $subsection prepend-path }
 { $subsection append-path }
 "Pathname presentations:"
 { $subsection pathname }
index 41498fa15a3cfbaffbd553bc6fe1d8ae57ccadfe..c3e419e60d9e8547d9779ae879e3bd0cf12cf3d2 100644 (file)
@@ -66,3 +66,7 @@ IN: io.pathnames.tests
 ] with-scope
 
 [ t ] [ cwd "misc" resource-path [ ] with-directory cwd = ] unit-test
+
+! Regression test for bug in file-extension
+[ f ] [ "/funny.directory/file-with-no-extension" file-extension ] unit-test
+[ "" ] [ "/funny.directory/file-with-no-extension." file-extension ] unit-test
index 96ac87282611248a0125d9d9c1308f5598c83d0a..eba3e6a19fdb41425a34abb561abc508fbe95d56 100644 (file)
@@ -119,7 +119,14 @@ PRIVATE>
     ] unless ;
 
 : file-extension ( filename -- extension )
-    "." split1-last nip ;
+    file-name "." split1-last nip ;
+
+: path-components ( path -- seq )
+    normalize-path path-separator split harvest ;
+
+HOOK: canonicalize-path os ( path -- path' )
+
+M: object canonicalize-path normalize-path ;
 
 : resource-path ( path -- newpath )
     "resource-path" get prepend-path ;