From db22666a302c5a61e792d68e991ef4e318f1d8b7 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 2 Dec 2018 19:42:50 -0800 Subject: [PATCH] add default root directory --- weed/filer2/filer.go | 20 ++++++++++++++++++++ weed/filer2/leveldb/leveldb_store_test.go | 22 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/weed/filer2/filer.go b/weed/filer2/filer.go index 8e8528e99..cfae6eb0a 100644 --- a/weed/filer2/filer.go +++ b/weed/filer2/filer.go @@ -14,6 +14,11 @@ import ( "github.com/karlseguin/ccache" ) +var ( + OS_UID = uint32(os.Getuid()) + OS_GID = uint32(os.Getgid()) +) + type Filer struct { store FilerStore directoryCache *ccache.Cache @@ -157,6 +162,21 @@ func (f *Filer) UpdateEntry(oldEntry, entry *Entry) (err error) { } func (f *Filer) FindEntry(p FullPath) (entry *Entry, err error) { + + now := time.Now() + + if string(p) == "/" { + return &Entry{ + FullPath: p, + Attr: Attr{ + Mtime: now, + Crtime: now, + Mode: os.ModeDir | 0777, + Uid: OS_UID, + Gid: OS_GID, + }, + }, nil + } return f.store.FindEntry(p) } diff --git a/weed/filer2/leveldb/leveldb_store_test.go b/weed/filer2/leveldb/leveldb_store_test.go index ad72a2e60..5b214558f 100644 --- a/weed/filer2/leveldb/leveldb_store_test.go +++ b/weed/filer2/leveldb/leveldb_store_test.go @@ -59,3 +59,25 @@ func TestCreateAndFind(t *testing.T) { } } + +func TestEmptyRoot(t *testing.T) { + filer := filer2.NewFiler(nil) + dir, _ := ioutil.TempDir("", "seaweedfs_filer_test2") + defer os.RemoveAll(dir) + store := &LevelDBStore{} + store.initialize(dir) + filer.SetStore(store) + filer.DisableDirectoryCache() + + // checking one upper directory + entries, err := filer.ListDirectoryEntries(filer2.FullPath("/"), "", false, 100) + if err != nil { + t.Errorf("list entries: %v", err) + return + } + if len(entries) != 0 { + t.Errorf("list entries count: %v", len(entries)) + return + } + +}