mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Modify: add recursive options for list method
Test: local.List
This commit is contained in:
@@ -46,7 +46,7 @@ type Driver struct {
|
||||
HTTPClient request.Client
|
||||
}
|
||||
|
||||
func (handler Driver) List(ctx context.Context, path string) ([]response.Object, error) {
|
||||
func (handler Driver) List(ctx context.Context, path string, recursive bool) ([]response.Object, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ type Driver struct {
|
||||
}
|
||||
|
||||
// List 递归列取给定物理路径下所有文件
|
||||
func (handler Driver) List(ctx context.Context, path string) ([]response.Object, error) {
|
||||
func (handler Driver) List(ctx context.Context, path string, recursive bool) ([]response.Object, error) {
|
||||
var res []response.Object
|
||||
|
||||
// 取得起始路径
|
||||
@@ -58,6 +58,11 @@ func (handler Driver) List(ctx context.Context, path string) ([]response.Object,
|
||||
LastModify: info.ModTime(),
|
||||
})
|
||||
|
||||
// 如果非递归,则不步入目录
|
||||
if !recursive && info.IsDir() {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package local
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
model "github.com/HFO4/cloudreve/models"
|
||||
"github.com/HFO4/cloudreve/pkg/auth"
|
||||
"github.com/HFO4/cloudreve/pkg/conf"
|
||||
@@ -233,10 +232,32 @@ func TestHandler_Token(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDriver_List(t *testing.T) {
|
||||
//asserts := assert.New(t)
|
||||
asserts := assert.New(t)
|
||||
handler := Driver{}
|
||||
ctx := context.Background()
|
||||
|
||||
res, err := handler.List(ctx, "KKV")
|
||||
fmt.Println(res, err)
|
||||
// 创建测试目录结构
|
||||
for _, path := range []string{
|
||||
"test/TestDriver_List/parent.txt",
|
||||
"test/TestDriver_List/parent_folder2/sub2.txt",
|
||||
"test/TestDriver_List/parent_folder1/sub_folder/sub1.txt",
|
||||
"test/TestDriver_List/parent_folder1/sub_folder/sub2.txt",
|
||||
} {
|
||||
f, _ := util.CreatNestedFile(util.RelativePath(path))
|
||||
f.Close()
|
||||
}
|
||||
|
||||
// 非递归列出
|
||||
{
|
||||
res, err := handler.List(ctx, "test/TestDriver_List", false)
|
||||
asserts.NoError(err)
|
||||
asserts.Len(res, 3)
|
||||
}
|
||||
|
||||
// 递归列出
|
||||
{
|
||||
res, err := handler.List(ctx, "test/TestDriver_List", true)
|
||||
asserts.NoError(err)
|
||||
asserts.Len(res, 7)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ type Driver struct {
|
||||
HTTPClient request.Client
|
||||
}
|
||||
|
||||
func (handler Driver) List(ctx context.Context, path string) ([]response.Object, error) {
|
||||
func (handler Driver) List(ctx context.Context, path string, recursive bool) ([]response.Object, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ type Driver struct {
|
||||
HTTPClient request.Client
|
||||
}
|
||||
|
||||
func (handler Driver) List(ctx context.Context, path string) ([]response.Object, error) {
|
||||
func (handler Driver) List(ctx context.Context, path string, recursive bool) ([]response.Object, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ type Driver struct {
|
||||
Policy *model.Policy
|
||||
}
|
||||
|
||||
func (handler Driver) List(ctx context.Context, path string) ([]response.Object, error) {
|
||||
func (handler Driver) List(ctx context.Context, path string, recursive bool) ([]response.Object, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ type Driver struct {
|
||||
AuthInstance auth.Auth
|
||||
}
|
||||
|
||||
func (handler Driver) List(ctx context.Context, path string) ([]response.Object, error) {
|
||||
func (handler Driver) List(ctx context.Context, path string, recursive bool) ([]response.Object, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ type Driver struct {
|
||||
Policy *model.Policy
|
||||
}
|
||||
|
||||
func (handler Driver) List(ctx context.Context, path string) ([]response.Object, error) {
|
||||
func (handler Driver) List(ctx context.Context, path string, recursive bool) ([]response.Object, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user