From 0ebbb65e3042e8612399c3a7ded07480ef89db1a Mon Sep 17 00:00:00 2001 From: MARiA so cute <33935209+NathanFreeman@users.noreply.github.com> Date: Wed, 18 Aug 2021 17:09:05 +0800 Subject: [PATCH 1/3] Improve the success rate when use mkdir() in multiprocessing environment --- main/streams/plain_wrapper.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 793779c1bcab2..c8bb92b2bcd1a 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -1414,10 +1414,9 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i } while (true) { int ret = VCWD_MKDIR(buf, (mode_t) mode); - if (ret < 0) { - if (options & REPORT_ERRORS) { - php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); - } + if (ret < 0 && errno != EEXIST) { + /* stop running and issue a warning to client when ret < 0 and errno != EEXIST */ + php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); return 0; } @@ -1432,7 +1431,13 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i } } if (p == e || !replaced_slash) { - /* No more directories to create */ + /* No more directories to create */ + /* issue a warning to client when the last directory was created failed */ + if (ret < 0) { + if (options & REPORT_ERRORS) { + php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); + } + } return 1; } } From 632c004657d4e60339a84b955c5c1546266be1ce Mon Sep 17 00:00:00 2001 From: MARiA so cute <33935209+NathanFreeman@users.noreply.github.com> Date: Wed, 18 Aug 2021 17:28:46 +0800 Subject: [PATCH 2/3] add return 0 --- main/streams/plain_wrapper.c | 1 + 1 file changed, 1 insertion(+) diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index c8bb92b2bcd1a..df70e14c6d4f3 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -1437,6 +1437,7 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i if (options & REPORT_ERRORS) { php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); } + return 0; } return 1; } From cc7804d8dd92c49fe50d29861981ec1695a78b11 Mon Sep 17 00:00:00 2001 From: MARiA so cute <33935209+NathanFreeman@users.noreply.github.com> Date: Wed, 18 Aug 2021 17:44:34 +0800 Subject: [PATCH 3/3] use tab and keep the options & REPORT_ERRORS check here. --- main/streams/plain_wrapper.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index df70e14c6d4f3..f8c3d89aefa9d 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -1415,8 +1415,9 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i while (true) { int ret = VCWD_MKDIR(buf, (mode_t) mode); if (ret < 0 && errno != EEXIST) { - /* stop running and issue a warning to client when ret < 0 and errno != EEXIST */ - php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); + if (options & REPORT_ERRORS) { + php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); + } return 0; } @@ -1431,14 +1432,14 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i } } if (p == e || !replaced_slash) { - /* No more directories to create */ - /* issue a warning to client when the last directory was created failed */ - if (ret < 0) { - if (options & REPORT_ERRORS) { - php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); - } - return 0; - } + /* No more directories to create */ + /* issue a warning to client when the last directory was created failed */ + if (ret < 0) { + if (options & REPORT_ERRORS) { + php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); + } + return 0; + } return 1; } }