Mercurial > hg > nginx
comparison src/core/ngx_open_file_cache.c @ 2069:23930ccd2642
use ngx_file_info() and test uniq if file is already open
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 26 Jun 2008 16:10:13 +0000 |
parents | 67a29af877ed |
children | 92402cc8b3cf |
comparison
equal
deleted
inserted
replaced
2068:75a8d34459c5 | 2069:23930ccd2642 |
---|---|
133 ngx_pool_cleanup_t *cln; | 133 ngx_pool_cleanup_t *cln; |
134 ngx_cached_open_file_t *file; | 134 ngx_cached_open_file_t *file; |
135 ngx_pool_cleanup_file_t *clnf; | 135 ngx_pool_cleanup_file_t *clnf; |
136 ngx_open_file_cache_cleanup_t *ofcln; | 136 ngx_open_file_cache_cleanup_t *ofcln; |
137 | 137 |
138 of->fd = NGX_INVALID_FILE; | |
138 of->err = 0; | 139 of->err = 0; |
139 | 140 |
140 if (cache == NULL) { | 141 if (cache == NULL) { |
141 | 142 |
142 cln = ngx_pool_cleanup_add(pool, sizeof(ngx_pool_cleanup_file_t)); | 143 cln = ngx_pool_cleanup_add(pool, sizeof(ngx_pool_cleanup_file_t)); |
230 */ | 231 */ |
231 | 232 |
232 of->test_dir = 1; | 233 of->test_dir = 1; |
233 } | 234 } |
234 | 235 |
236 of->fd = file->fd; | |
237 of->uniq = file->uniq; | |
238 | |
235 rc = ngx_open_and_stat_file(name->data, of, pool->log); | 239 rc = ngx_open_and_stat_file(name->data, of, pool->log); |
236 | 240 |
237 if (rc != NGX_OK && (of->err == 0 || !of->errors)) { | 241 if (rc != NGX_OK && (of->err == 0 || !of->errors)) { |
238 goto failed; | 242 goto failed; |
239 } | 243 } |
254 | 258 |
255 if (of->uniq == file->uniq | 259 if (of->uniq == file->uniq |
256 && of->mtime == file->mtime | 260 && of->mtime == file->mtime |
257 && of->size == file->size) | 261 && of->size == file->size) |
258 { | 262 { |
259 if (ngx_close_file(of->fd) == NGX_FILE_ERROR) { | 263 if (of->fd != file->fd) { |
260 ngx_log_error(NGX_LOG_ALERT, pool->log, ngx_errno, | 264 if (ngx_close_file(of->fd) == NGX_FILE_ERROR) { |
261 ngx_close_file_n " \"%s\" failed", | 265 ngx_log_error(NGX_LOG_ALERT, pool->log, ngx_errno, |
262 name->data); | 266 ngx_close_file_n " \"%s\" failed", |
267 name->data); | |
268 } | |
269 | |
270 of->fd = file->fd; | |
263 } | 271 } |
264 | 272 |
265 of->fd = file->fd; | |
266 file->count++; | 273 file->count++; |
267 | 274 |
268 if (file->event) { | 275 if (file->event) { |
269 file->use_event = 1; | 276 file->use_event = 1; |
270 goto renew; | 277 goto renew; |
446 ngx_open_and_stat_file(u_char *name, ngx_open_file_info_t *of, ngx_log_t *log) | 453 ngx_open_and_stat_file(u_char *name, ngx_open_file_info_t *of, ngx_log_t *log) |
447 { | 454 { |
448 ngx_fd_t fd; | 455 ngx_fd_t fd; |
449 ngx_file_info_t fi; | 456 ngx_file_info_t fi; |
450 | 457 |
451 of->fd = NGX_INVALID_FILE; | 458 if (of->fd != NGX_INVALID_FILE || of->test_dir) { |
452 | |
453 if (of->test_dir) { | |
454 | 459 |
455 if (ngx_file_info(name, &fi) == -1) { | 460 if (ngx_file_info(name, &fi) == -1) { |
456 of->err = ngx_errno; | 461 goto failed; |
457 | 462 } |
458 return NGX_ERROR; | 463 |
459 } | 464 if (of->fd != NGX_INVALID_FILE && of->uniq == ngx_file_uniq(&fi)) { |
460 | 465 goto done; |
461 of->uniq = ngx_file_uniq(&fi); | 466 } |
462 of->mtime = ngx_file_mtime(&fi); | 467 |
463 of->size = ngx_file_size(&fi); | 468 if (of->test_dir && of->is_dir) { |
464 of->is_dir = ngx_is_dir(&fi); | 469 goto done; |
465 of->is_file = ngx_is_file(&fi); | |
466 of->is_link = ngx_is_link(&fi); | |
467 of->is_exec = ngx_is_exec(&fi); | |
468 | |
469 if (of->is_dir) { | |
470 return NGX_OK; | |
471 } | 470 } |
472 } | 471 } |
473 | 472 |
474 fd = ngx_open_file(name, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0); | 473 fd = ngx_open_file(name, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0); |
475 | 474 |
476 if (fd == NGX_INVALID_FILE) { | 475 if (fd == NGX_INVALID_FILE) { |
477 of->err = ngx_errno; | 476 goto failed; |
478 return NGX_ERROR; | |
479 } | 477 } |
480 | 478 |
481 if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) { | 479 if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) { |
482 ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, | 480 ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, |
483 ngx_fd_info_n " \"%s\" failed", name); | 481 ngx_fd_info_n " \"%s\" failed", name); |
484 | 482 |
485 if (ngx_close_file(fd) == NGX_FILE_ERROR) { | 483 if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
486 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | 484 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
487 ngx_close_file_n " \"%s\" failed", name); | 485 ngx_close_file_n " \"%s\" failed", name); |
488 } | 486 } |
487 | |
488 of->fd = NGX_INVALID_FILE; | |
489 | 489 |
490 return NGX_ERROR; | 490 return NGX_ERROR; |
491 } | 491 } |
492 | 492 |
493 if (ngx_is_dir(&fi)) { | 493 if (ngx_is_dir(&fi)) { |
494 if (ngx_close_file(fd) == NGX_FILE_ERROR) { | 494 if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
495 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | 495 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
496 ngx_close_file_n " \"%s\" failed", name); | 496 ngx_close_file_n " \"%s\" failed", name); |
497 } | 497 } |
498 | 498 |
499 fd = NGX_INVALID_FILE; | 499 of->fd = NGX_INVALID_FILE; |
500 } | 500 |
501 | 501 } else { |
502 of->fd = fd; | 502 of->fd = fd; |
503 } | |
504 | |
505 done: | |
506 | |
503 of->uniq = ngx_file_uniq(&fi); | 507 of->uniq = ngx_file_uniq(&fi); |
504 of->mtime = ngx_file_mtime(&fi); | 508 of->mtime = ngx_file_mtime(&fi); |
505 of->size = ngx_file_size(&fi); | 509 of->size = ngx_file_size(&fi); |
506 of->is_dir = ngx_is_dir(&fi); | 510 of->is_dir = ngx_is_dir(&fi); |
507 of->is_file = ngx_is_file(&fi); | 511 of->is_file = ngx_is_file(&fi); |
508 of->is_link = ngx_is_link(&fi); | 512 of->is_link = ngx_is_link(&fi); |
509 of->is_exec = ngx_is_exec(&fi); | 513 of->is_exec = ngx_is_exec(&fi); |
510 | 514 |
511 return NGX_OK; | 515 return NGX_OK; |
516 | |
517 failed: | |
518 | |
519 of->fd = NGX_INVALID_FILE; | |
520 of->err = ngx_errno; | |
521 | |
522 return NGX_ERROR; | |
512 } | 523 } |
513 | 524 |
514 | 525 |
515 /* | 526 /* |
516 * we ignore any possible event setting error and | 527 * we ignore any possible event setting error and |