# HG changeset patch
# User Mindaugas Rasiukevicius <rmind@netbsd.org>
# Date 1447778549 0
#      Tue Nov 17 16:42:29 2015 +0000
# Branch ngx_copy_file
# Node ID a71fdd78cb5ea1d51492ec7220dc95072b803d94
# Parent  4221623f2e4622de1b5794f82111a13f43207b5a
ngx_copy_file: remove the destination file on failure.

diff -r 4221623f2e46 -r a71fdd78cb5e src/core/ngx_file.c
--- a/src/core/ngx_file.c	Tue Nov 17 17:50:57 2015 +0300
+++ b/src/core/ngx_file.c	Tue Nov 17 16:42:29 2015 +0000
@@ -872,6 +872,11 @@ failed:
             ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
                           ngx_close_file_n " \"%s\" failed", to);
         }
+
+        if (rc != NGX_OK && ngx_delete_file(to) == NGX_FILE_ERROR) {
+            ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
+                          ngx_delete_file_n " \"%s\" failed", to);
+        }
     }
 
     if (fd != NGX_INVALID_FILE) {
