Add canonicalize-drive because Windows likes C: instead of c:.
Add >windows-path for path string comparison.
Add canonicalize-path-full for fixing the path, drive, and / to \\ on
Windows.
HOOK: file-executable? os ( path -- ? )
: mount-points ( -- assoc )
- file-systems [ [ mount-point>> ] keep ] H{ } map>assoc ;
+ file-systems [ [ mount-point>> canonicalize-path-full ] keep ] H{ } map>assoc ;
: (find-mount-point-info) ( path assoc -- mtab-entry )
- [ resolve-symlinks ] dip
+ [ resolve-symlinks canonicalize-path-full ] dip
2dup at* [
2nip
] [
- drop [ parent-directory ] dip (find-mount-point-info)
+ drop [ parent-directory ] dip
+ (find-mount-point-info)
] if ;
: find-mount-point-info ( path -- file-system-info )
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.data alien.strings
-alien.syntax arrays assocs classes.struct combinators
+alien.syntax arrays ascii assocs classes.struct combinators
combinators.short-circuit continuations destructors environment io
io.backend io.binary io.buffers io.files io.files.private
-io.files.types io.pathnames io.ports io.streams.c io.streams.null
-io.timeouts kernel libc literals locals math math.bitwise namespaces
-sequences specialized-arrays system threads tr vectors windows
+io.files.types io.pathnames io.pathnames.private io.ports io.streams.c
+io.streams.null io.timeouts kernel libc literals locals math math.bitwise
+namespaces sequences specialized-arrays system threads tr vectors windows
windows.errors windows.handles windows.kernel32 windows.shell32
windows.time windows.types windows.winsock splitting ;
SPECIALIZED-ARRAY: ushort
M: windows canonicalize-path
remove-unicode-prefix canonicalize-path* ;
+M: windows canonicalize-drive
+ dup windows-absolute-path? [ ":" split1 [ >upper ] dip ":" glue ] when ;
+
+M: windows canonicalize-path-full canonicalize-path canonicalize-drive >windows-path ;
+
M: windows root-path remove-unicode-prefix root-path* ;
M: windows relative-path remove-unicode-prefix relative-path* ;
! Copyright (C) 2004, 2009 Slava Pestov, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors combinators io.backend kernel math math.order
-namespaces sequences splitting strings system ;
+USING: accessors assocs combinators io.backend kernel math
+math.order namespaces sequences splitting strings system ;
IN: io.pathnames
SYMBOL: current-directory
[ nip ]
} cond ;
-: windows-absolute-path? ( path -- path ? )
+: windows-absolute-path? ( path -- ? )
{
{ [ dup "\\\\?\\" head? ] [ t ] }
{ [ dup length 2 < ] [ f ] }
{ [ dup second CHAR: : = ] [ t ] }
[ f ]
- } cond ;
+ } cond nip ;
: special-path? ( path -- rest ? )
{
: absolute-path? ( path -- ? )
{
- { [ dup empty? ] [ f ] }
- { [ dup special-path? nip ] [ t ] }
+ { [ dup empty? ] [ drop f ] }
+ { [ dup special-path? nip ] [ drop t ] }
{ [ os windows? ] [ windows-absolute-path? ] }
- { [ dup first path-separator? ] [ t ] }
- [ f ]
- } cond nip ;
+ { [ dup first path-separator? ] [ drop t ] }
+ [ drop f ]
+ } cond ;
: append-relative-path ( path1 path2 -- path )
[ trim-tail-separators ]
M: object canonicalize-path canonicalize-path* ;
+HOOK: canonicalize-drive io-backend ( path -- path' )
+
+M: object canonicalize-drive ;
+
+HOOK: canonicalize-path-full io-backend ( path -- path' )
+
+M: object canonicalize-path-full canonicalize-path canonicalize-drive ;
+
+: >windows-path ( path -- path' ) H{ { CHAR: / CHAR: \\ } } substitute ;
+
TUPLE: pathname string ;
C: <pathname> pathname