Klaus Demo nginx / 9e0d123
Dav: changed ngx_copy_file() to preserve access and mtime. This fixes wrong permissions and file time after cross-device MOVE in the DAV module (ticket #1577). Broken in 8101d9101ed8 (0.8.9) when cross-device copying was introduced in ngx_ext_rename_file(). With this change, ngx_copy_file() always calls ngx_set_file_time(), either with the time provided, or with the time from the original file. This is considered acceptable given that copying the file is costly anyway, and optimizing cases when we do not need to preserve time will require interface changes. Maxim Dounin 3 years ago
1 changed file(s) with 13 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
795795 {
796796 char *buf;
797797 off_t size;
798 time_t time;
798799 size_t len;
799800 ssize_t n;
800801 ngx_fd_t fd, nfd;
801802 ngx_int_t rc;
803 ngx_uint_t access;
802804 ngx_file_info_t fi;
803805
804806 rc = NGX_ERROR;
813815 goto failed;
814816 }
815817
816 if (cf->size != -1) {
818 if (cf->size != -1 && cf->access != 0 && cf->time != -1) {
817819 size = cf->size;
820 access = cf->access;
821 time = cf->time;
818822
819823 } else {
820824 if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) {
824828 goto failed;
825829 }
826830
827 size = ngx_file_size(&fi);
831 size = (cf->size != -1) ? cf->size : ngx_file_size(&fi);
832 access = cf->access ? cf->access : ngx_file_access(&fi);
833 time = (cf->time != -1) ? cf->time : ngx_file_mtime(&fi);
828834 }
829835
830836 len = cf->buf_size ? cf->buf_size : 65536;
838844 goto failed;
839845 }
840846
841 nfd = ngx_open_file(to, NGX_FILE_WRONLY, NGX_FILE_TRUNCATE, cf->access);
847 nfd = ngx_open_file(to, NGX_FILE_WRONLY, NGX_FILE_TRUNCATE, access);
842848
843849 if (nfd == NGX_INVALID_FILE) {
844850 ngx_log_error(NGX_LOG_CRIT, cf->log, ngx_errno,
885891 size -= n;
886892 }
887893
888 if (cf->time != -1) {
889 if (ngx_set_file_time(to, nfd, cf->time) != NGX_OK) {
890 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
891 ngx_set_file_time_n " \"%s\" failed", to);
892 goto failed;
893 }
894 if (ngx_set_file_time(to, nfd, time) != NGX_OK) {
895 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
896 ngx_set_file_time_n " \"%s\" failed", to);
897 goto failed;
894898 }
895899
896900 rc = NGX_OK;