diff options
Diffstat (limited to 'go/filer')
| -rw-r--r-- | go/filer/client_operations.go | 2 | ||||
| -rw-r--r-- | go/filer/directory_in_map.go | 33 | ||||
| -rw-r--r-- | go/filer/filer_embedded.go | 2 | ||||
| -rw-r--r-- | go/filer/files_in_leveldb.go | 2 |
4 files changed, 28 insertions, 11 deletions
diff --git a/go/filer/client_operations.go b/go/filer/client_operations.go index 5d89fc865..0b006289f 100644 --- a/go/filer/client_operations.go +++ b/go/filer/client_operations.go @@ -3,7 +3,7 @@ package filer import () import ( - "code.google.com/p/weed-fs/go/util" + "github.com/chrislusf/weed-fs/go/util" "encoding/json" "errors" "fmt" diff --git a/go/filer/directory_in_map.go b/go/filer/directory_in_map.go index 9c2ecdf80..1d88a78be 100644 --- a/go/filer/directory_in_map.go +++ b/go/filer/directory_in_map.go @@ -2,15 +2,18 @@ package filer import ( "bufio" - "code.google.com/p/weed-fs/go/util" + "github.com/chrislusf/weed-fs/go/util" "fmt" "io" "os" "path/filepath" "strconv" "strings" + "sync" ) +var writeLock sync.Mutex //serialize changes to dir.log + type DirectoryEntryInMap struct { Name string Parent *DirectoryEntryInMap @@ -25,23 +28,25 @@ 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)} - dm.max++ - d.Id = dm.max parts := make([]string, 0) for p := d; p != nil && p.Name != ""; p = p.Parent { parts = append(parts, p.Name) } 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] } + 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) { @@ -157,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) } @@ -178,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 } @@ -193,6 +206,8 @@ func (dm *DirectoryManagerInMap) MakeDirectory(dirPath string) (DirectoryId, err } func (dm *DirectoryManagerInMap) MoveUnderDirectory(oldDirPath string, newParentDirPath string, newName string) error { + writeLock.Lock() + defer writeLock.Unlock() oldDir, oe := dm.findDirectory(oldDirPath) if oe != nil { return oe @@ -223,6 +238,8 @@ func (dm *DirectoryManagerInMap) ListDirectories(dirPath string) (dirNames []Dir return dirNames, nil } func (dm *DirectoryManagerInMap) DeleteDirectory(dirPath string) error { + writeLock.Lock() + defer writeLock.Unlock() if dirPath == "/" { return fmt.Errorf("Can not delete %s", dirPath) } diff --git a/go/filer/filer_embedded.go b/go/filer/filer_embedded.go index a3b64d37b..3d3dac941 100644 --- a/go/filer/filer_embedded.go +++ b/go/filer/filer_embedded.go @@ -1,7 +1,7 @@ package filer import ( - "code.google.com/p/weed-fs/go/operation" + "github.com/chrislusf/weed-fs/go/operation" "errors" "fmt" "path/filepath" diff --git a/go/filer/files_in_leveldb.go b/go/filer/files_in_leveldb.go index dbf2e6c52..41fbc74bd 100644 --- a/go/filer/files_in_leveldb.go +++ b/go/filer/files_in_leveldb.go @@ -2,7 +2,7 @@ package filer import ( "bytes" - "code.google.com/p/weed-fs/go/glog" + "github.com/chrislusf/weed-fs/go/glog" "github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb/util" ) |
