aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/netfiles/netfilestat
blob: d27448d72feed25430636a3a30f89d65e19cb324 (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
#!/usr/local/plan9/bin/rc

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

f=dostat

. netfilelib.rc $1

fn dostat {
	echo cd $2 | runsftp $1
	if(9 test -e $t.sftp -a ! -s $t.sftp){
		echo directory
		exit 0
	}
	if(9 grep -s 'Can''t change directory|is not a directory' $t.sftp){
		echo file
		exit 0
	}
	if(9 grep -s 'Couldn''t stat remote file|such file' $t.sftp){
		echo nonexistent
		exit 0
	}
	{
		echo unknown error:
		sed 's/^/	/' $t.sftp 
	} >[1=2]
	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