Miller, Raul D wrote:
David Mitchell wrote:
Does anyone know how to detect a link in Linux using J601? I get
this:
1!:0 <'/var/lib/ntp/var/lib/ntp'
+---+------------------+---+---+------+----------+
|ntp|2006 9 27 16 28 10|144|r-x|r---d-|drwxr-xr-x|
+---+------------------+---+---+------+----------+
ls -l /var/lib/ntp/var/lib/ntp
lrwxrwxrwx 1 root root 5 Apr 11 2005 ntp -> ../..
The problem with links is that they have two identities:
their identity as a link, and their identity as whatever
they link to.
To make links function reliably, their usual identity
is the identity of whatever they link to -- a special
system call is needed to detect that they are anything
else (lstat instead of stat).
One approach: invoke another program, which uses lstat.
If ls is not available, you can assume that no links
are present.
You could also use cd to call out to lstat(), if you
prefer.
Thanks for your suggestions. Here is one approach:
NB. lstodir
NB. lstodir - duplicate format of 1!:0 with results of ls
NB. lstd - duplicate format of 1!:0 using ls update date instead of access
date
fixts=: 3 : 0
<"1 (_1"."1 '- 'charsub >0{"1 y),.3{."1 ]_1"."1 ': . 'charsub >1{"1 y
)
flagso=: 3 : 0
<(('r-'-: 4 5{>0{y){'-r'),(('.'={.>8{y){'-h'),'--',({.>0{y),'-'
)
flags=: 3 : 0
<(('r-'-: 1 2{>0{y){'-r'),(('.'={.>8{y){'-h'),'--',({.>0{y),'-'
)
lstodir=: 3 : 0
q=.>cut&.>LF cut 2!:0 'ls -ldbu --time-style=full-iso -A ',y
(((('/'e.]){(0,([:>:(] i:&'/'))))y)}.&.>8{"1 q),.(fixts 5 6{"1 q),.(_1".&.>4{"1
q),.((4 5 6{]) &.>0{"1 q),.(flagso"1 q),.0{"1 q
)
lstd=: 3 : 0
q=.>cut&.>LF cut 2!:0 'ls -ldb --time-style=full-iso -A ',y
(((('/'e.]){(0,([:>:(] i:&'/'))))y)}.&.>8{"1 q),.(fixts 5 6{"1 q),.(_1".&.>4{"1
q),.((1 2 3{]) &.>0{"1 q),.(flags"1 q),.0{"1 q
--
David Mitchell
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm