From b131e6c61acae4749a6045dda8da9df6c5fdc450 Mon Sep 17 00:00:00 2001 From: shylinux Date: Thu, 13 Jul 2023 15:01:40 +0800 Subject: [PATCH] opt some --- base/nfs/dir.go | 21 ++++++++++++++++----- base/tcp/server.go | 5 +++-- base/web/web.go | 8 +++++++- conf.go | 1 + core/code/binpack.go | 6 +++--- misc/git/repos.go | 4 ++-- misc/git/total.go | 2 +- render.go | 7 ++----- 8 files changed, 35 insertions(+), 19 deletions(-) diff --git a/base/nfs/dir.go b/base/nfs/dir.go index 7eb67d9c..fa6d77df 100644 --- a/base/nfs/dir.go +++ b/base/nfs/dir.go @@ -5,6 +5,7 @@ import ( "path" "regexp" "strings" + "time" ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/aaa" @@ -22,7 +23,7 @@ func _dir_hash(m *ice.Message, p string) (h string) { kit.If(len(list) > 0, func() { h = kit.Hashs(list) }) return "" } -func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, dir_type string, dir_reg *regexp.Regexp, fields []string) *ice.Message { +func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, dir_type string, dir_reg *regexp.Regexp, fields []string) (total int64, last time.Time) { ls, _ := ReadDir(m, path.Join(root, dir)) if len(ls) == 0 { if s, e := StatFile(m, path.Join(root, dir)); e == nil && !s.IsDir() { @@ -49,6 +50,9 @@ func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, di default: m.ErrorNotImplement(cb) } + if s.ModTime().After(last) { + last = s.ModTime() + } for _, field := range fields { switch field { case mdb.TIME: @@ -74,6 +78,7 @@ func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, di m.Push(field, _dir_size(m, p)) } else { m.Push(field, kit.FmtSize(s.Size())) + total += s.Size() } case LINE: if isDir { @@ -121,10 +126,13 @@ func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, di case "pluged": continue } - _dir_list(m, root, pp, level+1, deep, dir_type, dir_reg, fields) + _total, _last := _dir_list(m, root, pp, level+1, deep, dir_type, dir_reg, fields) + if total += _total; _last.After(last) { + last = _last + } } } - return m + return } const ( @@ -171,7 +179,9 @@ func init() { }}, mdb.UPLOAD: {}, "finder": {Help: "本机", Hand: func(m *ice.Message, arg ...string) { m.Cmd("cli.system", "opens", "Finder.app") }}, TRASH: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(TRASH, mdb.CREATE, m.Option(PATH)) }}, - mdb.SHOW: {Hand: func(m *ice.Message, arg ...string) { Show(m.ProcessInner(), m.Option(PATH)) }}, + mdb.SHOW: {Hand: func(m *ice.Message, arg ...string) { + Show(m.ProcessInner(), path.Join(m.Option(DIR_ROOT), m.Option(PATH))) + }}, }, Hand: func(m *ice.Message, arg ...string) { root, dir := kit.Select(PWD, m.Option(DIR_ROOT)), kit.Select(PWD, arg, 0) kit.If(strings.HasPrefix(dir, PS), func() { root = "" }) @@ -180,7 +190,8 @@ func init() { } m.Logs(FIND, DIR_ROOT, root, PATH, dir, DIR_TYPE, m.Option(DIR_TYPE)) fields := kit.Split(kit.Select(kit.Select(DIR_DEF_FIELDS, m.OptionFields()), kit.Join(kit.Slice(arg, 1)))) - _dir_list(m, root, dir, 0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), regexp.MustCompile(m.Option(DIR_REG)), fields).StatusTimeCount() + size, last := _dir_list(m, root, dir, 0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), regexp.MustCompile(m.Option(DIR_REG)), fields) + m.Status(mdb.TIME, last, mdb.COUNT, kit.Split(m.FormatSize())[0], SIZE, kit.FmtSize(size), kit.MDB_COST, m.FormatCost()) }}, }) } diff --git a/base/tcp/server.go b/base/tcp/server.go index 53a2d53a..c0dc2bd1 100644 --- a/base/tcp/server.go +++ b/base/tcp/server.go @@ -30,14 +30,15 @@ func (l Listener) Close() error { func _server_listen(m *ice.Message, arg ...string) { l, e := net.Listen(TCP, m.Option(HOST)+nfs.DF+m.Option(PORT)) + if m.Warn(e) { + return + } l = &Listener{Listener: l, m: m, h: mdb.HashCreate(m, arg, kit.Dict(mdb.TARGET, l), STATUS, kit.Select(ERROR, OPEN, e == nil), ERROR, kit.Format(e)), s: &Stat{}} defer kit.If(e == nil, func() { l.Close() }) switch cb := m.OptionCB("").(type) { case func(net.Listener): - m.Assert(e) cb(l) case func(net.Conn): - m.Assert(e) for { if c, e := l.Accept(); !m.Warn(e) { cb(c) diff --git a/base/web/web.go b/base/web/web.go index 272aac62..8c0019c0 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -1,6 +1,7 @@ package web import ( + "fmt" "net" "net/http" "path" @@ -57,11 +58,16 @@ func (f *Frame) Start(m *ice.Message, arg ...string) { case func(http.Handler): cb(f) default: - m.Cmd(tcp.SERVER, tcp.LISTEN, mdb.TYPE, HTTP, mdb.NAME, logs.FileLine(1), m.OptionSimple(tcp.HOST, tcp.PORT), func(l net.Listener) { + m.Cmdy(tcp.SERVER, tcp.LISTEN, mdb.TYPE, HTTP, mdb.NAME, logs.FileLine(1), m.OptionSimple(tcp.HOST, tcp.PORT), func(l net.Listener) { defer mdb.HashCreateDeferRemove(m, m.OptionSimple(mdb.NAME, tcp.PROTO), arg, cli.STATUS, tcp.START)() gdb.Event(m, SERVE_START, arg) m.Warn(f.Server.Serve(l)) }) + if m.IsErr() { + fmt.Println() + fmt.Println(m.Result()) + m.Cmd(ice.QUIT) + } } } func (f *Frame) Close(m *ice.Message, arg ...string) {} diff --git a/conf.go b/conf.go index d88723c6..7015a6ab 100644 --- a/conf.go +++ b/conf.go @@ -118,6 +118,7 @@ const ( // DIR USR_VOLCANOS = "usr/volcanos/" USR_LEARNING = "usr/learning/" USR_PORTAL = "usr/portal/" + USR_ICONS = "usr/icons/" USR_LOCAL = "usr/local/" USR_LOCAL_GO = "usr/local/go/" diff --git a/core/code/binpack.go b/core/code/binpack.go index dab0e07c..c9175335 100644 --- a/core/code/binpack.go +++ b/core/code/binpack.go @@ -75,7 +75,7 @@ func _binpack_all(m *ice.Message) { } for _, k := range kit.SortedKey(list) { v := kit.Select(k, list[k]) - m.Cmd(nfs.DIR, nfs.PWD, nfs.PATH, kit.Dict(nfs.DIR_ROOT, v, nfs.DIR_REG, kit.ExtReg(SH, SHY, PY, JS, CSS, HTML))).Table(func(value ice.Maps) { + m.Cmd(nfs.DIR, nfs.PWD, nfs.PATH, kit.Dict(nfs.DIR_ROOT, v, nfs.DIR_REG, kit.ExtReg(kit.Split(mdb.Config(m, "extreg"))...))).Table(func(value ice.Maps) { if ice.Info.Make.Remote != "https://shylinux.com/x/contexts" && kit.HasPrefix(k, ice.USR_ICEBERGS) { return } @@ -90,7 +90,7 @@ func _binpack_all(m *ice.Message) { } }) m.Option(nfs.DIR_REG, kit.ExtReg(nfs.SHY)) - if ice.Info.Make.Remote == "shylinux.com/x/contexts" { + if ice.Info.Make.Remote == "https://shylinux.com/x/contexts" { _binpack_dir(m, w, "usr/release/") } } @@ -103,7 +103,7 @@ func init() { BINPACK: {Name: "binpack path auto create insert", Help: "打包", Actions: ice.MergeActions(ice.Actions{ mdb.CREATE: {Hand: func(m *ice.Message, arg ...string) { _binpack_all(m) }}, mdb.INSERT: {Name: "insert path*", Hand: func(m *ice.Message, arg ...string) { mdb.HashCreate(m, m.OptionSimple(nfs.PATH)) }}, - }, mdb.HashAction(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path"))}, + }, mdb.HashAction(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path", "extreg", "sh,shy,py,js,css,html,png,jpg"))}, }) } func GoCache(m *ice.Message) string { diff --git a/misc/git/repos.go b/misc/git/repos.go index c9def359..1efd9bf5 100644 --- a/misc/git/repos.go +++ b/misc/git/repos.go @@ -484,7 +484,7 @@ func init() { } }}, STASH: {Hand: func(m *ice.Message, arg ...string) { _repos_cmd(m, kit.Select(m.Option(REPOS), arg, 0), STASH) }}, - COMMIT: {Name: "commit actions=add,opt,fix comment*=some", Help: "提交", Hand: func(m *ice.Message, arg ...string) { + COMMIT: {Name: "commit actions=add,fix,opt message*=some", Help: "提交", Hand: func(m *ice.Message, arg ...string) { if work, err := _repos_open(m, m.Option(REPOS)).Worktree(); !m.Warn(err) { opt := &git.CommitOptions{All: true} if cfg, err := config.LoadConfig(config.GlobalScope); err == nil { @@ -496,7 +496,7 @@ func init() { } } } - _, err := work.Commit(m.Option("actions")+lex.SP+m.Option("comment"), opt) + _, err := work.Commit(m.Option("actions")+lex.SP+m.Option("message"), opt) m.Warn(err) } }}, diff --git a/misc/git/total.go b/misc/git/total.go index cf5a1a0c..f4a11e3e 100644 --- a/misc/git/total.go +++ b/misc/git/total.go @@ -38,7 +38,7 @@ func init() { }) }) }}, - }, ctx.ConfAction("skip", kit.DictList("go-git", "go-qrcode", "websocket"))), Hand: func(m *ice.Message, arg ...string) { + }, ctx.ConfAction("skip", kit.DictList("go-git", "go-qrcode", "websocket", "webview", "word-dict"))), Hand: func(m *ice.Message, arg ...string) { if len(arg) > 0 { ReposList(m).Table(func(value ice.Maps) { kit.If(value[REPOS] == arg[0], func() { m.Cmdy("_sum", value[nfs.PATH], arg[1:]) }) diff --git a/render.go b/render.go index 4713ad70..31faada9 100644 --- a/render.go +++ b/render.go @@ -220,12 +220,9 @@ func (m *Message) resource(file string) string { return file } p := strings.TrimPrefix(kit.FileLines(3), Info.Make.Path) - p = strings.TrimPrefix(p, kit.Path("")+PS) - if strings.Contains(p, "/pkg/mod/") { + if p = strings.TrimPrefix(p, kit.Path("")+PS); strings.Contains(p, "/pkg/mod/") { p = strings.Split(p, "/pkg/mod/")[1] } - if file != "" { - p = path.Join(path.Dir(p), file) - } + kit.If(file != "", func() { p = path.Join(path.Dir(p), file) }) return "/require/" + p }