comparison src/core/ngx_open_file_cache.c @ 2756:09cab3f8d92e

*) of.test_only to not open file if only stat() is enough *) of.failed to return exact name of failed syscall
author Igor Sysoev <igor@sysoev.ru>
date Mon, 27 Apr 2009 09:55:53 +0000
parents 367b29612a00
children 4bd7825fab80
comparison
equal deleted inserted replaced
2755:a65976a205a5 2756:09cab3f8d92e
128 ngx_open_file_info_t *of, ngx_pool_t *pool) 128 ngx_open_file_info_t *of, ngx_pool_t *pool)
129 { 129 {
130 time_t now; 130 time_t now;
131 uint32_t hash; 131 uint32_t hash;
132 ngx_int_t rc; 132 ngx_int_t rc;
133 ngx_file_info_t fi;
133 ngx_pool_cleanup_t *cln; 134 ngx_pool_cleanup_t *cln;
134 ngx_cached_open_file_t *file; 135 ngx_cached_open_file_t *file;
135 ngx_pool_cleanup_file_t *clnf; 136 ngx_pool_cleanup_file_t *clnf;
136 ngx_open_file_cache_cleanup_t *ofcln; 137 ngx_open_file_cache_cleanup_t *ofcln;
137 138
138 of->fd = NGX_INVALID_FILE; 139 of->fd = NGX_INVALID_FILE;
139 of->err = 0; 140 of->err = 0;
140 141
141 if (cache == NULL) { 142 if (cache == NULL) {
143
144 if (of->test_only) {
145
146 if (ngx_file_info(name->data, &fi) == -1) {
147 of->err = ngx_errno;
148 of->failed = ngx_file_info_n;
149 return NGX_ERROR;
150 }
151
152 of->uniq = ngx_file_uniq(&fi);
153 of->mtime = ngx_file_mtime(&fi);
154 of->size = ngx_file_size(&fi);
155 of->is_dir = ngx_is_dir(&fi);
156 of->is_file = ngx_is_file(&fi);
157 of->is_link = ngx_is_link(&fi);
158 of->is_exec = ngx_is_exec(&fi);
159
160 return NGX_OK;
161 }
142 162
143 cln = ngx_pool_cleanup_add(pool, sizeof(ngx_pool_cleanup_file_t)); 163 cln = ngx_pool_cleanup_add(pool, sizeof(ngx_pool_cleanup_file_t));
144 if (cln == NULL) { 164 if (cln == NULL) {
145 return NGX_ERROR; 165 return NGX_ERROR;
146 } 166 }
442 ngx_file_info_t fi; 462 ngx_file_info_t fi;
443 463
444 if (of->fd != NGX_INVALID_FILE) { 464 if (of->fd != NGX_INVALID_FILE) {
445 465
446 if (ngx_file_info(name, &fi) == -1) { 466 if (ngx_file_info(name, &fi) == -1) {
467 of->failed = ngx_file_info_n;
447 goto failed; 468 goto failed;
448 } 469 }
449 470
450 if (of->uniq == ngx_file_uniq(&fi)) { 471 if (of->uniq == ngx_file_uniq(&fi)) {
451 goto done; 472 goto done;
452 } 473 }
453 474
454 } else if (of->test_dir) { 475 } else if (of->test_dir) {
455 476
456 if (ngx_file_info(name, &fi) == -1) { 477 if (ngx_file_info(name, &fi) == -1) {
478 of->failed = ngx_file_info_n;
457 goto failed; 479 goto failed;
458 } 480 }
459 481
460 if (ngx_is_dir(&fi)) { 482 if (ngx_is_dir(&fi)) {
461 goto done; 483 goto done;
469 fd = ngx_open_file(name, NGX_FILE_APPEND, NGX_FILE_CREATE_OR_OPEN, 491 fd = ngx_open_file(name, NGX_FILE_APPEND, NGX_FILE_CREATE_OR_OPEN,
470 NGX_FILE_DEFAULT_ACCESS); 492 NGX_FILE_DEFAULT_ACCESS);
471 } 493 }
472 494
473 if (fd == NGX_INVALID_FILE) { 495 if (fd == NGX_INVALID_FILE) {
496 of->failed = ngx_open_file_n;
474 goto failed; 497 goto failed;
475 } 498 }
476 499
477 if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) { 500 if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) {
478 ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, 501 ngx_log_error(NGX_LOG_CRIT, log, ngx_errno,