forked from x/ContextOS
vps mod nfs 回复格式
This commit is contained in:
parent
4745e5b1e2
commit
347dbd5de1
@ -1,7 +1,6 @@
|
||||
package ctx // {{{
|
||||
// }}}
|
||||
import ( // {{{
|
||||
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
|
@ -19,7 +19,7 @@ type NFS struct {
|
||||
io io.ReadWriteCloser
|
||||
*bufio.Reader
|
||||
*bufio.Writer
|
||||
send map[string]*ctx.Message
|
||||
send map[int]*ctx.Message
|
||||
|
||||
in *os.File
|
||||
out *os.File
|
||||
@ -86,16 +86,34 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
||||
nfs.io = socket.(io.ReadWriteCloser)
|
||||
nfs.Reader = bufio.NewReader(nfs.io)
|
||||
nfs.Writer = bufio.NewWriter(nfs.io)
|
||||
nfs.send = make(map[string]*ctx.Message)
|
||||
nfs.send = make(map[int]*ctx.Message)
|
||||
|
||||
target, msg := m.Target(), m.Spawn(m.Target())
|
||||
nfs.Caches["target"] = &ctx.Cache{Name: "target", Value: target.Name, Help: "文件名"}
|
||||
|
||||
nsend := 0
|
||||
for {
|
||||
line, e := nfs.Reader.ReadString('\n')
|
||||
m.Assert(e)
|
||||
|
||||
if line = strings.TrimSpace(line); len(line) == 0 {
|
||||
if line = strings.TrimSpace(line); len(line) > 0 {
|
||||
ls := strings.SplitN(line, ":", 2)
|
||||
ls[0] = strings.TrimSpace(ls[0])
|
||||
ls[1], e = url.QueryUnescape(strings.TrimSpace(ls[1]))
|
||||
m.Assert(e)
|
||||
|
||||
switch ls[0] {
|
||||
case "nsend":
|
||||
n, e := strconv.Atoi(ls[1])
|
||||
m.Assert(e)
|
||||
nsend = n
|
||||
|
||||
default:
|
||||
msg.Add("option", ls[0], ls[1])
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if msg.Log("info", nil, "remote: %v", msg.Meta["option"]); msg.Has("detail") {
|
||||
msg.Log("info", nil, "%d exec: %v", m.Capi("nrecv", 1), msg.Meta["detail"])
|
||||
|
||||
@ -124,11 +142,12 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
||||
}
|
||||
}
|
||||
} else {
|
||||
msg.Log("info", nil, "%s echo: %v", msg.Get("nsend"), msg.Meta["result"])
|
||||
msg.Log("info", nil, "%d echo: %v", nsend, msg.Meta["result"])
|
||||
|
||||
m.Cap("result", msg.Get("result"))
|
||||
msg.Meta["append"] = msg.Meta["option"]
|
||||
send := nfs.send[msg.Get("nsend")]
|
||||
delete(msg.Meta, "option")
|
||||
send := nfs.send[nsend]
|
||||
send.Meta = msg.Meta
|
||||
|
||||
if send.Has("io") {
|
||||
@ -140,17 +159,9 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
||||
|
||||
send.Recv <- true
|
||||
}
|
||||
|
||||
msg = m.Spawn(target)
|
||||
m.Cap("target", target.Name)
|
||||
continue
|
||||
}
|
||||
|
||||
ls := strings.SplitN(line, ":", 2)
|
||||
ls[0] = strings.TrimSpace(ls[0])
|
||||
ls[1], e = url.QueryUnescape(strings.TrimSpace(ls[1]))
|
||||
m.Assert(e)
|
||||
msg.Add("option", ls[0], ls[1])
|
||||
|
||||
}
|
||||
return true
|
||||
}
|
||||
@ -319,7 +330,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
}
|
||||
|
||||
} else {
|
||||
nfs.send[m.Option("nrecv", m.Capi("nsend", 1))] = m
|
||||
nfs.send[m.Optioni("nrecv", m.Capi("nsend", 1))] = m
|
||||
|
||||
if len(arg) > 1 && arg[0] == "file" {
|
||||
info, e := os.Stat(arg[1])
|
||||
@ -352,8 +363,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
f, e := os.Open(arg[1])
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
n, e := io.Copy(nfs.Writer, f)
|
||||
m.Log("fuck", nil, "write %d %v", n, e)
|
||||
_, e = io.Copy(nfs.Writer, f)
|
||||
}
|
||||
}
|
||||
|
||||
@ -375,7 +385,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
return
|
||||
}
|
||||
|
||||
nfs.send[m.Option("nrecv", m.Capi("nsend", 1))] = m
|
||||
nfs.send[m.Optioni("nrecv", m.Capi("nsend", 1))] = m
|
||||
|
||||
if len(arg) > 1 && arg[0] == "file" {
|
||||
f, e := os.Create(arg[1])
|
||||
|
@ -33,7 +33,14 @@ type WEB struct {
|
||||
}
|
||||
|
||||
func (web *WEB) AppendJson(msg *ctx.Message) string { // {{{
|
||||
b, e := json.Marshal(msg.Meta)
|
||||
meta := map[string][]string{}
|
||||
meta["result"] = msg.Meta["result"]
|
||||
meta["append"] = msg.Meta["append"]
|
||||
for _, v := range msg.Meta["append"] {
|
||||
meta[v] = msg.Meta[v]
|
||||
}
|
||||
|
||||
b, e := json.Marshal(meta)
|
||||
msg.Assert(e)
|
||||
return string(b)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user