diff src/http/ngx_http_script.c @ 332:3a91bfeffaba NGINX_0_6_10

nginx 0.6.10 *) Feature: the "open_file_cache", "open_file_cache_retest", and "open_file_cache_errors" directives. *) Bugfix: socket leak; bug appeared in 0.6.7. *) Bugfix: a charset set by the "charset" directive was not appended to the "Content-Type" header set by $r->send_http_header(). *) Bugfix: a segmentation fault might occur in worker process if /dev/poll method was used.
author Igor Sysoev <http://sysoev.ru>
date Mon, 03 Sep 2007 00:00:00 +0400
parents 390b8f8309d6
children 10cc350ed8a1
line wrap: on
line diff
--- a/src/http/ngx_http_script.c
+++ b/src/http/ngx_http_script.c
@@ -952,8 +952,10 @@ ngx_http_script_not_equal_code(ngx_http_
 void
 ngx_http_script_file_code(ngx_http_script_engine_t *e)
 {
-    ngx_err_t                     err;
-    ngx_file_info_t               fi;
+    ngx_str_t                     path;
+    ngx_http_request_t           *r;
+    ngx_open_file_info_t          of;
+    ngx_http_core_loc_conf_t     *clcf;
     ngx_http_variable_value_t    *value;
     ngx_http_script_file_code_t  *code;
 
@@ -962,14 +964,26 @@ ngx_http_script_file_code(ngx_http_scrip
     code = (ngx_http_script_file_code_t *) e->ip;
     e->ip += sizeof(ngx_http_script_file_code_t);
 
-    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
-                   "http script file op %p", code->op);
+    path.len = value->len - 1;
+    path.data = value->data;
+
+    r = e->request;
+
+    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                   "http script file op %p \"%V\"", code->op, &path);
+
+    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
 
-    if (ngx_file_info(value->data, &fi) == -1) {
-        err = ngx_errno;
+    of.test_dir = 0;
+    of.retest = clcf->open_file_cache_retest;
+    of.errors = clcf->open_file_cache_errors;
+    of.events = clcf->open_file_cache_events;
 
-        if (err != NGX_ENOENT && err != NGX_ENOTDIR) {
-            ngx_log_error(NGX_LOG_CRIT, e->request->connection->log, err,
+    if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
+        == NGX_ERROR)
+    {
+        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);
         }
 
@@ -993,69 +1007,57 @@ ngx_http_script_file_code(ngx_http_scrip
 
     switch (code->op) {
     case ngx_http_script_file_plain:
-        if (ngx_is_file(&fi)) {
+        if (of.is_file) {
              goto true;
         }
         goto false;
 
     case ngx_http_script_file_not_plain:
-        if (ngx_is_file(&fi)) {
+        if (of.is_file) {
             goto false;
         }
         goto true;
 
     case ngx_http_script_file_dir:
-        if (ngx_is_dir(&fi)) {
+        if (of.is_dir) {
              goto true;
         }
         goto false;
 
     case ngx_http_script_file_not_dir:
-        if (ngx_is_dir(&fi)) {
+        if (of.is_dir) {
             goto false;
         }
         goto true;
 
     case ngx_http_script_file_exists:
-        if (ngx_is_file(&fi) || ngx_is_dir(&fi) || ngx_is_link(&fi)) {
+        if (of.is_file || of.is_dir || of.is_link) {
              goto true;
         }
         goto false;
 
     case ngx_http_script_file_not_exists:
-        if (ngx_is_file(&fi) || ngx_is_dir(&fi) || ngx_is_link(&fi)) {
+        if (of.is_file || of.is_dir || of.is_link) {
             goto false;
         }
         goto true;
 
-#if (NGX_WIN32)
-
     case ngx_http_script_file_exec:
-        goto false;
-
-    case ngx_http_script_file_not_exec:
-        goto true;
-
-#else
-
-    case ngx_http_script_file_exec:
-        if (ngx_is_exec(&fi)) {
+        if (of.is_exec) {
              goto true;
         }
         goto false;
 
     case ngx_http_script_file_not_exec:
-        if (ngx_is_exec(&fi)) {
+        if (of.is_exec) {
             goto false;
         }
         goto true;
-
-#endif
     }
 
 false:
 
-    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                    "http script file op false");
 
     *value = ngx_http_variable_null_value;