|
|
@ -28,7 +28,7 @@ type DirectoryManagerInMap struct { |
|
|
|
isLoading bool |
|
|
|
} |
|
|
|
|
|
|
|
func (dm *DirectoryManagerInMap) NewDirectoryEntryInMap(parent *DirectoryEntryInMap, name string) (d *DirectoryEntryInMap) { |
|
|
|
func (dm *DirectoryManagerInMap) NewDirectoryEntryInMap(parent *DirectoryEntryInMap, name string) (d *DirectoryEntryInMap, err error) { |
|
|
|
writeLock.Lock() |
|
|
|
defer writeLock.Unlock() |
|
|
|
d = &DirectoryEntryInMap{Name: name, Parent: parent, SubDirectories: make(map[string]*DirectoryEntryInMap)} |
|
|
@ -38,7 +38,7 @@ func (dm *DirectoryManagerInMap) NewDirectoryEntryInMap(parent *DirectoryEntryIn |
|
|
|
} |
|
|
|
n := len(parts) |
|
|
|
if n <= 0 { |
|
|
|
return d |
|
|
|
return nil, fmt.Errorf("Failed to create folder %s/%s", parent.Name, name) |
|
|
|
} |
|
|
|
for i := 0; i < n/2; i++ { |
|
|
|
parts[i], parts[n-1-i] = parts[n-1-i], parts[i] |
|
|
@ -46,7 +46,7 @@ func (dm *DirectoryManagerInMap) NewDirectoryEntryInMap(parent *DirectoryEntryIn |
|
|
|
dm.max++ |
|
|
|
d.Id = dm.max |
|
|
|
dm.log("add", "/"+strings.Join(parts, "/"), strconv.Itoa(int(d.Id))) |
|
|
|
return d |
|
|
|
return d, nil |
|
|
|
} |
|
|
|
|
|
|
|
func (dm *DirectoryManagerInMap) log(words ...string) { |
|
|
@ -162,7 +162,11 @@ func (dm *DirectoryManagerInMap) loadDirectory(dirPath string, dirId DirectoryId |
|
|
|
if i != len(parts)-1 { |
|
|
|
return fmt.Errorf("%s should be created after parent %s!", dirPath, parts[i]) |
|
|
|
} |
|
|
|
sub = dm.NewDirectoryEntryInMap(dir, parts[i]) |
|
|
|
var err error |
|
|
|
sub, err = dm.NewDirectoryEntryInMap(dir, parts[i]) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if sub.Id != dirId { |
|
|
|
return fmt.Errorf("%s should be have id %v instead of %v!", dirPath, sub.Id, dirId) |
|
|
|
} |
|
|
@ -183,7 +187,11 @@ func (dm *DirectoryManagerInMap) makeDirectory(dirPath string) (dir *DirectoryEn |
|
|
|
for i := 1; i < len(parts); i++ { |
|
|
|
sub, ok := dir.SubDirectories[parts[i]] |
|
|
|
if !ok { |
|
|
|
sub = dm.NewDirectoryEntryInMap(dir, parts[i]) |
|
|
|
var err error |
|
|
|
sub, err = dm.NewDirectoryEntryInMap(dir, parts[i]) |
|
|
|
if err != nil { |
|
|
|
return nil, false |
|
|
|
} |
|
|
|
dir.SubDirectories[parts[i]] = sub |
|
|
|
created = true |
|
|
|
} |
|
|
|