mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
new
This commit is contained in:
parent
e961291897
commit
b8c9f31785
6 changed files with 60 additions and 32 deletions
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ XTARG=\
|
|||
netfileget\
|
||||
netfileput\
|
||||
netfilestat\
|
||||
netfilelib.rc\
|
||||
|
||||
install:V:
|
||||
for i in $XTARG; do
|
||||
|
|
|
@ -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}'
|
||||
}
|
||||
|
|
21
src/cmd/netfiles/netfilelib.rc
Normal file
21
src/cmd/netfiles/netfilelib.rc
Normal file
|
@ -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 }
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue