]> git.kaiwu.me - nginx.git/commitdiff
Dav: fixed ngx_copy_file() to truncate destination file.
authorMaxim Dounin <mdounin@mdounin.ru>
Tue, 31 Jul 2018 23:11:58 +0000 (02:11 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Tue, 31 Jul 2018 23:11:58 +0000 (02:11 +0300)
Previously, ngx_open_file(NGX_FILE_CREATE_OR_OPEN) was used, resulting
in destination file being partially rewritten if exists.  Notably,
this affected WebDAV COPY command (ticket #1576).

src/core/ngx_file.c

index 3a94089decda84a74c0a0d71529dd3a2e8f20bce..57ad042debaa2d3722760ed64cdd6f98ce246828 100644 (file)
@@ -839,8 +839,7 @@ ngx_copy_file(u_char *from, u_char *to, ngx_copy_file_t *cf)
         goto failed;
     }
 
-    nfd = ngx_open_file(to, NGX_FILE_WRONLY, NGX_FILE_CREATE_OR_OPEN,
-                        cf->access);
+    nfd = ngx_open_file(to, NGX_FILE_WRONLY, NGX_FILE_TRUNCATE, cf->access);
 
     if (nfd == NGX_INVALID_FILE) {
         ngx_log_error(NGX_LOG_CRIT, cf->log, ngx_errno,