backend/filelu: fix recursive listing path handling and file filtering

This commit is contained in:
kingston125
2026-06-08 11:54:43 +01:00
committed by Nick Craig-Wood
parent ec97bb4d7f
commit e64480f634
+15 -17
View File
@@ -222,38 +222,36 @@ func (f *Fs) List(ctx context.Context, dir string) (fs.DirEntries, error) {
return nil, err return nil, err
} }
fldMap := map[string]bool{}
for _, folder := range result.Result.Folders { for _, folder := range result.Result.Folders {
fldMap[folder.FldID.String()] = true
if f.root == "" && dir == "" && strings.Contains(folder.Path, "/") { if f.root == "" && dir == "" && strings.Contains(folder.Path, "/") {
continue continue
} }
paths := strings.Split(folder.Path, fullPath+"/") folderPath := strings.Trim(folder.Path, "/")
remote := paths[0] root := strings.Trim(f.root, "/")
if len(paths) > 1 {
remote = paths[1] remotePathWithoutRoot := folderPath
if root != "" {
if remotePathWithoutRoot == root {
continue
}
remotePathWithoutRoot = strings.TrimPrefix(remotePathWithoutRoot, root+"/")
} }
if strings.Contains(remote, "/") { remotePathWithoutRoot = strings.TrimPrefix(remotePathWithoutRoot, "/")
if remotePathWithoutRoot == "" {
continue continue
} }
pathsWithoutRoot := strings.Split(folder.Path, "/"+f.root+"/")
remotePathWithoutRoot := pathsWithoutRoot[0]
if len(pathsWithoutRoot) > 1 {
remotePathWithoutRoot = pathsWithoutRoot[1]
}
remotePathWithoutRoot = strings.TrimPrefix(remotePathWithoutRoot, "/")
entries = append(entries, fs.NewDir(remotePathWithoutRoot, time.Now())) entries = append(entries, fs.NewDir(remotePathWithoutRoot, time.Now()))
} }
for _, file := range result.Result.Files { for _, file := range result.Result.Files {
if _, ok := fldMap[file.FldID.String()]; ok {
continue
}
remote := path.Join(dir, file.Name) remote := path.Join(dir, file.Name)
// trim leading slashes
remote = strings.TrimPrefix(remote, "/") remote = strings.TrimPrefix(remote, "/")
obj := &Object{ obj := &Object{
fs: f, fs: f,
remote: remote, remote: remote,