Skip to content

Commit 49e6028

Browse files
committed
pgmoneta#1067 fix: s3 ls command to work with pfix
Signed-off-by: Amr-Shams <amr.shams2015.as@gmail.com>
1 parent 437445e commit 49e6028

5 files changed

Lines changed: 21 additions & 10 deletions

File tree

src/cli.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void display_helper(char* command);
122122

123123
static int backup(SSL* ssl, int socket, char* server, uint8_t compression, uint8_t encryption, char* incremental, int32_t output_format);
124124
static int list_backup(SSL* ssl, int socket, char* server, char* sort_order, uint8_t compression, uint8_t encryption, int32_t output_format);
125-
static int list_s3_objects(SSL* ssl, int socket, char* server, uint8_t compression, uint8_t encryption, int32_t output_format);
125+
static int list_s3_objects(SSL* ssl, int socket, char* server, char* prefix, uint8_t compression, uint8_t encryption, int32_t output_format);
126126
static int delete_s3_objects(SSL* ssl, int socket, char* server, char* prefix, uint8_t compression, uint8_t encryption, int32_t output_format);
127127
static int restore_s3_objects(SSL* ssl, int socket, char* server, char* prefix, uint8_t compression, uint8_t encryption, int32_t output_format);
128128
static int restore(SSL* ssl, int socket, char* server, char* backup_id, char* position, char* directory, uint8_t compression, uint8_t encryption, int32_t output_format);
@@ -932,7 +932,7 @@ main(int argc, char** argv)
932932
}
933933
else if (parsed.cmd->action == MANAGEMENT_S3_LS)
934934
{
935-
exit_code = list_s3_objects(s_ssl, socket, parsed.args[0], compression, encryption, output_format);
935+
exit_code = list_s3_objects(s_ssl, socket, parsed.args[0], parsed.args[1], compression, encryption, output_format);
936936
}
937937
else if (parsed.cmd->action == MANAGEMENT_S3_DELETE)
938938
{
@@ -1426,9 +1426,9 @@ list_backup(SSL* ssl, int socket, char* server, char* sort_order, uint8_t compre
14261426
return 1;
14271427
}
14281428
static int
1429-
list_s3_objects(SSL* ssl, int socket, char* server, uint8_t compression, uint8_t encryption, int32_t output_format)
1429+
list_s3_objects(SSL* ssl, int socket, char* server, char* prefix, uint8_t compression, uint8_t encryption, int32_t output_format)
14301430
{
1431-
if (pgmoneta_management_request_list_s3_objects(ssl, socket, server, compression, encryption, output_format))
1431+
if (pgmoneta_management_request_list_s3_objects(ssl, socket, server, prefix, compression, encryption, output_format))
14321432
{
14331433
goto error;
14341434
}

src/include/management.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ pgmoneta_management_request_list_backup(SSL* ssl, int socket, char* server, char
496496
* @return 0 upon success, otherwise 1
497497
*/
498498
int
499-
pgmoneta_management_request_list_s3_objects(SSL* ssl, int socket, char* server, uint8_t compression, uint8_t encryption, int32_t output_format);
499+
pgmoneta_management_request_list_s3_objects(SSL* ssl, int socket, char* server, char* prefix, uint8_t compression, uint8_t encryption, int32_t output_format);
500500

501501
/**
502502
* Create a delete s3 objects request

src/libpgmoneta/management.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pgmoneta_management_request_list_backup(SSL* ssl, int socket, char* server, char
124124
return 1;
125125
}
126126
int
127-
pgmoneta_management_request_list_s3_objects(SSL* ssl, int socket, char* server, uint8_t compression, uint8_t encryption, int32_t output_format)
127+
pgmoneta_management_request_list_s3_objects(SSL* ssl, int socket, char* server, char* prefix, uint8_t compression, uint8_t encryption, int32_t output_format)
128128
{
129129
struct json* j = NULL;
130130
struct json* request = NULL;
@@ -140,6 +140,10 @@ pgmoneta_management_request_list_s3_objects(SSL* ssl, int socket, char* server,
140140
}
141141

142142
pgmoneta_json_put(request, MANAGEMENT_ARGUMENT_SERVER, (uintptr_t)server, ValueString);
143+
if (prefix != NULL)
144+
{
145+
pgmoneta_json_put(request, MANAGEMENT_ARGUMENT_S3_PREFIX, (uintptr_t)prefix, ValueString);
146+
}
143147

144148
if (pgmoneta_management_write_json(ssl, socket, compression, encryption, j))
145149
{

src/libpgmoneta/s3.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pgmoneta_list_s3_objects(int client_fd, int server, uint8_t compression, uint8_t
6868
{
6969
char* elapsed = NULL;
7070
char* en = NULL;
71+
char* prefix = NULL;
7172
int ec = -1;
7273
struct timespec start_t;
7374
struct timespec end_t;
@@ -79,8 +80,11 @@ pgmoneta_list_s3_objects(int client_fd, int server, uint8_t compression, uint8_t
7980
struct art* nodes = NULL;
8081
struct workflow* workflow = NULL;
8182
struct main_configuration* config;
83+
struct json* request = NULL;
8284

8385
config = (struct main_configuration*)shmem;
86+
request = (struct json*)pgmoneta_json_get(payload, MANAGEMENT_CATEGORY_REQUEST);
87+
prefix = (char*)pgmoneta_json_get(request, MANAGEMENT_ARGUMENT_S3_PREFIX);
8488

8589
#ifdef HAVE_FREEBSD
8690
clock_gettime(CLOCK_MONOTONIC_FAST, &start_t);
@@ -100,7 +104,7 @@ pgmoneta_list_s3_objects(int client_fd, int server, uint8_t compression, uint8_t
100104
goto error;
101105
}
102106

103-
if (pgmoneta_art_insert(nodes, NODE_LABEL, (uintptr_t)"", ValueString))
107+
if (pgmoneta_art_insert(nodes, NODE_LABEL, (uintptr_t)(prefix != NULL ? prefix : ""), ValueString))
104108
{
105109
ec = MANAGEMENT_ERROR_LIST_S3_WORKFLOW;
106110
goto error;

src/libpgmoneta/se_s3.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,10 +2321,13 @@ s3_get_basepath(int server, char* identifier)
23212321
d = pgmoneta_append(d, "/");
23222322
}
23232323

2324-
d = pgmoneta_append(d, effective_base_dir);
2325-
if (!pgmoneta_ends_with(effective_base_dir, "/"))
2324+
if (strlen(effective_base_dir) > 0)
23262325
{
2327-
d = pgmoneta_append(d, "/");
2326+
d = pgmoneta_append(d, effective_base_dir);
2327+
if (!pgmoneta_ends_with(effective_base_dir, "/"))
2328+
{
2329+
d = pgmoneta_append(d, "/");
2330+
}
23282331
}
23292332

23302333
d = pgmoneta_append(d, config->common.servers[server].name);

0 commit comments

Comments
 (0)