1
0
forked from x/icebergs
This commit is contained in:
shaoying 2020-07-20 10:26:25 +08:00
parent ccf3839fd0
commit 231fd0d857
2 changed files with 18 additions and 21 deletions

View File

@ -106,23 +106,24 @@ func _cache_download(m *ice.Message, r *http.Response) (file, size string) {
total := kit.Int(kit.Select("1", r.Header.Get("Content-Length"))) total := kit.Int(kit.Select("1", r.Header.Get("Content-Length")))
if f, p, e := kit.Create(path.Join("var/tmp", kit.Hashs("uniq"))); m.Assert(e) { if f, p, e := kit.Create(path.Join("var/tmp", kit.Hashs("uniq"))); m.Assert(e) {
size, buf := 0, make([]byte, 81920) size, buf := 0, make([]byte, 1024)
for { for {
if n, e := r.Body.Read(buf); e == nil { if n, _ := r.Body.Read(buf); n > 0 {
f.Write(buf[0:n]) f.Write(buf[0:n])
size += n size += n
m.Log_IMPORT(kit.MDB_FILE, p, "per", size*100/total, kit.MDB_SIZE, kit.FmtSize(int64(size)), "total", kit.FmtSize(int64(total))) m.Log_IMPORT(kit.MDB_FILE, p, "per", size*100/total, kit.MDB_SIZE, kit.FmtSize(int64(size)), "total", kit.FmtSize(int64(total)))
} else if e == io.EOF {
f.Close()
break
} else { } else {
f.Close()
break break
} }
} }
m.Log_IMPORT(kit.MDB_FILE, p, kit.MDB_SIZE, kit.FmtSize(int64(size))) if f, e := os.Open(p); m.Assert(e) {
c := _cache_name(m, kit.Hashs(f)) defer f.Close()
m.Cmd(nfs.LINK, c, p) m.Log_IMPORT(kit.MDB_FILE, p, kit.MDB_SIZE, kit.FmtSize(int64(size)))
return c, kit.Format(size) c := _cache_name(m, kit.Hashs(f))
m.Cmd(nfs.LINK, c, p)
return c, kit.Format(size)
}
} }
return "", "0" return "", "0"
} }

View File

@ -25,12 +25,11 @@ const ( // CODE
var Index = &ice.Context{Name: "code", Help: "编程中心", var Index = &ice.Context{Name: "code", Help: "编程中心",
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{
INSTALL: {Name: "install", Help: "安装", Value: kit.Data("path", "usr/install", INSTALL: {Name: "install", Help: "安装", Value: kit.Data(
"path", "usr/install", "target", "usr/local",
"linux", "https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz", "linux", "https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz",
"darwin", "https://dl.google.com/go/go1.14.2.darwin-amd64.pkg", "darwin", "https://dl.google.com/go/go1.14.6.darwin-amd64.tar.gz",
"windows", "https://dl.google.com/go/go1.14.2.windows-amd64.msi", "windows", "https://golang.google.cn/dl/go1.14.6.windows-amd64.zip",
"source", "https://dl.google.com/go/go1.14.2.src.tar.gz",
"target", "usr/local",
)}, )},
PREPARE: {Name: "prepare", Help: "配置", Value: kit.Data("path", "usr/prepare", PREPARE: {Name: "prepare", Help: "配置", Value: kit.Data("path", "usr/prepare",
"script", ".ish/pluged/golang/init.sh", "export", kit.Dict( "script", ".ish/pluged/golang/init.sh", "export", kit.Dict(
@ -51,20 +50,17 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
m.Save("login") m.Save("login")
}}, }},
INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { INSTALL: {Name: "install url 安装:button", Help: "安装", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
target := m.Conf(INSTALL, kit.Keys("meta", runtime.GOOS)) target := m.Conf(INSTALL, kit.Keys("meta", runtime.GOOS))
p := path.Join(m.Conf(INSTALL, "meta.path"), path.Base(target))
p := path.Join(m.Conf(INSTALL, "meta.path"), path.Base(target))
if _, e := os.Stat(p); e != nil { if _, e := os.Stat(p); e != nil {
// 下载 // 下载
m.Option(cli.CMD_DIR, m.Conf(INSTALL, "meta.path")) msg := m.Cmd(web.SPIDE, "dev", web.CACHE, http.MethodGet, target)
msg := m.Cmd(web.SPIDE, web.CACHE, http.MethodGet, target)
m.Cmd(web.CACHE, web.WATCH, msg.Append(web.DATA), p) m.Cmd(web.CACHE, web.WATCH, msg.Append(web.DATA), p)
} }
// 安装 os.MkdirAll(m.Conf(INSTALL, kit.Keys("meta.target")), ice.MOD_DIR)
m.Option(cli.CMD_DIR, "")
os.MkdirAll(m.Conf(INSTALL, kit.Keys("meta.target")), 0777)
m.Cmdy(cli.SYSTEM, "tar", "xvf", p, "-C", m.Conf(INSTALL, kit.Keys("meta.target"))) m.Cmdy(cli.SYSTEM, "tar", "xvf", p, "-C", m.Conf(INSTALL, kit.Keys("meta.target")))
}}, }},
PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {