plan9port/src/cmd/netfiles/netfilestat

47 lines
665 B
Text
Raw Normal View History

2005-03-18 19:30:22 +00:00
#!/usr/local/plan9/bin/rc
if(! ~ $#* 2){
2005-03-20 23:39:48 +00:00
echo usage: netfilestat system path >[1=2]
2005-03-18 19:30:22 +00:00
exit usage
}
f=dostat
2005-03-21 07:37:34 +00:00
. netfilelib.rc $1
2005-03-18 19:30:22 +00:00
fn dostat {
2005-03-24 05:17:01 +00:00
echo cd $2 | runsftp $1
if(9 test -e $t.sftp -a ! -s $t.sftp){
2005-03-18 19:30:22 +00:00
echo directory
exit 0
}
2005-03-24 05:17:01 +00:00
if(9 grep -s 'Can''t change directory|is not a directory' $t.sftp){
2005-03-18 19:30:22 +00:00
echo file
exit 0
}
2005-03-24 05:17:01 +00:00
if(9 grep -s 'Couldn''t stat remote file|such file' $t.sftp){
2005-03-21 07:37:34 +00:00
echo nonexistent
2005-03-18 19:30:22 +00:00
exit 0
}
2005-03-24 05:17:01 +00:00
{
echo unknown error:
sed 's/^/ /' $t.sftp
} >[1=2]
2005-03-18 19:30:22 +00:00
exit 0
}
fn dostat9p {
if(! 9p ls -ld $1/$2 >$t >[2]/dev/null){
echo nonexistent
exit 0
}
if(9 grep -s '^d' $t){
echo directory
exit 0
}
echo file
exit 0
}
$f $1 $2