]> gitweb.factorcode.org Git - factor.git/commitdiff
pathnames: support pathnames more places like append-path and recursive-directory...
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 17 Feb 2023 02:55:48 +0000 (20:55 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 26 Feb 2023 23:11:04 +0000 (17:11 -0600)
In general, P"" or `pathname` is a frontend/tooling convenience concept
with tab-complete for paths in the ui. Backend apis should see strings.

basis/io/directories/directories-tests.factor
basis/io/directories/directories.factor
core/io/pathnames/pathnames.factor

index 0f2933cdb6d9520f218f1ba4557c124172ae8a4b..2d027e88de49be9a68d3724429d60658177b2960 100644 (file)
@@ -294,3 +294,9 @@ tools.test ;
         ] with-variable
     ] with-test-directory
 ] unit-test
+
+! test P"" pathnames
+[ "resource:extra/math" recursive-directory-files drop ] must-not-fail
+
+{ "/foo/bar" } [ P"/foo" P"./bar" append-path ] unit-test
+{ "/bar/foo" } [ P"./foo" P"/bar" prepend-path ] unit-test
index c061d30f4131ec4b69b8ede695ca807a6d4ba85c..6f6b00dc75f44a7d0111ca4b76058cee7e457a7d 100644 (file)
@@ -88,6 +88,7 @@ TUPLE: directory-iterator
     [ queue>> swap '[ _ _ [ push-front ] [ push-back ] if ] each ] bi ;
 
 : <directory-iterator> ( path bfs? -- iter )
+    [ pathname> ] dip
     <dlist> directory-iterator boa
     dup path>> over push-directory-entries ;
 
index 6bf366797faea6aea3e116ad5d1e5b9a5fba9042..a172fe45bcb1d8a3305f2c5c1be512dd085d58d3 100644 (file)
@@ -78,6 +78,16 @@ ERROR: no-parent-directory path ;
 
 PRIVATE>
 
+TUPLE: pathname string ;
+
+C: <pathname> pathname
+
+: >pathname ( obj -- pathname )
+    dup pathname? [ <pathname> ] unless ;
+
+: pathname> ( pathname -- obj )
+    dup pathname? [ string>> ] when ;
+
 : absolute-path? ( path -- ? )
     {
         { [ dup empty? ] [ drop f ] }
@@ -92,6 +102,7 @@ PRIVATE>
     [ trim-head-separators ] bi* "/" glue ;
 
 : append-path ( path1 path2 -- path )
+    [ pathname> ] bi@
     {
         { [ over empty? ] [ append-path-empty ] }
         { [ dup empty? ] [ drop ] }
@@ -221,13 +232,6 @@ M: object canonicalize-path-full canonicalize-path canonicalize-drive ;
 
 : >windows-path ( path -- path' ) H{ { CHAR: / CHAR: \\ } } substitute ;
 
-TUPLE: pathname string ;
-
-C: <pathname> pathname
-
 M: pathname absolute-path string>> absolute-path ;
 
 M: pathname <=> [ string>> ] compare ;
-
-: >pathname ( obj -- pathname )
-    dup pathname? [ <pathname> ] unless ;