diff options
| author | Устюжанин Антон Александрович <ustuzhanin@tochka.com> | 2020-08-05 22:19:16 +0500 |
|---|---|---|
| committer | Устюжанин Антон Александрович <ustuzhanin@tochka.com> | 2020-08-05 22:19:16 +0500 |
| commit | 33a9e5e2d1948d08ec6456be6df3a6683a780905 (patch) | |
| tree | c123075cfe5b82dd53bf286c71f7c107b0d89f15 /weed/filer2/abstract_sql | |
| parent | cbd80253e33688f55c02dd29c994a3ee6eac3d6c (diff) | |
| download | seaweedfs-33a9e5e2d1948d08ec6456be6df3a6683a780905.tar.xz seaweedfs-33a9e5e2d1948d08ec6456be6df3a6683a780905.zip | |
test ListDirectoryPrefixedEntries
Diffstat (limited to 'weed/filer2/abstract_sql')
| -rw-r--r-- | weed/filer2/abstract_sql/abstract_sql_store.go | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/weed/filer2/abstract_sql/abstract_sql_store.go b/weed/filer2/abstract_sql/abstract_sql_store.go index 5ade18960..ed0d6e8ef 100644 --- a/weed/filer2/abstract_sql/abstract_sql_store.go +++ b/weed/filer2/abstract_sql/abstract_sql_store.go @@ -150,8 +150,75 @@ func (store *AbstractSqlStore) DeleteFolderChildren(ctx context.Context, fullpat return nil } -func (store *AbstractSqlStore) ListDirectoryEntries(ctx context.Context, fullpath util.FullPath, startFileName string, inclusive bool, limit int) (entries []*filer2.Entry, err error) { +//func (store *AbstractSqlStore) ListDirectoryPrefixedEntries(ctx context.Context, fullpath util.FullPath, startFileName string, inclusive bool, limit int, prefix string) (entries []*filer2.Entry, err error) { +// sqlText := store.SqlListExclusive +// if inclusive { +// sqlText = store.SqlListInclusive +// } +// +// rows, err := store.getTxOrDB(ctx).QueryContext(ctx, sqlText, util.HashStringToLong(string(fullpath)), startFileName, string(fullpath), prefix, limit) +// if err != nil { +// return nil, fmt.Errorf("list %s : %v", fullpath, err) +// } +// defer rows.Close() +// +// for rows.Next() { +// var name string +// var data []byte +// if err = rows.Scan(&name, &data); err != nil { +// glog.V(0).Infof("scan %s : %v", fullpath, err) +// return nil, fmt.Errorf("scan %s: %v", fullpath, err) +// } +// +// entry := &filer2.Entry{ +// FullPath: util.NewFullPath(string(fullpath), name), +// } +// if err = entry.DecodeAttributesAndChunks(data); err != nil { +// glog.V(0).Infof("scan decode %s : %v", entry.FullPath, err) +// return nil, fmt.Errorf("scan decode %s : %v", entry.FullPath, err) +// } +// +// entries = append(entries, entry) +// } +// +// return entries, nil +//} +//func (store *AbstractSqlStore) ListDirectoryEntries(ctx context.Context, fullpath util.FullPath, startFileName string, inclusive bool, limit int, prefix string) (entries []*filer2.Entry, err error) { +// return nil, fmt.Errorf("not implemented") +// +//} + +func (store *AbstractSqlStore) ListDirectoryPrefixedEntries(ctx context.Context, fullpath util.FullPath, startFileName string, inclusive bool, limit int, prefix string) (entries []*filer2.Entry, err error) { + count := 0 + notPrefixed, err := store.ListDirectoryEntries(ctx, fullpath, startFileName, inclusive, limit) + if err != nil { + return nil, err + } + + if prefix == "" { + return notPrefixed, nil + } + for count < limit { + for _, entry := range notPrefixed { + if strings.HasPrefix(entry.Name(), prefix) { + count++ + entries = append(entries, entry) + } + } + if count >= limit { + break + } + notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, startFileName, inclusive, limit) + if err != nil { + return nil, err + } + } + + return entries, nil +} + +func (store *AbstractSqlStore) ListDirectoryEntries(ctx context.Context, fullpath util.FullPath, startFileName string, inclusive bool, limit int) (entries []*filer2.Entry, err error) { sqlText := store.SqlListExclusive if inclusive { sqlText = store.SqlListInclusive |
