mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
visit parent folder first
This commit is contained in:
parent
8a1d640dc4
commit
a808df5019
|
@ -39,7 +39,7 @@ func (f *Filer) CreateEntry(entry Entry) (error) {
|
||||||
3. add the file entry
|
3. add the file entry
|
||||||
*/
|
*/
|
||||||
|
|
||||||
f.recursivelyEnsureDirectory(entry.Dir, func(parent, name string) error {
|
recursivelyEnsureDirectory(entry.Dir, func(parent, name string) error {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ func (f *Filer) UpdateEntry(entry Entry) (error) {
|
||||||
return f.store.UpdateEntry(entry)
|
return f.store.UpdateEntry(entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Filer) recursivelyEnsureDirectory(fullPath string, fn func(parent, name string) error) (error) {
|
func recursivelyEnsureDirectory(fullPath string, fn func(parent, name string) error) (error) {
|
||||||
if strings.HasSuffix(fullPath, "/") {
|
if strings.HasSuffix(fullPath, "/") {
|
||||||
fullPath = fullPath[0:len(fullPath)-1]
|
fullPath = fullPath[0:len(fullPath)-1]
|
||||||
}
|
}
|
||||||
|
@ -82,11 +82,15 @@ func (f *Filer) recursivelyEnsureDirectory(fullPath string, fn func(parent, name
|
||||||
parentDirPath = "/"
|
parentDirPath = "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := recursivelyEnsureDirectory(parentDirPath, fn); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if err := fn(parentDirPath, dirName); err != nil {
|
if err := fn(parentDirPath, dirName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return f.recursivelyEnsureDirectory(parentDirPath, fn)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Filer) cacheGetDirectory(dirpath string) (error) {
|
func (f *Filer) cacheGetDirectory(dirpath string) (error) {
|
||||||
|
|
|
@ -7,21 +7,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRecursion(t *testing.T) {
|
func TestRecursion(t *testing.T) {
|
||||||
filer := NewFiler("")
|
|
||||||
|
|
||||||
fullPath := "/home/chris/some/file/abc.jpg"
|
fullPath := "/home/chris/some/file/abc.jpg"
|
||||||
expected := []string{
|
expected := []string{
|
||||||
"/home/chris/some", "file",
|
|
||||||
"/home/chris", "some",
|
|
||||||
"/home", "chris",
|
|
||||||
"/", "home",
|
"/", "home",
|
||||||
|
"/home", "chris",
|
||||||
|
"/home/chris", "some",
|
||||||
|
"/home/chris/some", "file",
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, _ := filepath.Split(fullPath)
|
dir, _ := filepath.Split(fullPath)
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
|
|
||||||
filer.recursivelyEnsureDirectory(dir, func(parent, name string) error {
|
recursivelyEnsureDirectory(dir, func(parent, name string) error {
|
||||||
if parent != expected[i] || name != expected[i+1] {
|
if parent != expected[i] || name != expected[i+1] {
|
||||||
t.Errorf("recursive directory is wrong! parent=%s dirName=%s", parent, name)
|
t.Errorf("recursive directory is wrong! parent=%s dirName=%s", parent, name)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue