54
55
static ngx_int_t ngx_http_dav_copy_tree_file(ngx_tree_ctx_t *ctx,
56
static ngx_int_t ngx_http_dav_copy_file(ngx_tree_ctx_t *ctx, u_char *from,
59
58
static ngx_int_t ngx_http_dav_depth(ngx_http_request_t *r, ngx_int_t dflt);
60
59
static ngx_int_t ngx_http_dav_error(ngx_log_t *log, ngx_err_t err,
166
160
if (r->uri.data[r->uri.len - 1] == '/') {
167
161
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
168
"can not PUT to a collection");
162
"cannot PUT to a collection");
169
163
return NGX_HTTP_CONFLICT;
215
209
ngx_ext_rename_file_t ext;
216
210
ngx_http_dav_loc_conf_t *dlcf;
212
if (r->request_body == NULL || r->request_body->temp_file == NULL) {
213
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
218
217
ngx_http_map_uri_to_path(r, &path, &root, 0);
220
221
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
221
222
"http put filename: \"%s\"", path.data);
223
224
temp = &r->request_body->temp_file->file.name;
225
if (ngx_file_info(path.data, &fi) == -1) {
226
if (ngx_file_info(path.data, &fi) == NGX_FILE_ERROR) {
226
227
status = NGX_HTTP_CREATED;
325
327
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
326
328
"http delete filename: \"%s\"", path.data);
328
if (ngx_file_info(path.data, &fi) == -1) {
330
if (ngx_link_info(path.data, &fi) == NGX_FILE_ERROR) {
331
333
rc = (err == NGX_ENOTDIR) ? NGX_HTTP_CONFLICT : NGX_HTTP_NOT_FOUND;
333
335
return ngx_http_dav_error(r->connection->log, err,
334
rc, ngx_file_info_n, path.data);
336
rc, ngx_link_info_n, path.data);
337
339
if (ngx_is_dir(&fi)) {
490
492
p = ngx_http_map_uri_to_path(r, &path, &root, 0);
494
497
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
495
498
"http mkcol path: \"%s\"", path.data);
516
519
size_t len, root;
518
521
ngx_int_t rc, depth;
519
ngx_uint_t overwrite, slash, dir;
522
ngx_uint_t overwrite, slash, dir, flags;
523
ngx_str_t path, uri, duri, args;
521
524
ngx_tree_ctx_t tree;
522
526
ngx_file_info_t fi;
523
527
ngx_table_elt_t *dest, *over;
528
ngx_ext_rename_file_t ext;
524
529
ngx_http_dav_copy_ctx_t copy;
525
530
ngx_http_dav_loc_conf_t *dlcf;
676
694
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
677
695
"http copy to: \"%s\"", copy.path.data);
679
if (ngx_file_info(copy.path.data, &fi) == -1) {
697
if (ngx_link_info(copy.path.data, &fi) == NGX_FILE_ERROR) {
682
700
if (err != NGX_ENOENT) {
683
701
return ngx_http_dav_error(r->connection->log, err,
684
NGX_HTTP_NOT_FOUND, ngx_file_info_n,
702
NGX_HTTP_NOT_FOUND, ngx_link_info_n,
710
728
dir = ngx_is_dir(&fi);
713
if (ngx_file_info(path.data, &fi) == -1) {
731
if (ngx_link_info(path.data, &fi) == NGX_FILE_ERROR) {
714
732
return ngx_http_dav_error(r->connection->log, ngx_errno,
715
NGX_HTTP_NOT_FOUND, ngx_file_info_n,
733
NGX_HTTP_NOT_FOUND, ngx_link_info_n,
783
801
if (r->method == NGX_HTTP_MOVE) {
784
if (ngx_rename_file(path.data, copy.path.data) != NGX_FILE_ERROR) {
803
dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
806
ext.path_access = dlcf->access;
810
ext.log = r->connection->log;
812
if (ngx_ext_rename_file(&path, ©.path, &ext) == NGX_OK) {
785
813
return NGX_HTTP_NO_CONTENT;
816
return NGX_HTTP_INTERNAL_SERVER_ERROR;
789
819
dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
791
tree.size = ngx_file_size(&fi);
792
tree.mtime = ngx_file_mtime(&fi);
793
tree.access = dlcf->access;
794
tree.log = r->connection->log;
796
if (ngx_http_dav_copy_file(&tree, path.data, copy.path.data) == NGX_OK)
798
if (r->method == NGX_HTTP_MOVE) {
799
rc = ngx_http_dav_delete_path(r, &path, 0);
821
cf.size = ngx_file_size(&fi);
823
cf.access = dlcf->access;
824
cf.time = ngx_file_mtime(&fi);
825
cf.log = r->connection->log;
827
if (ngx_copy_file(path.data, copy.path.data, &cf) == NGX_OK) {
806
828
return NGX_HTTP_NO_CONTENT;
936
959
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->log, 0,
937
960
"http copy file to: \"%s\"", file);
939
(void) ngx_http_dav_copy_file(ctx, path->data, file);
964
cf.access = ctx->access;
965
cf.time = ctx->mtime;
968
(void) ngx_copy_file(path->data, file, &cf);
948
ngx_http_dav_copy_file(ngx_tree_ctx_t *ctx, u_char *from, u_char *to)
954
u_char buf[NGX_HTTP_DAV_COPY_BLOCK];
956
fd = ngx_open_file(from, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0);
958
if (fd == NGX_INVALID_FILE) {
959
(void) ngx_http_dav_error(ctx->log, ngx_errno, 0, ngx_open_file_n,
964
cfd = ngx_open_file(to, NGX_FILE_WRONLY, NGX_FILE_CREATE_OR_OPEN,
969
if (cfd == NGX_INVALID_FILE) {
970
(void) ngx_http_dav_error(ctx->log, ngx_errno, 0, ngx_open_file_n, to);
974
for (size = ctx->size; size > 0; size -= n) {
976
n = ngx_read_fd(fd, buf, NGX_HTTP_DAV_COPY_BLOCK);
978
if (n == NGX_FILE_ERROR) {
979
ngx_log_error(NGX_LOG_ALERT, ctx->log, ngx_errno,
980
ngx_read_fd_n " \"%s\" failed", from);
984
if (ngx_write_fd(cfd, buf, n) == NGX_FILE_ERROR) {
985
ngx_log_error(NGX_LOG_ALERT, ctx->log, ngx_errno,
986
ngx_write_fd_n " \"%s\" failed", to);
991
if (ngx_set_file_time(to, cfd, ctx->mtime) != NGX_OK) {
992
ngx_log_error(NGX_LOG_ALERT, ctx->log, ngx_errno,
993
ngx_set_file_time_n " \"%s\" failed", to);
997
if (ngx_close_file(cfd) == NGX_FILE_ERROR) {
998
ngx_log_error(NGX_LOG_ALERT, ctx->log, ngx_errno,
999
ngx_close_file_n " \"%s\" failed", to);
1007
if (ngx_close_file(fd) == NGX_FILE_ERROR) {
1008
ngx_log_error(NGX_LOG_ALERT, ctx->log, ngx_errno,
1009
ngx_close_file_n " \"%s\" failed", from);
1017
977
ngx_http_dav_depth(ngx_http_request_t *r, ngx_int_t dflt)
1019
979
ngx_table_elt_t *depth;