提交 2fe9c7a1 编写于 作者: D Davies Liu

verify volume name

上级 da163c17
......@@ -23,6 +23,7 @@ import (
_ "net/http/pprof"
"os"
"path"
"regexp"
"runtime"
"strings"
"time"
......@@ -130,7 +131,7 @@ func format(c *cli.Context) error {
addr = "redis://" + addr
}
logger.Infof("Meta address: %s", addr)
var rc = meta.RedisConfig{Retries: 10}
var rc = meta.RedisConfig{Retries: 2}
m, err := meta.NewRedisMeta(addr, &rc)
if err != nil {
logger.Fatalf("Meta is not available: %s", err)
......@@ -139,13 +140,18 @@ func format(c *cli.Context) error {
if c.Args().Len() < 2 {
logger.Fatalf("Please give it a name")
}
name := c.Args().Get(1)
validName := regexp.MustCompile(`^[a-z0-9][a-z0-9\-]{1,61}[a-z0-9]$`)
if !validName.MatchString(name) {
logger.Fatalf("invalid name: %s, only alphabet, number and - are allowed.", name)
}
compressor := compress.NewCompressor(c.String("compress"))
if compressor == nil {
logger.Fatalf("Unsupported compress algorithm: %s", c.String("compress"))
}
format := meta.Format{
Name: c.Args().Get(1),
Name: name,
UUID: uuid.New().String(),
Storage: c.String("storage"),
Bucket: c.String("bucket"),
......
......@@ -134,7 +134,7 @@ func NewRedisMeta(url string, conf *RedisConfig) (Meta, error) {
m.shaLookup, err = m.rdb.ScriptLoad(Background, scriptLookup).Result()
if err != nil {
logger.Infof("Failed to load scriptLookup: %v", err)
logger.Warnf("load scriptLookup: %v", err)
m.shaLookup = ""
}
......@@ -188,21 +188,16 @@ func (r *redisMeta) Init(format Format, force bool) error {
// root inode
var attr Attr
attr.Flags = 0
attr.Typ = TypeDirectory
attr.Mode = 0777
attr.Uid = 0
attr.Uid = 0
ts := time.Now().Unix()
attr.Atime = ts
attr.Mtime = ts
attr.Ctime = ts
attr.Nlink = 2
attr.Length = 4 << 10
attr.Rdev = 0
attr.Parent = 1
r.rdb.Set(Background, r.inodeKey(1), r.marshal(&attr), 0)
return nil
return r.rdb.Set(Background, r.inodeKey(1), r.marshal(&attr), 0).Err()
}
func (r *redisMeta) Load() (*Format, error) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册