fix directory creation, directory listing

This commit is contained in:
Chris Lu 2018-05-19 12:07:15 -07:00
parent e31c514b00
commit ab4ddb1e0e
4 changed files with 17 additions and 7 deletions

View file

@ -9,6 +9,7 @@ import (
"time" "time"
"os" "os"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/chrislusf/seaweedfs/weed/glog"
) )
type Filer struct { type Filer struct {
@ -44,22 +45,23 @@ func (f *Filer) CreateEntry(entry *Entry) (error) {
dirPath := "/" + filepath.Join(dirParts[:i]...) dirPath := "/" + filepath.Join(dirParts[:i]...)
// fmt.Printf("%d directory: %+v\n", i, dirPath) // fmt.Printf("%d directory: %+v\n", i, dirPath)
dirFound := false
// first check local cache // first check local cache
dirEntry := f.cacheGetDirectory(dirPath) dirEntry := f.cacheGetDirectory(dirPath)
// not found, check the store directly // not found, check the store directly
if dirEntry == nil { if dirEntry == nil {
glog.V(4).Infof("find uncached directory: %s", dirPath)
var dirFindErr error var dirFindErr error
dirFound, dirEntry, dirFindErr = f.FindEntry(FullPath(dirPath)) _, dirEntry, dirFindErr = f.FindEntry(FullPath(dirPath))
if dirFindErr != nil { if dirFindErr != nil {
return fmt.Errorf("findDirectory %s: %v", dirPath, dirFindErr) return fmt.Errorf("findDirectory %s: %v", dirPath, dirFindErr)
} }
}else{
glog.V(4).Infof("found cached directory: %s", dirPath)
} }
// no such existing directory // no such existing directory
if !dirFound { if dirEntry == nil {
// create the directory // create the directory
now := time.Now() now := time.Now()
@ -75,6 +77,7 @@ func (f *Filer) CreateEntry(entry *Entry) (error) {
}, },
} }
glog.V(2).Infof("create directory: %s", dirPath)
mkdirErr := f.store.InsertEntry(dirEntry) mkdirErr := f.store.InsertEntry(dirEntry)
if mkdirErr != nil { if mkdirErr != nil {
return fmt.Errorf("mkdir %s: %v", dirPath, mkdirErr) return fmt.Errorf("mkdir %s: %v", dirPath, mkdirErr)

View file

@ -77,11 +77,13 @@ func (filer *MemDbStore) ListDirectoryEntries(fullpath filer2.FullPath, startFil
} }
entry := item.(Entry).Entry entry := item.(Entry).Entry
// println("checking", entry.FullPath) // println("checking", entry.FullPath)
if entry.FullPath == fullpath { if entry.FullPath == fullpath {
// skipping the current directory // skipping the current directory
// println("skipping the folder", entry.FullPath) // println("skipping the folder", entry.FullPath)
return true return true
} }
dir, name := entry.FullPath.DirAndName() dir, name := entry.FullPath.DirAndName()
if name == startFileName { if name == startFileName {
if inclusive { if inclusive {
@ -90,11 +92,13 @@ func (filer *MemDbStore) ListDirectoryEntries(fullpath filer2.FullPath, startFil
} }
return true return true
} }
if !strings.HasPrefix(dir, string(fullpath)) {
// println("directory is:", dir, "fullpath:", fullpath) // only iterate the same prefix
if !strings.HasPrefix(string(entry.FullPath), string(fullpath)) {
// println("breaking from", entry.FullPath) // println("breaking from", entry.FullPath)
return false return false
} }
if dir != string(fullpath) { if dir != string(fullpath) {
// this could be items in deeper directories // this could be items in deeper directories
// println("skipping deeper folder", entry.FullPath) // println("skipping deeper folder", entry.FullPath)

View file

@ -15,7 +15,7 @@ func (fs *FilerServer) registerHandler(w http.ResponseWriter, r *http.Request) {
fileId := r.FormValue("fileId") fileId := r.FormValue("fileId")
fileSize, err := strconv.ParseUint(r.FormValue("fileSize"), 10, 64) fileSize, err := strconv.ParseUint(r.FormValue("fileSize"), 10, 64)
if err != nil { if err != nil {
glog.V(4).Infof("register %s to %s parse fileSize %s: %v", fileId, path, r.FormValue("fileSize"), err) glog.V(0).Infof("register %s to %s parse fileSize %s: %v", fileId, path, r.FormValue("fileSize"), err)
writeJsonError(w, r, http.StatusInternalServerError, err) writeJsonError(w, r, http.StatusInternalServerError, err)
return return
} }
@ -30,6 +30,7 @@ func (fs *FilerServer) registerHandler(w http.ResponseWriter, r *http.Request) {
Mtime: time.Now().UnixNano(), Mtime: time.Now().UnixNano(),
}}, }},
} }
glog.V(2).Infof("register %s to %s parse fileSize %s", fileId, path, r.FormValue("fileSize"))
err = fs.filer.CreateEntry(entry) err = fs.filer.CreateEntry(entry)
if err != nil { if err != nil {
glog.V(4).Infof("register %s to %s error: %v", fileId, path, err) glog.V(4).Infof("register %s to %s error: %v", fileId, path, err)

View file

@ -48,6 +48,8 @@ func (fs *FilerServer) listDirectoryHandler(w http.ResponseWriter, r *http.Reque
lastFileName = entries[len(entries)-1].Name() lastFileName = entries[len(entries)-1].Name()
} }
glog.V(4).Infof("listDirectory %s, last file %s, limit %d: %d items", path, lastFileName, limit, len(entries))
args := struct { args := struct {
Path string Path string
Entries interface{} Entries interface{}