vocabs.refresh.monitor: handle symlink paths

On macosx, fsevents always provides the true path for changed files, even if the monitored path includes symlinks. This screws things up if a symlinked path is used as a vocab root. Fixes #404.
db4
Joe Groff 2011-11-15 20:04:44 -08:00
parent 34e77ec408
commit b5c72dab40
1 changed files with 9 additions and 3 deletions

View File

@ -3,7 +3,8 @@
USING: accessors assocs command-line concurrency.messaging USING: accessors assocs command-line concurrency.messaging
continuations init io.backend io.files io.monitors io.pathnames continuations init io.backend io.files io.monitors io.pathnames
kernel namespaces sequences sets splitting threads fry kernel namespaces sequences sets splitting threads fry
tr vocabs vocabs.loader vocabs.refresh vocabs.cache ; tr vocabs vocabs.loader vocabs.refresh vocabs.cache
io.files.links ;
IN: vocabs.refresh.monitor IN: vocabs.refresh.monitor
TR: convert-separators "/\\" ".." ; TR: convert-separators "/\\" ".." ;
@ -16,10 +17,15 @@ TR: convert-separators "/\\" ".." ;
: path>vocab-name ( path -- vocab ) : path>vocab-name ( path -- vocab )
dup ".factor" tail? [ parent-directory ] when ; dup ".factor" tail? [ parent-directory ] when ;
: scrub-links-in-path ( path -- path' )
normalize-path path-components "/"
[ append-path follow-links ] reduce ;
: chop-vocab-root ( path -- path' ) : chop-vocab-root ( path -- path' )
"resource:" prepend-path normalize-path "resource:" prepend-path normalize-path
dup vocab-roots get dup vocab-roots get
[ normalize-path ] map [ [ normalize-path ] map ]
[ [ scrub-links-in-path ] map ] bi append
[ head? ] with find nip [ head? ] with find nip
?head drop ; ?head drop ;
@ -29,7 +35,7 @@ TR: convert-separators "/\\" ".." ;
: monitor-loop ( monitor -- ) : monitor-loop ( monitor -- )
#! On OS X, monitors give us the full path, so we chop it #! On OS X, monitors give us the full path, so we chop it
#! off if its there. #! off if its there.
[ next-change path>> path>vocab changed-vocab reset-cache ] [ next-change path>> P path>vocab changed-vocab reset-cache ]
[ monitor-loop ] [ monitor-loop ]
bi ; bi ;