comparison src/core/ngx_file.c @ 272:29a6403156b0 NGINX_0_5_6

nginx 0.5.6 *) Change: now the ngx_http_index_module ignores all methods except the GET, HEAD, and POST methods. *) Feature: the ngx_http_limit_zone_module. *) Feature: the $binary_remote_addr variable. *) Feature: the "ssl_session_cache" directives of the ngx_http_ssl_module and ngx_imap_ssl_module. *) Feature: the DELETE method supports recursive removal. *) Bugfix: the byte-ranges were transferred incorrectly if the $r->sendfile() was used.
author Igor Sysoev <http://sysoev.ru>
date Tue, 09 Jan 2007 00:00:00 +0300
parents fbf2b2f66c9f
children c5c2b2883984
comparison
equal deleted inserted replaced
271:fcbee7dacf2b 272:29a6403156b0
416 #endif 416 #endif
417 } 417 }
418 418
419 return NGX_OK; 419 return NGX_OK;
420 } 420 }
421
422
423 ngx_int_t
424 ngx_walk_tree(ngx_tree_ctx_t *ctx, ngx_str_t *tree)
425 {
426 void *data, *prev;
427 u_char *p, *name;
428 size_t len;
429 ngx_int_t rc;
430 ngx_err_t err;
431 ngx_str_t file, buf;
432 ngx_dir_t dir;
433
434 buf.len = 0;
435 buf.data = NULL;
436
437 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0,
438 "walk tree \"%V\"", tree);
439
440 if (ngx_open_dir(tree, &dir) == NGX_ERROR) {
441 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno,
442 ngx_open_dir_n " \"%s\" failed", tree->data);
443 return NGX_ERROR;
444 }
445
446 prev = ctx->data;
447
448 if (ctx->size) {
449 data = ngx_alloc(ctx->size, ctx->log);
450 if (data == NULL) {
451 goto failed;
452 }
453
454 if (ctx->init_handler(data, prev) == NGX_ABORT) {
455 goto failed;
456 }
457
458 ctx->data = data;
459 }
460
461 for ( ;; ) {
462
463 ngx_set_errno(0);
464
465 if (ngx_read_dir(&dir) == NGX_ERROR) {
466 err = ngx_errno;
467
468 if (err == NGX_ENOMOREFILES) {
469 rc = NGX_OK;
470
471 } else {
472 ngx_log_error(NGX_LOG_CRIT, ctx->log, err,
473 ngx_read_dir_n " \"%s\" failed", tree->data);
474 rc = NGX_ERROR;
475 }
476
477 goto done;
478 }
479
480 len = ngx_de_namelen(&dir);
481 name = ngx_de_name(&dir);
482
483 ngx_log_debug2(NGX_LOG_DEBUG_CORE, ctx->log, 0,
484 "tree name %uz:\"%s\"", len, name);
485
486 if (len == 1 && name[0] == '.') {
487 continue;
488 }
489
490 if (len == 2 && name[0] == '.' && name[1] == '.') {
491 continue;
492 }
493
494 file.len = tree->len + 1 + len;
495
496 if (file.len + NGX_DIR_MASK_LEN > buf.len) {
497
498 if (buf.len) {
499 ngx_free(buf.data);
500 }
501
502 buf.len = tree->len + 1 + len + NGX_DIR_MASK_LEN;
503
504 buf.data = ngx_alloc(buf.len + 1, ctx->log);
505 if (buf.data == NULL) {
506 goto failed;
507 }
508 }
509
510 p = ngx_cpymem(buf.data, tree->data, tree->len);
511 *p++ = '/';
512 ngx_memcpy(p, name, len + 1);
513
514 file.data = buf.data;
515
516 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0,
517 "tree path \"%s\"", file.data);
518
519 if (!dir.valid_info) {
520 if (ngx_de_info(file.data, &dir) == NGX_FILE_ERROR) {
521 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno,
522 ngx_de_info_n " \"%s\" failed", file.data);
523 continue;
524 }
525 }
526
527 if (ngx_de_is_file(&dir)) {
528
529 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0,
530 "tree file \"%s\"", file.data);
531
532 if (ctx->file_handler(ctx, &file) == NGX_ABORT) {
533 goto failed;
534 }
535
536 } else if (ngx_de_is_dir(&dir)) {
537
538 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0,
539 "tree enter dir \"%s\"", file.data);
540
541 if (ctx->pre_tree_handler(ctx, &file) == NGX_ABORT) {
542 goto failed;
543 }
544
545 if (ngx_walk_tree(ctx, &file) == NGX_ABORT) {
546 goto failed;
547 }
548
549 if (ctx->post_tree_handler(ctx, &file) == NGX_ABORT) {
550 goto failed;
551 }
552
553 } else {
554
555 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0,
556 "tree special \"%s\"", file.data);
557
558 if (ctx->spec_handler(ctx, &file) == NGX_ABORT) {
559 goto failed;
560 }
561 }
562 }
563
564 failed:
565
566 rc = NGX_ABORT;
567
568 done:
569
570 if (buf.len) {
571 ngx_free(buf.data);
572 }
573
574 if (ctx->data) {
575 ngx_free(ctx->data);
576 ctx->data = prev;
577 }
578
579 if (ngx_close_dir(&dir) == NGX_ERROR) {
580 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno,
581 ngx_close_dir_n " \"%s\" failed", tree->data);
582 }
583
584 return rc;
585 }