Skip to content

Commit

Permalink
out_s3: Unify nested directory creations
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Jun 4, 2024
1 parent d3e2aa3 commit 1e7fba1
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions plugins/out_s3/s3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,9 @@ static int s3_mkdir(struct flb_s3 *ctx, const char *dir, mode_t mode)
{
struct stat st;
char *dup_dir = NULL;
#ifdef FLB_SYSTEM_WINDOWS
char path[PATH_MAX];
#endif
#ifdef FLB_SYSTEM_MACOS
char *parent_dir = NULL;
#endif
Expand All @@ -1349,7 +1352,19 @@ static int s3_mkdir(struct flb_s3 *ctx, const char *dir, mode_t mode)
return 0;
}

#if FLB_SYSTEM_MACOS
#ifdef FLB_SYSTEM_WINDOWS
(void) mode;

if (_fullpath(path, dir, MAX_PATH) == NULL) {
return -1;
}

if (SHCreateDirectoryExA(NULL, path, NULL) != ERROR_SUCCESS) {
return -1;
}

return 0;
#elif FLB_SYSTEM_MACOS
dup_dir = strdup(dir);
if (!dup_dir) {
return -1;
Expand Down Expand Up @@ -1432,13 +1447,10 @@ static flb_sds_t create_parquest_processing_dir(struct flb_s3 *ctx)

ret = s3_is_dir(path_buf);
if (ret == -1) {
if (_fullpath(work_dir, path_buf, MAX_PATH) == NULL) {
ret = -1;
goto error;
}

if (SHCreateDirectoryExA(NULL, work_dir, NULL) != ERROR_SUCCESS) {
ret = -1;
flb_plg_debug(ctx->ins, "creating process dir %s.", ctx->parquet_process_dir);
if (s3_mkdir(ctx, ctx->parquet_process_dir, 0755) == -1) {
flb_plg_error(ctx->ins, "ensuring existence of process dir %s is failed.",
ctx->parquet_process_dir);
goto error;
}
}
Expand Down Expand Up @@ -1624,7 +1636,9 @@ static int create_tmpfile(struct flb_s3 *ctx, char *file_path, char *template, s
if (ret == -1) {
flb_plg_debug(ctx->ins, "creating process dir %s.", ctx->parquet_process_dir);
if (s3_mkdir(ctx, ctx->parquet_process_dir, 0755) == -1) {
flb_plg_error(ctx->ins, "ensuring existence of process dir %s is failed.", ctx->parquet_process_dir);
flb_plg_error(ctx->ins, "ensuring existence of process dir %s is failed.",
ctx->parquet_process_dir);
goto error;
}
}

Expand Down

0 comments on commit 1e7fba1

Please sign in to comment.