Be a bit more resilient to errors.

This commit is contained in:
rsc 2005-03-24 05:17:01 +00:00
parent ed8dfe37db
commit 65fb6fb74c
5 changed files with 63 additions and 44 deletions

View file

@ -462,7 +462,7 @@ do3(Win *w, char *text)
cleanname(name); cleanname(name);
cprint("b3 \t=> name=%s addr=%s\n", name, addr); cprint("b3 \t=> name=%s addr=%s\n", name, addr);
if(strcmp(name, lastfail) == 0){ if(strcmp(name, lastfail) == 0){
cprint("b3 \t=> non-existant (cached)\n"); cprint("b3 \t=> nonexistent (cached)\n");
free(name); free(name);
return -1; return -1;
} }

View file

@ -13,33 +13,34 @@ if(! ~ $#* 2){
. netfilelib.rc $1 . netfilelib.rc $1
fn getfile {
rm -f $t
if(! 9 echo -get $2 $t | mysftp $1 >$t.e >[2=1])
exit 1
egrep -v '^Fetching' $t.e >$t.e2
if(test -s $t.e2){
cat $t.e >[1=2]
exit 1
}
cat $t
}
fn getfile9p { fn getfile9p {
if(! 9p read $1/$2) if(! 9p read $1/$2)
exit 1 exit 1
} }
fn getdir {
if(! {echo cd $2; echo ls -l} | mysftp $1 | sed '1,2d; s/sftp> //g; /^$/d' >$t)
exit 1
cat $t | awk '$NF == "." || $NF == ".." { next } {s = $NF; if($0 ~ /^d/) s = s "/"; print s}'
}
fn getdir9p { fn getdir9p {
9p ls -l $1/$2 | awk '{s=$NF; if($0 ~ /^d/) s=s"/"; print s}' 9p ls -l $1/$2 | awk '{s=$NF; if($0 ~ /^d/) s=s"/"; print s}'
} }
fn getfile {
rm -f $t
echo get $2 $t | runsftp -e $1
cat $t
}
fn getdir {
{echo cd $2; echo ls -l} | runsftp $1
awk '
$NF == "." || $NF == ".." { next }
{
s = $NF
if($0 ~ /^d/)
s = s "/"
print s
}
' $t.sftp
}
$f $1 $2 $f $1 $2
exit 0 exit 0

View file

@ -3,19 +3,43 @@ ns=`{namespace}
if(</dev/null dial 'unix!'^$ns/$1 >[2]/dev/null) if(</dev/null dial 'unix!'^$ns/$1 >[2]/dev/null)
f=$f^9p f=$f^9p
fn mysftp { t=/tmp/netfilexxx.$pid.$USER
if(! </dev/null dial 'unix!'^$ns/$1.sftp >[2]/dev/null){ fn sigexit { rm -f $t $t.* }
echo 'caching sftp' $1 >[1=2]
sftpcache -D $1 fn runsftp {
eflag=no
if(~ $1 -e){
eflag=yes
shift
} }
if(! </dev/null dial 'unix!'^$ns/$1.sftp >[2]/dev/null){ if(! </dev/null dial 'unix!'^$ns/$1.sftp >[2]/dev/null){
sftp -b /dev/stdin $1 sftpcache -D $1 >/dev/tty
} }
if not{ {
{cat; echo DONE} | dial -e 'unix!'^$ns/$1.sftp if(! </dev/null dial 'unix!'^$ns/$1.sftp >[2]/dev/null){
sed 's/^/-/' | sftp -b /dev/stdin $1 && echo DONE
}
if not{
{cat; echo DONE} | dial -e 'unix!'^$ns/$1.sftp
}
} >$t.sftp1 >[2=1]
sed 's/^/1 /' $t.sftp1
sed '/^sftp> /d
/^Connecting to /d
/^Fetching /d
/^Uploading /d
/^DONE$/d
' $t.sftp1 >$t.sftp
if(! 9 grep -s '^DONE$' $t.sftp1){
echo sftp did not finish: >[1=2]
sed 's/^/ /g' $t.sftp1 >[1=2]
exit 1
} }
if(~ $eflag yes && test -s $t.sftp){
echo sftp error output: >[1=2]
sed '/^DONE$/d; s/^/ /g' $t.sftp1 >[1=2]
exit 1
}
status=''
} }
t=/tmp/netfilexxx.$pid.$USER
fn sigexit { rm -f $t $t.e $t.e2 }

View file

@ -11,13 +11,7 @@ f=putfile
fn putfile{ fn putfile{
cat >$t cat >$t
if(! 9 echo -put $t $2 | mysftp $1 >$t.e >[2=1]) echo put $t $2 | runsftp -e $1
exit 1
egrep -v '^Uploading' $t.e >$t.e2
if(test -s $t.e2){
cat $t.e >[1=2]
exit 1
}
} }
fn putfile9p{ fn putfile9p{
if(! 9p write $1/$2) if(! 9p write $1/$2)

View file

@ -10,23 +10,23 @@ f=dostat
. netfilelib.rc $1 . netfilelib.rc $1
fn dostat { fn dostat {
{ echo cd $2 | runsftp $1
9 echo -cd $2 if(9 test -e $t.sftp -a ! -s $t.sftp){
} | mysftp $1 >$t
if(9 test -e $t -a ! -s $t){
echo directory echo directory
exit 0 exit 0
} }
if(9 grep -s 'Can''t change directory|is not a directory' $t){ if(9 grep -s 'Can''t change directory|is not a directory' $t.sftp){
echo file echo file
exit 0 exit 0
} }
if(9 grep -s 'Couldn''t stat remote file|such file' $t){ if(9 grep -s 'Couldn''t stat remote file|such file' $t.sftp){
echo nonexistent echo nonexistent
exit 0 exit 0
} }
cat $t >[1=2] {
echo unknown error echo unknown error:
sed 's/^/ /' $t.sftp
} >[1=2]
exit 0 exit 0
} }