]> gitweb.factorcode.org Git - factor.git/blob - basis/io/files/links/links.factor
Merge branch 'master' into experimental
[factor.git] / basis / io / files / links / links.factor
1 ! Copyright (C) 2008 Slava Pestov, Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors io.backend io.files.info io.files.types
4 io.pathnames kernel math namespaces system vocabs.loader ;
5 IN: io.files.links
6
7 HOOK: make-link os ( target symlink -- )
8
9 HOOK: read-link os ( symlink -- path )
10
11 : copy-link ( target symlink -- )
12     [ read-link ] dip make-link ;
13
14 os unix? [ "io.files.links.unix" require ] when
15
16 : follow-link ( path -- path' )
17     [ parent-directory ] [ read-link ] bi append-path ;
18
19 SYMBOL: symlink-depth
20 10 symlink-depth set-global
21
22 ERROR: too-many-symlinks path n ;
23
24 <PRIVATE
25
26 : (follow-links) ( n path -- path' )
27     over 0 = [ symlink-depth get too-many-symlinks ] when
28     dup link-info type>> +symbolic-link+ =
29     [ [ 1- ] [ follow-link ] bi* (follow-links) ]
30     [ nip ] if ; inline recursive
31
32 PRIVATE>
33
34 : follow-links ( path -- path' )
35     [ symlink-depth get ] dip normalize-path (follow-links) ;