mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactoring variable names
This commit is contained in:
parent
828e4a5ace
commit
c1e353491a
|
@ -24,21 +24,21 @@ type LevelDBStore struct {
|
||||||
db *leveldb.DB
|
db *leveldb.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (filer *LevelDBStore) GetName() string {
|
func (store *LevelDBStore) GetName() string {
|
||||||
return "leveldb"
|
return "leveldb"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (filer *LevelDBStore) Initialize(viper *viper.Viper) (err error) {
|
func (store *LevelDBStore) Initialize(viper *viper.Viper) (err error) {
|
||||||
dir := viper.GetString("dir")
|
dir := viper.GetString("dir")
|
||||||
return filer.initialize(dir)
|
return store.initialize(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (filer *LevelDBStore) initialize(dir string) (err error) {
|
func (store *LevelDBStore) initialize(dir string) (err error) {
|
||||||
if err := weed_util.TestFolderWritable(dir); err != nil {
|
if err := weed_util.TestFolderWritable(dir); err != nil {
|
||||||
return fmt.Errorf("Check Level Folder %s Writable: %s", dir, err)
|
return fmt.Errorf("Check Level Folder %s Writable: %s", dir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if filer.db, err = leveldb.OpenFile(dir, nil); err != nil {
|
if store.db, err = leveldb.OpenFile(dir, nil); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
|
@ -17,70 +17,70 @@ type MemDbStore struct {
|
||||||
tree *btree.BTree
|
tree *btree.BTree
|
||||||
}
|
}
|
||||||
|
|
||||||
type Entry struct {
|
type entryItem struct {
|
||||||
*filer2.Entry
|
*filer2.Entry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Entry) Less(b btree.Item) bool {
|
func (a entryItem) Less(b btree.Item) bool {
|
||||||
return strings.Compare(string(a.FullPath), string(b.(Entry).FullPath)) < 0
|
return strings.Compare(string(a.FullPath), string(b.(entryItem).FullPath)) < 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (filer *MemDbStore) GetName() string {
|
func (store *MemDbStore) GetName() string {
|
||||||
return "memory"
|
return "memory"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (filer *MemDbStore) Initialize(viper *viper.Viper) (err error) {
|
func (store *MemDbStore) Initialize(viper *viper.Viper) (err error) {
|
||||||
filer.tree = btree.New(8)
|
store.tree = btree.New(8)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (filer *MemDbStore) InsertEntry(entry *filer2.Entry) (err error) {
|
func (store *MemDbStore) InsertEntry(entry *filer2.Entry) (err error) {
|
||||||
// println("inserting", entry.FullPath)
|
// println("inserting", entry.FullPath)
|
||||||
entry.Crtime = time.Now()
|
entry.Crtime = time.Now()
|
||||||
filer.tree.ReplaceOrInsert(Entry{entry})
|
store.tree.ReplaceOrInsert(entryItem{entry})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (filer *MemDbStore) UpdateEntry(entry *filer2.Entry) (err error) {
|
func (store *MemDbStore) UpdateEntry(entry *filer2.Entry) (err error) {
|
||||||
if _, err = filer.FindEntry(entry.FullPath); err != nil {
|
if _, err = store.FindEntry(entry.FullPath); err != nil {
|
||||||
return fmt.Errorf("no such file %s : %v", entry.FullPath, err)
|
return fmt.Errorf("no such file %s : %v", entry.FullPath, err)
|
||||||
}
|
}
|
||||||
entry.Mtime = time.Now()
|
entry.Mtime = time.Now()
|
||||||
filer.tree.ReplaceOrInsert(Entry{entry})
|
store.tree.ReplaceOrInsert(entryItem{entry})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (filer *MemDbStore) FindEntry(fullpath filer2.FullPath) (entry *filer2.Entry, err error) {
|
func (store *MemDbStore) FindEntry(fullpath filer2.FullPath) (entry *filer2.Entry, err error) {
|
||||||
item := filer.tree.Get(Entry{&filer2.Entry{FullPath: fullpath}})
|
item := store.tree.Get(entryItem{&filer2.Entry{FullPath: fullpath}})
|
||||||
if item == nil {
|
if item == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
entry = item.(Entry).Entry
|
entry = item.(entryItem).Entry
|
||||||
return entry, nil
|
return entry, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (filer *MemDbStore) DeleteEntry(fullpath filer2.FullPath) (entry *filer2.Entry, err error) {
|
func (store *MemDbStore) DeleteEntry(fullpath filer2.FullPath) (entry *filer2.Entry, err error) {
|
||||||
item := filer.tree.Delete(Entry{&filer2.Entry{FullPath: fullpath}})
|
item := store.tree.Delete(entryItem{&filer2.Entry{FullPath: fullpath}})
|
||||||
if item == nil {
|
if item == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
entry = item.(Entry).Entry
|
entry = item.(entryItem).Entry
|
||||||
return entry, nil
|
return entry, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (filer *MemDbStore) ListDirectoryEntries(fullpath filer2.FullPath, startFileName string, inclusive bool, limit int) (entries []*filer2.Entry, err error) {
|
func (store *MemDbStore) ListDirectoryEntries(fullpath filer2.FullPath, startFileName string, inclusive bool, limit int) (entries []*filer2.Entry, err error) {
|
||||||
|
|
||||||
startFrom := string(fullpath)
|
startFrom := string(fullpath)
|
||||||
if startFileName != "" {
|
if startFileName != "" {
|
||||||
startFrom = startFrom + "/" + startFileName
|
startFrom = startFrom + "/" + startFileName
|
||||||
}
|
}
|
||||||
|
|
||||||
filer.tree.AscendGreaterOrEqual(Entry{&filer2.Entry{FullPath: filer2.FullPath(startFrom)}},
|
store.tree.AscendGreaterOrEqual(entryItem{&filer2.Entry{FullPath: filer2.FullPath(startFrom)}},
|
||||||
func(item btree.Item) bool {
|
func(item btree.Item) bool {
|
||||||
if limit <= 0 {
|
if limit <= 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
entry := item.(Entry).Entry
|
entry := item.(entryItem).Entry
|
||||||
// println("checking", entry.FullPath)
|
// println("checking", entry.FullPath)
|
||||||
|
|
||||||
if entry.FullPath == fullpath {
|
if entry.FullPath == fullpath {
|
||||||
|
|
Loading…
Reference in a new issue