From 7ddb99645f3cd76849c8eee0c03d3500f1f484c4 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Mon, 27 May 2024 14:59:04 +0500 Subject: [PATCH] fix test_bucket_listv2_continuationtoken --- weed/filer/abstract_sql/abstract_sql_store.go | 2 +- weed/filer/mysql/mysql_sql_gen.go | 2 +- weed/s3api/s3api_object_handlers_list.go | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/weed/filer/abstract_sql/abstract_sql_store.go b/weed/filer/abstract_sql/abstract_sql_store.go index 31a4a053a..9944209e4 100644 --- a/weed/filer/abstract_sql/abstract_sql_store.go +++ b/weed/filer/abstract_sql/abstract_sql_store.go @@ -366,7 +366,7 @@ func (store *AbstractSqlStore) ListRecursivePrefixedEntries(ctx context.Context, } else { fileName = dir + name } - lastFileName = fmt.Sprintf("%s/%s", dir, name) + lastFileName = fmt.Sprintf("%s%s", dir, name) entry := &filer.Entry{ FullPath: util.NewFullPath(bucketDir, fileName), } diff --git a/weed/filer/mysql/mysql_sql_gen.go b/weed/filer/mysql/mysql_sql_gen.go index fb2495dfa..db31df180 100644 --- a/weed/filer/mysql/mysql_sql_gen.go +++ b/weed/filer/mysql/mysql_sql_gen.go @@ -50,7 +50,7 @@ func (gen *SqlGenMysql) GetSqlListInclusive(tableName string) string { } func (gen *SqlGenMysql) GetSqlListRecursive(tableName string) string { - return fmt.Sprintf("SELECT `directory`, `name`, `meta` FROM `%s` WHERE `directory` || '/' || `name` > ? AND ((`dirhash` == ? AND `name` like ?) OR `directory` like ?) ORDER BY `directory` || '/' || `name` ASC LIMIT ?", tableName) + return fmt.Sprintf("SELECT `directory`, `name`, `meta` FROM `%s` WHERE `directory` || `name` > ? AND ((`dirhash` == ? AND `name` like ?) OR `directory` like ?) ORDER BY `directory` || `name` ASC LIMIT ?", tableName) } func (gen *SqlGenMysql) GetSqlCreateTable(tableName string) string { diff --git a/weed/s3api/s3api_object_handlers_list.go b/weed/s3api/s3api_object_handlers_list.go index 0a6119432..c93a0aaa5 100644 --- a/weed/s3api/s3api_object_handlers_list.go +++ b/weed/s3api/s3api_object_handlers_list.go @@ -155,12 +155,12 @@ func (s3a *S3ApiServer) listFilerEntries(bucket string, originalPrefix string, m reqDir += originalPrefix[:idx] prefix = originalPrefix[idx+1:] } - // This is necessary for SQL request with WHERE `directory` || '/' || `name` > originalMarker + // This is necessary for SQL request with WHERE `directory` || `name` > originalMarker if len(originalMarker) > 0 && originalMarker[0:1] != "/" { - if reqDir == bucketPrefix { - marker = "//" + originalMarker - } else { + if idx := strings.LastIndex(originalMarker, "/"); idx == -1 { marker = "/" + originalMarker + } else { + marker = fmt.Sprintf("/%s%s", originalMarker[0:idx], originalMarker[idx+1:len(originalMarker)]) } } else { marker = originalMarker @@ -192,10 +192,10 @@ func (s3a *S3ApiServer) listFilerEntries(bucket string, originalPrefix string, m defer func() { if cursor.maxKeys == 0 { cursor.isTruncated = true - if strings.Index(key, "/") == -1 { - cursor.nextMarker = "//" + key - } else { + if idx := strings.Index(key, "/"); idx == -1 { cursor.nextMarker = "/" + key + } else { + cursor.nextMarker = fmt.Sprintf("/%s%s", key[0:idx], key[idx+1:len(key)]) } } }()