diff options
author | rsc <devnull@localhost> | 2005-03-21 07:37:34 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-03-21 07:37:34 +0000 |
commit | b8c9f31785f3243a52432023d4d555d490963769 (patch) | |
tree | 4a55c22d8af3e61f4aa4528c4aefb03fd684769c /src/cmd/netfiles | |
parent | e96129189712a83de71d45cbc852a54c5960d575 (diff) | |
download | plan9port-b8c9f31785f3243a52432023d4d555d490963769.tar.gz plan9port-b8c9f31785f3243a52432023d4d555d490963769.tar.bz2 plan9port-b8c9f31785f3243a52432023d4d555d490963769.zip |
new
Diffstat (limited to 'src/cmd/netfiles')
-rw-r--r-- | src/cmd/netfiles/main.c | 16 | ||||
-rw-r--r-- | src/cmd/netfiles/mkfile | 1 | ||||
-rwxr-xr-x | src/cmd/netfiles/netfileget | 16 | ||||
-rw-r--r-- | src/cmd/netfiles/netfilelib.rc | 21 | ||||
-rwxr-xr-x | src/cmd/netfiles/netfileput | 14 | ||||
-rwxr-xr-x | src/cmd/netfiles/netfilestat | 24 |
6 files changed, 60 insertions, 32 deletions
diff --git a/src/cmd/netfiles/main.c b/src/cmd/netfiles/main.c index 9c5f83e7..bb388c5f 100644 --- a/src/cmd/netfiles/main.c +++ b/src/cmd/netfiles/main.c @@ -173,12 +173,22 @@ isdot(Win *w, uint xq0, uint xq1) char* expandarg(Win *w, Event *e) { + uint q0, q1; + if(e->c2 == 'l') /* in tag - no choice but to accept acme's expansion */ return estrdup(e->text); - dprint("expand %d %d %d %d\n", e->oq0, e->oq1, e->q0, e->q1); - if(e->oq0 == e->oq1 && e->q0 != e->q1 && !isdot(w, e->q0, e->q1)) + winaddr(w, ","); + winctl(w, "addr=dot"); + + q0 = winreadaddr(w, &q1); + cprint("acme expanded %d-%d into %d-%d (dot %d-%d)\n", + e->oq0, e->oq1, e->q0, e->q1, q0, q1); + + if(e->oq0 == e->oq1 && e->q0 != e->q1 && !isdot(w, e->q0, e->q1)){ winaddr(w, "#%ud+#1-/[^ \t\\n]*/,#%ud-#1+/[^ \t\\n]*/", e->q0, e->q1); - else + q0 = winreadaddr(w, &q1); + cprint("\tre-expand to %d-%d\n", q0, q1); + }else winaddr(w, "#%ud,#%ud", e->q0, e->q1); return winmread(w, "xdata"); } diff --git a/src/cmd/netfiles/mkfile b/src/cmd/netfiles/mkfile index 9d953c99..6f0038f4 100644 --- a/src/cmd/netfiles/mkfile +++ b/src/cmd/netfiles/mkfile @@ -15,6 +15,7 @@ XTARG=\ netfileget\ netfileput\ netfilestat\ + netfilelib.rc\ install:V: for i in $XTARG; do diff --git a/src/cmd/netfiles/netfileget b/src/cmd/netfiles/netfileget index 88544f5c..ad2d6265 100755 --- a/src/cmd/netfiles/netfileget +++ b/src/cmd/netfiles/netfileget @@ -11,17 +11,17 @@ if(! ~ $#* 2){ exit usage } -ns=`{namespace} -if(u test -S $ns/$1) - f=$f^9p - -t=/tmp/netget.$pid.$USER -fn sigexit { rm -f $t } +. netfilelib.rc $1 fn getfile { rm -f $t - if(! echo get $2 $t | sftp -b /dev/stdin $1 >/dev/null) + 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 } @@ -31,7 +31,7 @@ fn getfile9p { } fn getdir { - if(! {echo cd $2; echo ls -l} | sftp -b /dev/stdin $1 | sed '1,2d; s/sftp> //g; /^$/d' >$t) + 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}' } diff --git a/src/cmd/netfiles/netfilelib.rc b/src/cmd/netfiles/netfilelib.rc new file mode 100644 index 00000000..f610ccd0 --- /dev/null +++ b/src/cmd/netfiles/netfilelib.rc @@ -0,0 +1,21 @@ + +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 + } + if(! </dev/null dial 'unix!'^$ns/$1.sftp >[2]/dev/null){ + sftp -b /dev/stdin $1 + } + if not{ + {cat; echo DONE} | dial -e 'unix!'^$ns/$1.sftp + } +} + +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 7b90124d..84cdf610 100755 --- a/src/cmd/netfiles/netfileput +++ b/src/cmd/netfiles/netfileput @@ -6,17 +6,18 @@ if(! ~ $#* 2){ } f=putfile -ns=`{namespace} -if(u test -S $ns/$1) - f=$f^9p -t=/tmp/netget.$pid.$USER -fn sigexit { rm -f $t } +. netfilelib.rc $1 fn putfile{ cat >$t - if(! echo put $t $2 | sftp -b /dev/stdin $1 >/dev/null) + 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 + } } fn putfile9p{ if(! 9p write $1/$2) @@ -25,3 +26,4 @@ fn putfile9p{ $f $1 $2 exit 0 + diff --git a/src/cmd/netfiles/netfilestat b/src/cmd/netfiles/netfilestat index 992cac22..f01c5de6 100755 --- a/src/cmd/netfiles/netfilestat +++ b/src/cmd/netfiles/netfilestat @@ -6,33 +6,27 @@ if(! ~ $#* 2){ } f=dostat -ns=`{namespace} -if(u test -S $ns/$1) - f=$f^9p -t=/tmp/netisdir.$pid.$USER -fn sigexit { rm -f $t } +. netfilelib.rc $1 fn dostat { { - echo !echo XXX connected - echo cd $2 - echo !echo XXX directory exists - } | sftp -b /dev/stdin $1 >$t >[2=1] - if(9 grep -s XXX.directory.exists $t){ + 9 echo -cd $2 + } | mysftp $1 >$t + if(9 test -e $t -a ! -s $t){ echo directory exit 0 } - if(9 grep -s 'is not a directory' $t){ + if(9 grep -s 'Can''t change directory|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 + if(9 grep -s 'Couldn''t stat remote file|such file' $t){ + echo nonexistent exit 0 } - echo nonexistent + cat $t >[1=2] + echo unknown error exit 0 } |