mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-09 19:30:30 +08:00
初步实验使用KV数据库(pebble)存储缓存索引
This commit is contained in:
50
internal/utils/kvstore/utils.go
Normal file
50
internal/utils/kvstore/utils.go
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package kvstore
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var nameRegexp = regexp.MustCompile(`^[a-zA-Z0-9_.-]+$`)
|
||||
|
||||
// IsValidName check if store name or database name or table name is valid
|
||||
func IsValidName(name string) bool {
|
||||
return nameRegexp.MatchString(name)
|
||||
}
|
||||
|
||||
// RemoveStore remove store directory
|
||||
func RemoveStore(path string) error {
|
||||
var errNotStoreDirectory = errors.New("not store directory")
|
||||
|
||||
if strings.HasSuffix(path, StoreSuffix) {
|
||||
_, err := os.Stat(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// validate store
|
||||
{
|
||||
_, err = os.Stat(path + "/CURRENT")
|
||||
if err != nil {
|
||||
return errNotStoreDirectory
|
||||
}
|
||||
}
|
||||
{
|
||||
_, err = os.Stat(path + "/LOCK")
|
||||
if err != nil {
|
||||
return errNotStoreDirectory
|
||||
}
|
||||
}
|
||||
|
||||
return os.RemoveAll(path)
|
||||
}
|
||||
|
||||
return errNotStoreDirectory
|
||||
}
|
||||
Reference in New Issue
Block a user