mirror of
https://github.com/nginx/nginx.git
synced 2025-08-06 14:56:15 +08:00
use ngx_ext_rename_file() in PUT
This commit is contained in:
parent
3739151f5b
commit
81922511ae
@ -207,14 +207,12 @@ ngx_http_dav_handler(ngx_http_request_t *r)
|
|||||||
static void
|
static void
|
||||||
ngx_http_dav_put_handler(ngx_http_request_t *r)
|
ngx_http_dav_put_handler(ngx_http_request_t *r)
|
||||||
{
|
{
|
||||||
char *failed;
|
|
||||||
u_char *name;
|
|
||||||
size_t root;
|
size_t root;
|
||||||
time_t date;
|
time_t date;
|
||||||
ngx_err_t err;
|
|
||||||
ngx_str_t *temp, path;
|
ngx_str_t *temp, path;
|
||||||
ngx_uint_t status, not_found;
|
ngx_uint_t status;
|
||||||
ngx_file_info_t fi;
|
ngx_file_info_t fi;
|
||||||
|
ngx_ext_rename_file_t ext;
|
||||||
ngx_http_dav_loc_conf_t *dlcf;
|
ngx_http_dav_loc_conf_t *dlcf;
|
||||||
|
|
||||||
ngx_http_map_uri_to_path(r, &path, &root, 0);
|
ngx_http_map_uri_to_path(r, &path, &root, 0);
|
||||||
@ -247,94 +245,27 @@ ngx_http_dav_put_handler(ngx_http_request_t *r)
|
|||||||
|
|
||||||
dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
|
dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
|
||||||
|
|
||||||
#if !(NGX_WIN32)
|
ext.access = dlcf->access;
|
||||||
|
ext.time = -1;
|
||||||
if (ngx_change_file_access(temp->data, dlcf->access) == NGX_FILE_ERROR) {
|
ext.create_path = dlcf->create_full_put_path;
|
||||||
err = ngx_errno;
|
ext.delete = 1;
|
||||||
not_found = NGX_HTTP_INTERNAL_SERVER_ERROR;
|
ext.log = r->connection->log;
|
||||||
failed = ngx_change_file_access_n;
|
|
||||||
name = temp->data;
|
|
||||||
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (r->headers_in.date) {
|
if (r->headers_in.date) {
|
||||||
date = ngx_http_parse_time(r->headers_in.date->value.data,
|
date = ngx_http_parse_time(r->headers_in.date->value.data,
|
||||||
r->headers_in.date->value.len);
|
r->headers_in.date->value.len);
|
||||||
|
|
||||||
if (date != NGX_ERROR) {
|
if (date != NGX_ERROR) {
|
||||||
if (ngx_set_file_time(temp->data,
|
ext.time = date;
|
||||||
r->request_body->temp_file->file.fd, date)
|
ext.fd = r->request_body->temp_file->file.fd;
|
||||||
!= NGX_OK)
|
|
||||||
{
|
|
||||||
err = ngx_errno;
|
|
||||||
not_found = NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
||||||
failed = ngx_set_file_time_n;
|
|
||||||
name = temp->data;
|
|
||||||
|
|
||||||
goto failed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
not_found = NGX_HTTP_CONFLICT;
|
if (ngx_ext_rename_file(temp, &path, &ext) != NGX_OK) {
|
||||||
failed = ngx_rename_file_n;
|
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||||
name = path.data;
|
return;
|
||||||
|
|
||||||
if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) {
|
|
||||||
goto ok;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ngx_errno;
|
|
||||||
|
|
||||||
if (err == NGX_ENOENT) {
|
|
||||||
|
|
||||||
if (dlcf->create_full_put_path) {
|
|
||||||
err = ngx_create_full_path(path.data, ngx_dir_access(dlcf->access));
|
|
||||||
|
|
||||||
if (err == 0) {
|
|
||||||
if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) {
|
|
||||||
goto ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = ngx_errno;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (NGX_WIN32)
|
|
||||||
|
|
||||||
if (err == NGX_EEXIST) {
|
|
||||||
if (ngx_win32_rename_file(temp, &path, r->connection->log) == NGX_OK) {
|
|
||||||
|
|
||||||
if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) {
|
|
||||||
goto ok;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = ngx_errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
failed:
|
|
||||||
|
|
||||||
if (ngx_delete_file(temp->data) == NGX_FILE_ERROR) {
|
|
||||||
ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
|
|
||||||
ngx_delete_file_n " \"%s\" failed",
|
|
||||||
temp->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
ngx_http_finalize_request(r,
|
|
||||||
ngx_http_dav_error(r->connection->log, err,
|
|
||||||
not_found, failed, name));
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
ok:
|
|
||||||
|
|
||||||
if (status == NGX_HTTP_CREATED) {
|
if (status == NGX_HTTP_CREATED) {
|
||||||
if (ngx_http_dav_location(r, path.data) != NGX_OK) {
|
if (ngx_http_dav_location(r, path.data) != NGX_OK) {
|
||||||
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
Loading…
Reference in New Issue
Block a user