forked from x/icebergs
add nfs.trash
This commit is contained in:
parent
aa2f7b0e00
commit
6fa699411e
@ -1,8 +1,8 @@
|
|||||||
package nfs
|
package nfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
|
|
||||||
"bufio"
|
"bufio"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
@ -139,7 +139,9 @@ func dir(m *ice.Message, root string, name string, level int, deep bool, dir_typ
|
|||||||
|
|
||||||
var Index = &ice.Context{Name: "nfs", Help: "存储模块",
|
var Index = &ice.Context{Name: "nfs", Help: "存储模块",
|
||||||
Caches: map[string]*ice.Cache{},
|
Caches: map[string]*ice.Cache{},
|
||||||
Configs: map[string]*ice.Config{},
|
Configs: map[string]*ice.Config{
|
||||||
|
"trash": {Name: "trash", Help: "trash", Value: kit.Data("path", "var/trash")},
|
||||||
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
"dir": {Name: "dir", Help: "目录", List: kit.List(
|
"dir": {Name: "dir", Help: "目录", List: kit.List(
|
||||||
kit.MDB_INPUT, "text", "name", "path", "action", "auto",
|
kit.MDB_INPUT, "text", "name", "path", "action", "auto",
|
||||||
@ -161,7 +163,7 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
|
|||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
|
|
||||||
"save": {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"save": {Name: "save path text...", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if f, p, e := kit.Create(arg[0]); m.Assert(e) {
|
if f, p, e := kit.Create(arg[0]); m.Assert(e) {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
for _, v := range arg[1:] {
|
for _, v := range arg[1:] {
|
||||||
@ -172,17 +174,7 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
"echo": {Name: "echo path text", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"copy": {Name: "copy path file...", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if f, e := os.OpenFile(arg[0], os.O_WRONLY, 0777); m.Assert(e) {
|
|
||||||
defer f.Close()
|
|
||||||
for _, v := range arg[1:] {
|
|
||||||
if n, e := f.WriteString(v); m.Assert(e) {
|
|
||||||
m.Log(ice.LOG_EXPORT, "%d: %s", n, arg[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}},
|
|
||||||
"copy": {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
if f, _, e := kit.Create(arg[0]); m.Assert(e) {
|
if f, _, e := kit.Create(arg[0]); m.Assert(e) {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
for _, v := range arg[1:] {
|
for _, v := range arg[1:] {
|
||||||
@ -194,6 +186,27 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
|
|
||||||
|
"trash": {Name: "trash file", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
if s, e := os.Stat(arg[0]); e == nil {
|
||||||
|
if s.IsDir() {
|
||||||
|
name := path.Base(arg[0]) + ".tar.gz"
|
||||||
|
m.Cmd(ice.CLI_SYSTEM, "tar", "zcf", name, arg[0])
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
|
||||||
|
if f, e := os.Open(arg[0]); m.Assert(e) {
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
h := kit.Hashs(f)
|
||||||
|
p := path.Join(m.Conf("trash", "meta.path"), h[:2], h)
|
||||||
|
os.MkdirAll(path.Dir(p), 0777)
|
||||||
|
os.Rename(arg[0], p)
|
||||||
|
|
||||||
|
m.Cmd(ice.WEB_FAVOR, "trash", "bin", arg[0], p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ var Index = &ice.Context{Name: "git", Help: "代码库",
|
|||||||
"config", kit.Dict(
|
"config", kit.Dict(
|
||||||
"alias", kit.Dict("s", "status", "b", "branch"),
|
"alias", kit.Dict("s", "status", "b", "branch"),
|
||||||
"color", kit.Dict("ui", "true"),
|
"color", kit.Dict("ui", "true"),
|
||||||
|
"push", kit.Dict("default", "simple"),
|
||||||
|
"credential", kit.Dict("helper", "store"),
|
||||||
),
|
),
|
||||||
)},
|
)},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user