aboutsummaryrefslogtreecommitdiff
path: root/weed/filer2
diff options
context:
space:
mode:
Diffstat (limited to 'weed/filer2')
-rw-r--r--weed/filer2/filer.go15
-rw-r--r--weed/filer2/filer_structure.go9
-rw-r--r--weed/filer2/memdb/memdb_store_test.go8
3 files changed, 31 insertions, 1 deletions
diff --git a/weed/filer2/filer.go b/weed/filer2/filer.go
index ad7a3d906..5f76d6fb0 100644
--- a/weed/filer2/filer.go
+++ b/weed/filer2/filer.go
@@ -114,11 +114,24 @@ func (f *Filer) FindEntry(p FullPath) (found bool, entry *Entry, err error) {
}
func (f *Filer) DeleteEntry(p FullPath) (fileEntry *Entry, err error) {
+ found, entry, err := f.FindEntry(p)
+ if err != nil || !found {
+ return nil, err
+ }
+ if entry.IsDirectory() {
+ entries, err := f.ListDirectoryEntries(p, "", false, 1)
+ if err != nil {
+ return nil, fmt.Errorf("list folder %s: %v", p, err)
+ }
+ if len(entries) > 0 {
+ return nil, fmt.Errorf("folder %s is not empty", p)
+ }
+ }
return f.store.DeleteEntry(p)
}
func (f *Filer) ListDirectoryEntries(p FullPath, startFileName string, inclusive bool, limit int) ([]*Entry, error) {
- if strings.HasSuffix(string(p), "/") {
+ if strings.HasSuffix(string(p), "/") && len(p) > 1 {
p = p[0:len(p)-1]
}
return f.store.ListDirectoryEntries(p, startFileName, inclusive, limit)
diff --git a/weed/filer2/filer_structure.go b/weed/filer2/filer_structure.go
index c31d878cf..1cff96253 100644
--- a/weed/filer2/filer_structure.go
+++ b/weed/filer2/filer_structure.go
@@ -21,6 +21,11 @@ func (fp FullPath) DirAndName() (string, string) {
return dir[:len(dir)-1], name
}
+func (fp FullPath) Name() (string) {
+ _, name := filepath.Split(string(fp))
+ return name
+}
+
type Attr struct {
Mtime time.Time // time of last modification
Crtime time.Time // time of creation (OS X only)
@@ -29,6 +34,10 @@ type Attr struct {
Gid uint32 // group gid
}
+func (attr Attr) IsDirectory() (bool) {
+ return attr.Mode & os.ModeDir > 0
+}
+
type Entry struct {
FullPath
diff --git a/weed/filer2/memdb/memdb_store_test.go b/weed/filer2/memdb/memdb_store_test.go
index 3fefbf5cd..ab93a7665 100644
--- a/weed/filer2/memdb/memdb_store_test.go
+++ b/weed/filer2/memdb/memdb_store_test.go
@@ -108,6 +108,14 @@ func TestCreateFileAndList(t *testing.T) {
return
}
+ // checking root directory
+ entries, _ = filer.ListDirectoryEntries(filer2.FullPath("/"), "", false, 100)
+ if len(entries) != 1 {
+ t.Errorf("list entries count: %v", len(entries))
+ return
+ }
+
+ // add file3
file3Path := filer2.FullPath("/home/chris/this/is/file3.jpg")
entry3 := &filer2.Entry{
FullPath: file3Path,