From 0ddc1978eef2e89f2a4537a31421930c3252fa5e Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Thu, 20 Aug 2009 13:41:32 +0000 Subject: [PATCH] fix copy failure logging and stale files removal, introduced in r3025 --- src/core/ngx_file.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c index eb340a22a..7adee6db3 100644 --- a/src/core/ngx_file.c +++ b/src/core/ngx_file.c @@ -615,24 +615,33 @@ ngx_ext_rename_file(ngx_str_t *src, ngx_str_t *to, ngx_ext_rename_file_t *ext) if (ngx_copy_file(src->data, name, &cf) == NGX_OK) { - if (ngx_rename_file(name, to->data) == NGX_FILE_ERROR) { + if (ngx_rename_file(name, to->data) != NGX_FILE_ERROR) { ngx_free(name); - goto failed; + + if (ngx_delete_file(src->data) == NGX_FILE_ERROR) { + ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno, + ngx_delete_file_n " \"%s\" failed", + src->data); + return NGX_ERROR; + } + + return NGX_OK; } - ngx_free(name); + ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno, + ngx_rename_file_n " \"%s\" to \"%s\" failed", + name, to->data); - if (ngx_delete_file(src->data) == NGX_FILE_ERROR) { + if (ngx_delete_file(name) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno, - ngx_delete_file_n " \"%s\" failed", src->data); + ngx_delete_file_n " \"%s\" failed", name); - return NGX_ERROR; } - - return NGX_OK; } ngx_free(name); + + err = 0; } failed: