aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/netfiles
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-03-24 05:17:01 +0000
committerrsc <devnull@localhost>2005-03-24 05:17:01 +0000
commit65fb6fb74cb14afcc8b7040fcc6f253dec622fd0 (patch)
tree0f494c00efdcf64b1a1ac07008321661ccd1bf31 /src/cmd/netfiles
parented8dfe37dbd4470bbb9ce487e78b1d6ae365fb85 (diff)
downloadplan9port-65fb6fb74cb14afcc8b7040fcc6f253dec622fd0.tar.gz
plan9port-65fb6fb74cb14afcc8b7040fcc6f253dec622fd0.tar.bz2
plan9port-65fb6fb74cb14afcc8b7040fcc6f253dec622fd0.zip
Be a bit more resilient to errors.
Diffstat (limited to 'src/cmd/netfiles')
-rw-r--r--src/cmd/netfiles/main.c2
-rwxr-xr-xsrc/cmd/netfiles/netfileget37
-rw-r--r--src/cmd/netfiles/netfilelib.rc44
-rwxr-xr-xsrc/cmd/netfiles/netfileput8
-rwxr-xr-xsrc/cmd/netfiles/netfilestat16
5 files changed, 63 insertions, 44 deletions
diff --git a/src/cmd/netfiles/main.c b/src/cmd/netfiles/main.c
index bb388c5f..d7ee27a8 100644
--- a/src/cmd/netfiles/main.c
+++ b/src/cmd/netfiles/main.c
@@ -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;
}
diff --git a/src/cmd/netfiles/netfileget b/src/cmd/netfiles/netfileget
index ad2d6265..be133713 100755
--- a/src/cmd/netfiles/netfileget
+++ b/src/cmd/netfiles/netfileget
@@ -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
diff --git a/src/cmd/netfiles/netfilelib.rc b/src/cmd/netfiles/netfilelib.rc
index f610ccd0..13af8440 100644
--- a/src/cmd/netfiles/netfilelib.rc
+++ b/src/cmd/netfiles/netfilelib.rc
@@ -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 }
-
diff --git a/src/cmd/netfiles/netfileput b/src/cmd/netfiles/netfileput
index 84cdf610..c8a0ee3f 100755
--- a/src/cmd/netfiles/netfileput
+++ b/src/cmd/netfiles/netfileput
@@ -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)
diff --git a/src/cmd/netfiles/netfilestat b/src/cmd/netfiles/netfilestat
index f01c5de6..d27448d7 100755
--- a/src/cmd/netfiles/netfilestat
+++ b/src/cmd/netfiles/netfilestat
@@ -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
}