mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-28 13:31:27 +08:00
use util to generate md5.
This commit is contained in:
parent
6a5b38c0d4
commit
72f9d7f047
@ -2,7 +2,6 @@ package elastic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/md5"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
@ -108,9 +107,9 @@ func (store *ElasticStore) ListDirectoryPrefixedEntries(ctx context.Context, ful
|
|||||||
func (store *ElasticStore) InsertEntry(ctx context.Context, entry *filer.Entry) (err error) {
|
func (store *ElasticStore) InsertEntry(ctx context.Context, entry *filer.Entry) (err error) {
|
||||||
index := getIndex(entry.FullPath)
|
index := getIndex(entry.FullPath)
|
||||||
dir, _ := entry.FullPath.DirAndName()
|
dir, _ := entry.FullPath.DirAndName()
|
||||||
id := fmt.Sprintf("%x", md5.Sum([]byte(entry.FullPath)))
|
id := weed_util.Md5String([]byte(entry.FullPath))
|
||||||
esEntry := &ESEntry{
|
esEntry := &ESEntry{
|
||||||
ParentId: fmt.Sprintf("%x", md5.Sum([]byte(dir))),
|
ParentId: weed_util.Md5String([]byte(dir)),
|
||||||
Entry: entry,
|
Entry: entry,
|
||||||
}
|
}
|
||||||
value, err := jsoniter.Marshal(esEntry)
|
value, err := jsoniter.Marshal(esEntry)
|
||||||
@ -137,7 +136,7 @@ func (store *ElasticStore) UpdateEntry(ctx context.Context, entry *filer.Entry)
|
|||||||
|
|
||||||
func (store *ElasticStore) FindEntry(ctx context.Context, fullpath weed_util.FullPath) (entry *filer.Entry, err error) {
|
func (store *ElasticStore) FindEntry(ctx context.Context, fullpath weed_util.FullPath) (entry *filer.Entry, err error) {
|
||||||
index := getIndex(fullpath)
|
index := getIndex(fullpath)
|
||||||
id := fmt.Sprintf("%x", md5.Sum([]byte(fullpath)))
|
id := weed_util.Md5String([]byte(fullpath))
|
||||||
searchResult, err := store.client.Get().
|
searchResult, err := store.client.Get().
|
||||||
Index(index).
|
Index(index).
|
||||||
Type(indexType).
|
Type(indexType).
|
||||||
@ -160,7 +159,7 @@ func (store *ElasticStore) FindEntry(ctx context.Context, fullpath weed_util.Ful
|
|||||||
|
|
||||||
func (store *ElasticStore) DeleteEntry(ctx context.Context, fullpath weed_util.FullPath) (err error) {
|
func (store *ElasticStore) DeleteEntry(ctx context.Context, fullpath weed_util.FullPath) (err error) {
|
||||||
index := getIndex(fullpath)
|
index := getIndex(fullpath)
|
||||||
id := fmt.Sprintf("%x", md5.Sum([]byte(fullpath)))
|
id := weed_util.Md5String([]byte(fullpath))
|
||||||
if strings.Count(string(fullpath), "/") == 1 {
|
if strings.Count(string(fullpath), "/") == 1 {
|
||||||
return store.deleteIndex(ctx, index)
|
return store.deleteIndex(ctx, index)
|
||||||
}
|
}
|
||||||
@ -243,7 +242,7 @@ func (store *ElasticStore) listDirectoryEntries(
|
|||||||
first := true
|
first := true
|
||||||
index := getIndex(fullpath)
|
index := getIndex(fullpath)
|
||||||
nextStart := ""
|
nextStart := ""
|
||||||
parentId := fmt.Sprintf("%x", md5.Sum([]byte(fullpath)))
|
parentId := weed_util.Md5String([]byte(fullpath))
|
||||||
if _, err := store.client.Refresh(index).Do(ctx); err != nil {
|
if _, err := store.client.Refresh(index).Do(ctx); err != nil {
|
||||||
if elastic.IsNotFound(err) {
|
if elastic.IsNotFound(err) {
|
||||||
store.client.CreateIndex(index).Do(ctx)
|
store.client.CreateIndex(index).Do(ctx)
|
||||||
@ -262,7 +261,7 @@ func (store *ElasticStore) listDirectoryEntries(
|
|||||||
if !first {
|
if !first {
|
||||||
fullPath = nextStart
|
fullPath = nextStart
|
||||||
}
|
}
|
||||||
after := fmt.Sprintf("%x", md5.Sum([]byte(fullPath)))
|
after := weed_util.Md5String([]byte(fullPath))
|
||||||
if result, err = store.searchAfter(ctx, index, parentId, after); err != nil {
|
if result, err = store.searchAfter(ctx, index, parentId, after); err != nil {
|
||||||
glog.Errorf("searchAfter (%s,%s,%t,%d) %v.", string(fullpath), startFileName, inclusive, limit, err)
|
glog.Errorf("searchAfter (%s,%s,%t,%d) %v.", string(fullpath), startFileName, inclusive, limit, err)
|
||||||
return entries, err
|
return entries, err
|
||||||
|
Loading…
Reference in New Issue
Block a user