fix Win32 error messages when an temporary file replaces an existent file:

*) do not rename an already renamed file
*) now ngx_win32_rename_file() returns error code
*) do not log failure inside ngx_win32_rename_file()
This commit is contained in:
Igor Sysoev 2009-12-15 13:47:02 +00:00
parent 29b5a13784
commit 44be39475c
3 changed files with 8 additions and 24 deletions

View File

@ -591,17 +591,7 @@ ngx_ext_rename_file(ngx_str_t *src, ngx_str_t *to, ngx_ext_rename_file_t *ext)
#if (NGX_WIN32)
if (err == NGX_EEXIST) {
if (ngx_win32_rename_file(src, to, ext->log) == NGX_OK) {
if (ngx_rename_file(src->data, to->data) != NGX_FILE_ERROR) {
return NGX_OK;
}
err = ngx_errno;
} else {
err = 0;
}
err = ngx_win32_rename_file(src, to, ext->log);
}
#endif

View File

@ -187,17 +187,17 @@ ngx_write_console(ngx_fd_t fd, void *buf, size_t size)
}
ngx_int_t
ngx_err_t
ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log)
{
u_char *name;
ngx_int_t rc;
ngx_err_t err;
ngx_uint_t collision;
ngx_atomic_uint_t num;
name = ngx_alloc(to->len + 1 + 10 + 1 + sizeof("DELETE"), log);
if (name == NULL) {
return NGX_ERROR;
return NGX_ENOMEM;
}
ngx_memcpy(name, to->data, to->len);
@ -222,10 +222,10 @@ ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log)
}
if (MoveFile((const char *) from->data, (const char *) to->data) == 0) {
rc = NGX_ERROR;
err = ngx_errno;
} else {
rc = NGX_OK;
err = 0;
}
if (DeleteFile((const char *) name) == 0) {
@ -233,17 +233,11 @@ ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log)
"DeleteFile() \"%s\" failed", name);
}
if (rc == NGX_ERROR) {
ngx_log_error(NGX_LOG_CRIT, log, ngx_errno,
"MoveFile() \"%s\" to \"%s\" failed",
from->data, to->data);
}
/* mutex_unlock() */
ngx_free(name);
return rc;
return err;
}

View File

@ -111,7 +111,7 @@ ssize_t ngx_write_console(ngx_fd_t fd, void *buf, size_t size);
#define ngx_rename_file(o, n) MoveFile((const char *) o, (const char *) n)
#define ngx_rename_file_n "MoveFile()"
ngx_int_t ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log);
ngx_err_t ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log);