Klaus Demo nginx / d6711d3
use ngx_file_info() and test uniq if file is already open Igor Sysoev 13 years ago
1 changed file(s) with 40 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
134134 ngx_pool_cleanup_file_t *clnf;
135135 ngx_open_file_cache_cleanup_t *ofcln;
136136
137 of->fd = NGX_INVALID_FILE;
137138 of->err = 0;
138139
139140 if (cache == NULL) {
231232 of->test_dir = 1;
232233 }
233234
235 of->fd = file->fd;
236 of->uniq = file->uniq;
237
234238 rc = ngx_open_and_stat_file(name->data, of, pool->log);
235239
236240 if (rc != NGX_OK && (of->err == 0 || !of->errors)) {
255259 && of->mtime == file->mtime
256260 && of->size == file->size)
257261 {
258 if (ngx_close_file(of->fd) == NGX_FILE_ERROR) {
259 ngx_log_error(NGX_LOG_ALERT, pool->log, ngx_errno,
260 ngx_close_file_n " \"%s\" failed",
261 name->data);
262 if (of->fd != file->fd) {
263 if (ngx_close_file(of->fd) == NGX_FILE_ERROR) {
264 ngx_log_error(NGX_LOG_ALERT, pool->log, ngx_errno,
265 ngx_close_file_n " \"%s\" failed",
266 name->data);
267 }
268
269 of->fd = file->fd;
262270 }
263271
264 of->fd = file->fd;
265272 file->count++;
266273
267274 if (file->event) {
447454 ngx_fd_t fd;
448455 ngx_file_info_t fi;
449456
450 of->fd = NGX_INVALID_FILE;
451
452 if (of->test_dir) {
457 if (of->fd != NGX_INVALID_FILE || of->test_dir) {
453458
454459 if (ngx_file_info(name, &fi) == -1) {
455 of->err = ngx_errno;
456
457 return NGX_ERROR;
458 }
459
460 of->uniq = ngx_file_uniq(&fi);
461 of->mtime = ngx_file_mtime(&fi);
462 of->size = ngx_file_size(&fi);
463 of->is_dir = ngx_is_dir(&fi);
464 of->is_file = ngx_is_file(&fi);
465 of->is_link = ngx_is_link(&fi);
466 of->is_exec = ngx_is_exec(&fi);
467
468 if (of->is_dir) {
469 return NGX_OK;
460 goto failed;
461 }
462
463 if (of->fd != NGX_INVALID_FILE && of->uniq == ngx_file_uniq(&fi)) {
464 goto done;
465 }
466
467 if (of->test_dir && of->is_dir) {
468 goto done;
470469 }
471470 }
472471
473472 fd = ngx_open_file(name, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0);
474473
475474 if (fd == NGX_INVALID_FILE) {
476 of->err = ngx_errno;
477 return NGX_ERROR;
475 goto failed;
478476 }
479477
480478 if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) {
485483 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
486484 ngx_close_file_n " \"%s\" failed", name);
487485 }
486
487 of->fd = NGX_INVALID_FILE;
488488
489489 return NGX_ERROR;
490490 }
495495 ngx_close_file_n " \"%s\" failed", name);
496496 }
497497
498 fd = NGX_INVALID_FILE;
499 }
500
501 of->fd = fd;
498 of->fd = NGX_INVALID_FILE;
499
500 } else {
501 of->fd = fd;
502 }
503
504 done:
505
502506 of->uniq = ngx_file_uniq(&fi);
503507 of->mtime = ngx_file_mtime(&fi);
504508 of->size = ngx_file_size(&fi);
508512 of->is_exec = ngx_is_exec(&fi);
509513
510514 return NGX_OK;
515
516 failed:
517
518 of->fd = NGX_INVALID_FILE;
519 of->err = ngx_errno;
520
521 return NGX_ERROR;
511522 }
512523
513524