Storage: fix filestorage.Wrapper PathFiltering and non-recursive folder listing (#46469)

* fix pathFilters in wrapper - apply rootPath changes before filtering

* fix non-recursive folder listing
This commit is contained in:
Artur Wierzbicki
2022-03-11 23:16:46 +04:00
committed by GitHub
parent ed924b3d0c
commit 5881127319
4 changed files with 83 additions and 12 deletions

View File

@@ -318,6 +318,8 @@ func (s dbFileStorage) ListFiles(ctx context.Context, folderPath string, paging
func (s dbFileStorage) ListFolders(ctx context.Context, parentFolderPath string, options *ListOptions) ([]FileMetadata, error) {
folders := make([]FileMetadata, 0)
parentFolderPath = strings.TrimSuffix(parentFolderPath, Delimiter)
err := s.db.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
var foundPaths []string
@@ -327,7 +329,7 @@ func (s dbFileStorage) ListFolders(ctx context.Context, parentFolderPath string,
if options.Recursive {
sess.Where("LOWER(parent_folder_path) > ?", strings.ToLower(parentFolderPath))
} else {
sess.Where("LOWER(parent_folder_path) = ?", strings.ToLower(parentFolderPath))
sess.Where("LOWER(parent_folder_path) LIKE ? AND LOWER(parent_folder_path) NOT LIKE ?", strings.ToLower(parentFolderPath)+Delimiter+"%", strings.ToLower(parentFolderPath)+Delimiter+"%"+Delimiter+"%")
}
if options.PathFilters.isDenyAll() {