From 8ad498b33585199716f535b32938ec12d9ce9a55 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Tue, 4 Jun 2024 19:47:06 +0900 Subject: [PATCH] out_s3: Unify nested directory creations Signed-off-by: Hiroshi Hatake --- plugins/out_s3/s3.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/plugins/out_s3/s3.c b/plugins/out_s3/s3.c index bfabc64a6cd..b503504a196 100644 --- a/plugins/out_s3/s3.c +++ b/plugins/out_s3/s3.c @@ -1349,7 +1349,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; @@ -1432,13 +1444,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; } } @@ -1624,7 +1633,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; } }