aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/netfiles/netfilestat
blob: 1d687e5153767c9d4631b8a2da7a258e4532305d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/local/plan9/bin/rc

if(! ~ $#* 2){
	echo usage: netisdir system path >[1=2]
	exit usage
}

f=dostat
ns=`{namespace}
if(u test -S $ns/$1)
	f=$f^9p

t=/tmp/netisdir.$pid.$USER
fn sigexit { rm -f $t }

fn dostat {
	{
		echo !echo XXX connected
		echo cd $2
		echo !echo XXX directory exists
	}  | sftp -b - $1 >$t >[2=1]
	if(9 grep -s XXX.directory.exists $t){
		echo directory
		exit 0
	}
	if(9 grep -s 'is not a directory' $t){
		echo file
		exit 0
	}
	cat $t | sed 's/sftp> //g; /^$/d; /XXX/d; /^cd /d' >[1=2]
	if(! 9 grep -s XXX.connected $t){
		echo connect failed
		exit 0
	}
	echo nonexistent
	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