time_t now;
uint32_t hash;
ngx_int_t rc;
+ ngx_file_info_t fi;
ngx_pool_cleanup_t *cln;
ngx_cached_open_file_t *file;
ngx_pool_cleanup_file_t *clnf;
if (cache == NULL) {
+ if (of->test_only) {
+
+ if (ngx_file_info(name->data, &fi) == -1) {
+ of->err = ngx_errno;
+ of->failed = ngx_file_info_n;
+ return NGX_ERROR;
+ }
+
+ of->uniq = ngx_file_uniq(&fi);
+ of->mtime = ngx_file_mtime(&fi);
+ of->size = ngx_file_size(&fi);
+ of->is_dir = ngx_is_dir(&fi);
+ of->is_file = ngx_is_file(&fi);
+ of->is_link = ngx_is_link(&fi);
+ of->is_exec = ngx_is_exec(&fi);
+
+ return NGX_OK;
+ }
+
cln = ngx_pool_cleanup_add(pool, sizeof(ngx_pool_cleanup_file_t));
if (cln == NULL) {
return NGX_ERROR;
if (of->fd != NGX_INVALID_FILE) {
if (ngx_file_info(name, &fi) == -1) {
+ of->failed = ngx_file_info_n;
goto failed;
}
} else if (of->test_dir) {
if (ngx_file_info(name, &fi) == -1) {
+ of->failed = ngx_file_info_n;
goto failed;
}
}
if (fd == NGX_INVALID_FILE) {
+ of->failed = ngx_open_file_n;
goto failed;
}
time_t mtime;
off_t size;
off_t directio;
+
ngx_err_t err;
+ char *failed;
time_t valid;
ngx_uint_t min_uses;
unsigned test_dir:1;
+ unsigned test_only:1;
unsigned log:1;
unsigned errors:1;
unsigned events:1;
if (rc != NGX_HTTP_NOT_FOUND || clcf->log_not_found) {
ngx_log_error(level, log, of.err,
- ngx_open_file_n " \"%s\" failed", path.data);
+ "%s \"%s\" failed", of.failed, path.data);
}
return rc;
}
ngx_log_error(level, log, of.err,
- ngx_open_file_n " \"%s\" failed", path.data);
+ "%s \"%s\" failed", of.failed, path.data);
return NGX_DECLINED;
}
/*
- * Try to open the first index file before the test of the directory existence
- * because the valid requests should be many more than invalid ones.
- * If open() would fail, then stat() should be more quickly because some data
- * is already cached in the kernel.
- * Besides, Win32 has ERROR_PATH_NOT_FOUND (NGX_ENOTDIR).
- * Unix has ENOTDIR error, although it less helpfull - it points only
- * that path contains the usual file in place of the directory.
+ * Try to open/test the first index file before the test of directory
+ * existence because valid requests should be much more than invalid ones.
+ * If the file open()/stat() would fail, then the directory stat() should
+ * be more quickly because some data is already cached in the kernel.
+ * Besides, Win32 may return ERROR_PATH_NOT_FOUND (NGX_ENOTDIR) at once.
+ * Unix has ENOTDIR error, however, it's less helpful than Win32's one:
+ * it only indicates that path contains an usual file in place of directory.
*/
static ngx_int_t
of.directio = clcf->directio;
of.valid = clcf->open_file_cache_valid;
of.min_uses = clcf->open_file_cache_min_uses;
+ of.test_only = 1;
of.errors = clcf->open_file_cache_errors;
of.events = clcf->open_file_cache_events;
if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
!= NGX_OK)
{
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, of.err,
- ngx_open_file_n " \"%s\" failed", path.data);
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, of.err,
+ "%s \"%s\" failed", of.failed, path.data);
if (of.err == 0) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
continue;
}
- ngx_log_error(NGX_LOG_ERR, r->connection->log, of.err,
- ngx_open_file_n " \"%s\" failed", path.data);
+ ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
+ "%s \"%s\" failed", of.failed, path.data);
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
ngx_memzero(&of, sizeof(ngx_open_file_info_t));
of.test_dir = 1;
+ of.test_only = 1;
of.valid = clcf->open_file_cache_valid;
of.errors = clcf->open_file_cache_errors;
}
ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
- ngx_open_file_n " \"%s\" failed", dir.data);
+ "%s \"%s\" failed", of.failed, dir.data);
}
return NGX_HTTP_INTERNAL_SERVER_ERROR;
of.valid = clcf->open_file_cache_valid;
of.min_uses = clcf->open_file_cache_min_uses;
+ of.test_dir = 1;
+ of.test_only = 1;
of.errors = clcf->open_file_cache_errors;
of.events = clcf->open_file_cache_events;
!= NGX_OK)
{
ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
- ngx_open_file_n " \"%s\" failed", log.data);
+ "%s \"%s\" failed", of.failed, log.data);
/* simulate successfull logging */
return len;
}
if (rc != NGX_HTTP_NOT_FOUND || clcf->log_not_found) {
ngx_log_error(level, log, of.err,
- ngx_open_file_n " \"%s\" failed", path.data);
+ "%s \"%s\" failed", of.failed, path.data);
}
return rc;
}
ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
- ngx_open_file_n " \"%s\" failed", filename);
+ "%s \"%s\" failed", of.failed, filename);
XSRETURN_EMPTY;
}
of.directio = clcf->directio;
of.valid = clcf->open_file_cache_valid;
of.min_uses = clcf->open_file_cache_min_uses;
+ of.test_only = 1;
of.errors = clcf->open_file_cache_errors;
of.events = clcf->open_file_cache_events;
{
if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) {
ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
- ngx_open_file_n " \"%s\" failed", path.data);
+ "%s \"%s\" failed", of.failed, path.data);
}
continue;
of.directio = clcf->directio;
of.valid = clcf->open_file_cache_valid;
of.min_uses = clcf->open_file_cache_min_uses;
+ of.test_only = 1;
of.errors = clcf->open_file_cache_errors;
of.events = clcf->open_file_cache_events;
{
if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) {
ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
- ngx_file_info_n " \"%s\" failed", value->data);
+ "%s \"%s\" failed", of.failed, value->data);
}
switch (code->op) {