Klaus Demo nginx / 524f54f
use ngx_ext_rename_file() for single file MOVE Igor Sysoev 13 years ago
6 changed file(s) with 50 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
486486
487487 #if !(NGX_WIN32)
488488
489 if (ngx_change_file_access(src->data, ext->access) == NGX_FILE_ERROR) {
490 ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno,
491 ngx_change_file_access_n " \"%s\" failed", src->data);
492 err = 0;
493 goto failed;
489 if (ext->access) {
490 if (ngx_change_file_access(src->data, ext->access) == NGX_FILE_ERROR) {
491 ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno,
492 ngx_change_file_access_n " \"%s\" failed", src->data);
493 err = 0;
494 goto failed;
495 }
494496 }
495497
496498 #endif
516518 goto failed;
517519 }
518520
519 err = ngx_create_full_path(to->data, ngx_dir_access(ext->access));
521 err = ngx_create_full_path(to->data, ngx_dir_access(ext->path_access));
520522
521523 if (err) {
522524 ngx_log_error(NGX_LOG_CRIT, ext->log, err,
560562 }
561563 }
562564
563 if (err) {
565 if (err && ext->log_rename_error) {
564566 ngx_log_error(NGX_LOG_CRIT, ext->log, err,
565567 ngx_rename_file_n " \"%s\" to \"%s\" failed",
566568 src->data, to->data);
567569 }
570
571 ext->rename_error = err;
568572
569573 return NGX_ERROR;
570574 }
5959
6060 typedef struct {
6161 ngx_uint_t access;
62 ngx_uint_t path_access;
6263 time_t time;
6364 ngx_fd_t fd;
65 ngx_err_t rename_error;
6466
6567 unsigned create_path:1;
6668 unsigned delete_file:1;
69 unsigned log_rename_error:1;
6770
6871 ngx_log_t *log;
6972 } ngx_ext_rename_file_t;
245245 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
246246
247247 ext.access = dlcf->access;
248 ext.path_access = dlcf->access;
248249 ext.time = -1;
249250 ext.create_path = dlcf->create_full_put_path;
250251 ext.delete_file = 1;
252 ext.log_rename_error = 1;
251253 ext.log = r->connection->log;
252254
253255 if (r->headers_in.date) {
520522 ngx_tree_ctx_t tree;
521523 ngx_file_info_t fi;
522524 ngx_table_elt_t *dest, *over;
525 ngx_ext_rename_file_t ext;
523526 ngx_http_dav_copy_ctx_t copy;
524527 ngx_http_dav_loc_conf_t *dlcf;
525528
780783 } else {
781784
782785 if (r->method == NGX_HTTP_MOVE) {
783 if (ngx_rename_file(path.data, copy.path.data) != NGX_FILE_ERROR) {
786
787 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
788
789 ext.access = 0;
790 ext.path_access = dlcf->access;
791 ext.time = -1;
792 ext.create_path = 1;
793 ext.delete_file = 0;
794 ext.log_rename_error = 0;
795 ext.log = r->connection->log;
796
797 if (ngx_ext_rename_file(&path, &copy.path, &ext) == NGX_OK) {
784798 return NGX_HTTP_NO_CONTENT;
799 }
800
801 if (ext.rename_error != NGX_EXDEV) {
802
803 if (ext.rename_error) {
804 ngx_log_error(NGX_LOG_CRIT, r->connection->log,
805 ext.rename_error,
806 ngx_rename_file_n " \"%s\" to \"%s\" failed",
807 path.data, copy.path.data);
808 }
809
810 return NGX_HTTP_INTERNAL_SERVER_ERROR;
785811 }
786812 }
787813
22872287 }
22882288
22892289 ext.access = u->conf->store_access;
2290 ext.path_access = u->conf->store_access;
22902291 ext.time = -1;
22912292 ext.create_path = 1;
22922293 ext.delete_file = 1;
2294 ext.log_rename_error = 1;
22932295 ext.log = r->connection->log;
22942296
22952297 if (u->headers_in.last_modified) {
2222 #define NGX_EACCES EACCES
2323 #define NGX_EBUSY EBUSY
2424 #define NGX_EEXIST EEXIST
25 #define NGX_EXDEV EXDEV
2526 #define NGX_ENOTDIR ENOTDIR
2627 #define NGX_EISDIR EISDIR
2728 #define NGX_EINVAL EINVAL
2222 #define NGX_ENOENT ERROR_FILE_NOT_FOUND
2323 #define NGX_ENOMEM ERROR_NOT_ENOUGH_MEMORY
2424 #define NGX_EACCES ERROR_ACCESS_DENIED
25 #if 0
26 #define NGX_EEXIST ERROR_FILE_EXISTS
27 #endif
25 /* it's seems that ERROR_FILE_EXISTS is not appropriate error code */
2826 #define NGX_EEXIST ERROR_ALREADY_EXISTS
27 /*
28 * could not found cross volume directory move error code,
29 * so use ERROR_WRONG_DISK as stub one
30 */
31 #define NGX_EXDEV ERROR_WRONG_DISK
2932 #define NGX_ENOTDIR ERROR_PATH_NOT_FOUND
3033 #define NGX_EISDIR ERROR_CANNOT_MAKE
3134 #define NGX_ENOSPC ERROR_DISK_FULL