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);
cprint("b3 \t=> name=%s addr=%s\n", name, addr);
if(strcmp(name, lastfail) == 0){
cprint("b3 \t=> non-existant (cached)\n");
cprint("b3 \t=> nonexistent (cached)\n");
free(name);
return -1;
}

View file

@ -13,33 +13,34 @@ if(! ~ $#* 2){
. 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 {
if(! 9p read $1/$2)
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 {
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
exit 0

View file

@ -3,19 +3,43 @@ ns=`{namespace}
if(</dev/null dial 'unix!'^$ns/$1 >[2]/dev/null)
f=$f^9p
fn mysftp {
if(! </dev/null dial 'unix!'^$ns/$1.sftp >[2]/dev/null){
echo 'caching sftp' $1 >[1=2]
sftpcache -D $1
t=/tmp/netfilexxx.$pid.$USER
fn sigexit { rm -f $t $t.* }
fn runsftp {
eflag=no
if(~ $1 -e){
eflag=yes
shift
}
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{
cat >$t
if(! 9 echo -put $t $2 | mysftp $1 >$t.e >[2=1])
exit 1
egrep -v '^Uploading' $t.e >$t.e2
if(test -s $t.e2){
cat $t.e >[1=2]
exit 1
}
echo put $t $2 | runsftp -e $1
}
fn putfile9p{
if(! 9p write $1/$2)

View file

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