forked from x/icebergs
opt nfs.cat
This commit is contained in:
parent
37ee31219a
commit
1754b933cc
@ -3,6 +3,7 @@ package nfs
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@ -25,13 +26,25 @@ func _cat_right(m *ice.Message, name string) bool {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
func _cat_find(m *ice.Message, name string) io.ReadCloser {
|
||||||
|
if f, e := os.Open(path.Join(m.Option(DIR_ROOT), name)); e == nil {
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
if b, ok := ice.Info.BinPack[name]; ok {
|
||||||
|
m.Logs("binpack", len(b), name)
|
||||||
|
return kit.NewReadCloser(bytes.NewBuffer(b))
|
||||||
|
}
|
||||||
|
|
||||||
|
return kit.NewReadCloser(bytes.NewBufferString(m.Cmdx("web.spide", "dev", "raw", "GET", path.Join("/share/local/", name))))
|
||||||
|
}
|
||||||
func _cat_show(m *ice.Message, name string) {
|
func _cat_show(m *ice.Message, name string) {
|
||||||
if !_cat_right(m, name) {
|
if !_cat_right(m, name) {
|
||||||
return // 没有权限
|
return // 没有权限
|
||||||
}
|
}
|
||||||
|
|
||||||
// 本地文件
|
// 本地文件
|
||||||
if f, e := os.Open(path.Join(m.Option(DIR_ROOT), name)); e == nil {
|
f := _cat_find(m, name)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
switch cb := m.Optionv(kit.Keycb(CAT)).(type) {
|
switch cb := m.Optionv(kit.Keycb(CAT)).(type) {
|
||||||
@ -50,33 +63,18 @@ func _cat_show(m *ice.Message, name string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if s, e := f.Stat(); m.Assert(e) {
|
buf := make([]byte, ice.MOD_BUFS)
|
||||||
buf := make([]byte, s.Size())
|
for begin := 0; true; {
|
||||||
if n, e := f.Read(buf); m.Assert(e) {
|
n, e := f.Read(buf[begin:])
|
||||||
|
m.Warn(e != nil && e != io.EOF, e)
|
||||||
m.Log_IMPORT(kit.MDB_FILE, name, kit.MDB_SIZE, n)
|
m.Log_IMPORT(kit.MDB_FILE, name, kit.MDB_SIZE, n)
|
||||||
m.Echo(string(buf[:n]))
|
if begin += n; begin < len(buf) {
|
||||||
|
buf = buf[:begin]
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
buf = append(buf, make([]byte, ice.MOD_BUFS)...)
|
||||||
}
|
}
|
||||||
}
|
m.Echo(string(buf))
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 打包文件
|
|
||||||
if b, ok := ice.Info.BinPack[name]; ok {
|
|
||||||
m.Logs("binpack", name, kit.MDB_SIZE, len(b))
|
|
||||||
m.Echo(string(b))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 远程文件
|
|
||||||
switch cb := m.Optionv(kit.Keycb(CAT)).(type) {
|
|
||||||
case func(string, int):
|
|
||||||
bio := bufio.NewScanner(bytes.NewBufferString(m.Cmdx("web.spide", "dev", "raw", "GET", path.Join("/share/local/", name))))
|
|
||||||
for i := 0; bio.Scan(); i++ {
|
|
||||||
cb(bio.Text(), i)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
m.Cmdy("web.spide", "dev", "raw", "GET", path.Join("/share/local/", name))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
"shylinux.com/x/icebergs/base/aaa"
|
"shylinux.com/x/icebergs/base/aaa"
|
||||||
"shylinux.com/x/icebergs/base/ctx"
|
"shylinux.com/x/icebergs/base/ctx"
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -55,42 +54,10 @@ func Script(m *ice.Message, name string) io.Reader {
|
|||||||
}
|
}
|
||||||
m.Option(ice.MSG_SCRIPT, name)
|
m.Option(ice.MSG_SCRIPT, name)
|
||||||
|
|
||||||
// 本地文件
|
|
||||||
back := kit.Split(m.Option(nfs.DIR_ROOT))
|
|
||||||
for i := len(back) - 1; i >= 0; i-- {
|
|
||||||
if s, e := os.Open(path.Join(path.Join(back[:i]...), name)); e == nil {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if s, e := os.Open(name); e == nil {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
switch strings.Split(name, "/")[0] {
|
|
||||||
case kit.SSH_ETC, kit.SSH_VAR:
|
|
||||||
m.Warn(true, ice.ErrNotFound)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 打包文件
|
|
||||||
if b, ok := ice.Info.BinPack["/"+name]; ok {
|
|
||||||
m.Info("binpack %v %v", len(b), name)
|
|
||||||
return bytes.NewReader(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 远程文件
|
// 远程文件
|
||||||
if msg := m.Cmd("web.spide", "dev", "GET", path.Join("/share/local/", name)); msg.Result(0) != ice.ErrWarn {
|
if msg := m.Cmd("nfs.cat", name); msg.Result(0) != ice.ErrWarn {
|
||||||
return bytes.NewBuffer([]byte(msg.Result()))
|
return bytes.NewBuffer([]byte(msg.Result()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 源码文件
|
|
||||||
if strings.HasPrefix(name, kit.SSH_USR) {
|
|
||||||
ls := strings.Split(name, "/")
|
|
||||||
m.Cmd("web.code.git.repos", ls[1], path.Join(kit.SSH_USR, ls[1]))
|
|
||||||
if s, e := os.Open(name); e == nil {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
conf.go
1
conf.go
@ -71,6 +71,7 @@ const ( // DIR
|
|||||||
ETC_MISS = "etc/miss.sh"
|
ETC_MISS = "etc/miss.sh"
|
||||||
ETC_MISS_SH = "etc/miss.sh"
|
ETC_MISS_SH = "etc/miss.sh"
|
||||||
|
|
||||||
|
SRC_HELP = "src/help"
|
||||||
SRC_MAIN_SHY = "src/main.shy"
|
SRC_MAIN_SHY = "src/main.shy"
|
||||||
SRC_MAIN_GO = "src/main.go"
|
SRC_MAIN_GO = "src/main.go"
|
||||||
SRC_VERSION = "src/version.go"
|
SRC_VERSION = "src/version.go"
|
||||||
|
@ -40,6 +40,9 @@ func _pack_dir(m *ice.Message, pack *os.File, dir string) {
|
|||||||
m.Option(nfs.DIR_ROOT, dir)
|
m.Option(nfs.DIR_ROOT, dir)
|
||||||
|
|
||||||
m.Cmd(nfs.DIR, "./").Table(func(index int, value map[string]string, head []string) {
|
m.Cmd(nfs.DIR, "./").Table(func(index int, value map[string]string, head []string) {
|
||||||
|
if path.Base(value[kit.MDB_PATH]) == "binpack.go" {
|
||||||
|
return
|
||||||
|
}
|
||||||
switch strings.Split(value[kit.MDB_PATH], "/")[0] {
|
switch strings.Split(value[kit.MDB_PATH], "/")[0] {
|
||||||
case "pluged", "trash":
|
case "pluged", "trash":
|
||||||
return
|
return
|
||||||
@ -67,7 +70,8 @@ func _pack_volcanos(m *ice.Message, pack *os.File, dir string) {
|
|||||||
}
|
}
|
||||||
pack.WriteString(ice.NL)
|
pack.WriteString(ice.NL)
|
||||||
}
|
}
|
||||||
func _pack_contexts(m *ice.Message, pack *os.File) {
|
func _pack_ctx(m *ice.Message, pack *os.File) {
|
||||||
|
_pack_dir(m, pack, ice.SRC_HELP)
|
||||||
_pack_dir(m, pack, "src")
|
_pack_dir(m, pack, "src")
|
||||||
pack.WriteString(ice.NL)
|
pack.WriteString(ice.NL)
|
||||||
}
|
}
|
||||||
@ -96,7 +100,7 @@ func init() {
|
|||||||
// _pack_dir(m, pack, ice.USR_ICEBERGS)
|
// _pack_dir(m, pack, ice.USR_ICEBERGS)
|
||||||
// _pack_dir(m, pack, ice.USR_TOOLKITS)
|
// _pack_dir(m, pack, ice.USR_TOOLKITS)
|
||||||
_pack_dir(m, pack, ice.USR_INTSHELL)
|
_pack_dir(m, pack, ice.USR_INTSHELL)
|
||||||
// _pack_contexts(m, pack)
|
_pack_ctx(m, pack)
|
||||||
|
|
||||||
_pack_write(pack, ` }`)
|
_pack_write(pack, ` }`)
|
||||||
_pack_write(pack, `}`)
|
_pack_write(pack, `}`)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user