summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2023-02-23 20:49:50 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2023-02-23 20:49:50 +0300
commit94d8cea620e0abc67f4d0fe9aaf6170f39529c8c (patch)
tree730ef1923d84ad8f7e4d73e8b69551b84bcc4873
parentf8075f1ef5106c9f0d894f83cfa81dbb9f5ce2da (diff)
downloadnginx-94d8cea620e0abc67f4d0fe9aaf6170f39529c8c.tar.gz
Win32: reworked ngx_win32_rename_file() to check errors.
Previously, ngx_win32_rename_file() retried on all errors returned by MoveFile() to a temporary name. It only make sense, however, to retry when the destination file already exists, similarly to the condition when ngx_win32_rename_file() is called. Retrying on other errors is meaningless and might result in an infinite loop.
-rw-r--r--src/os/win32/ngx_files.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c
index 2e0e5faa9..48075b4c9 100644
--- a/src/os/win32/ngx_files.c
+++ b/src/os/win32/ngx_files.c
@@ -236,10 +236,16 @@ ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log)
break;
}
- collision = 1;
+ err = ngx_errno;
- ngx_log_error(NGX_LOG_CRIT, log, ngx_errno,
+ if (err == NGX_EEXIST || err == NGX_EEXIST_FILE) {
+ collision = 1;
+ continue;
+ }
+
+ ngx_log_error(NGX_LOG_CRIT, log, err,
"MoveFile() \"%s\" to \"%s\" failed", to->data, name);
+ goto failed;
}
if (MoveFile((const char *) from->data, (const char *) to->data) == 0) {
@@ -254,6 +260,8 @@ ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log)
"DeleteFile() \"%s\" failed", name);
}
+failed:
+
/* mutex_unlock() */
ngx_free(name);