comparison src/http/ngx_http_upstream.c @ 370:9a242235a80a NGINX_0_6_29

nginx 0.6.29 *) Feature: the ngx_google_perftools_module. *) Bugfix: the ngx_http_perl_module could be not built on 64-bit platforms; bug appeared in 0.6.27.
author Igor Sysoev <http://sysoev.ru>
date Tue, 18 Mar 2008 00:00:00 +0300
parents babd3d9efb62
children 6639b93e81b2
comparison
equal deleted inserted replaced
369:5906b8639a07 370:9a242235a80a
2123 2123
2124 2124
2125 static void 2125 static void
2126 ngx_http_upstream_store(ngx_http_request_t *r, ngx_http_upstream_t *u) 2126 ngx_http_upstream_store(ngx_http_request_t *r, ngx_http_upstream_t *u)
2127 { 2127 {
2128 char *failed; 2128 size_t root;
2129 u_char *name; 2129 time_t lm;
2130 size_t root; 2130 ngx_str_t path;
2131 time_t lm; 2131 ngx_temp_file_t *tf;
2132 ngx_err_t err; 2132 ngx_ext_rename_file_t ext;
2133 ngx_str_t *temp, path, *last_modified;
2134 ngx_temp_file_t *tf;
2135 2133
2136 tf = u->pipe->temp_file; 2134 tf = u->pipe->temp_file;
2137 2135
2138 if (tf->file.fd == NGX_INVALID_FILE) { 2136 if (tf->file.fd == NGX_INVALID_FILE) {
2139 2137
2158 } 2156 }
2159 2157
2160 u->pipe->temp_file = tf; 2158 u->pipe->temp_file = tf;
2161 } 2159 }
2162 2160
2163 temp = &tf->file.name; 2161 ext.access = u->conf->store_access;
2164 2162 ext.time = -1;
2165 #if !(NGX_WIN32) 2163 ext.create_path = 1;
2166 2164 ext.delete_file = 1;
2167 if (ngx_change_file_access(temp->data, u->conf->store_access) 2165 ext.log = r->connection->log;
2168 == NGX_FILE_ERROR)
2169 {
2170 err = ngx_errno;
2171 failed = ngx_change_file_access_n;
2172 name = temp->data;
2173
2174 goto failed;
2175 }
2176
2177 #endif
2178 2166
2179 if (u->headers_in.last_modified) { 2167 if (u->headers_in.last_modified) {
2180 2168
2181 last_modified = &u->headers_in.last_modified->value; 2169 lm = ngx_http_parse_time(u->headers_in.last_modified->value.data,
2182 2170 u->headers_in.last_modified->value.len);
2183 lm = ngx_http_parse_time(last_modified->data, last_modified->len);
2184 2171
2185 if (lm != NGX_ERROR) { 2172 if (lm != NGX_ERROR) {
2186 if (ngx_set_file_time(temp->data, tf->file.fd, lm) != NGX_OK) { 2173 ext.time = lm;
2187 err = ngx_errno; 2174 ext.fd = tf->file.fd;
2188 failed = ngx_set_file_time_n;
2189 name = temp->data;
2190
2191 goto failed;
2192 }
2193 } 2175 }
2194 } 2176 }
2195 2177
2196 if (u->conf->store_lengths == NULL) { 2178 if (u->conf->store_lengths == NULL) {
2197 2179
2205 return; 2187 return;
2206 } 2188 }
2207 } 2189 }
2208 2190
2209 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 2191 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2210 "upstream stores \"%s\" to \"%s\"", temp->data, path.data); 2192 "upstream stores \"%s\" to \"%s\"",
2211 2193 tf->file.name.data, path.data);
2212 failed = ngx_rename_file_n; 2194
2213 name = path.data; 2195 (void) ngx_ext_rename_file(&tf->file.name, &path, &ext);
2214
2215 if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) {
2216 return;
2217 }
2218
2219 err = ngx_errno;
2220
2221 if (err == NGX_ENOENT) {
2222
2223 err = ngx_create_full_path(path.data,
2224 ngx_dir_access(u->conf->store_access));
2225 if (err == 0) {
2226 if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) {
2227 return;
2228 }
2229
2230 err = ngx_errno;
2231 }
2232 }
2233
2234 #if (NGX_WIN32)
2235
2236 if (err == NGX_EEXIST) {
2237 if (ngx_win32_rename_file(temp, &path, r->connection->log) == NGX_OK) {
2238
2239 if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) {
2240 return;
2241 }
2242 }
2243
2244 err = ngx_errno;
2245 }
2246
2247 #endif
2248
2249 failed:
2250
2251 if (ngx_delete_file(temp->data) == NGX_FILE_ERROR) {
2252 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
2253 ngx_delete_file_n " \"%s\" failed",
2254 temp->data);
2255 }
2256
2257 ngx_log_error(NGX_LOG_CRIT, r->connection->log, err,
2258 "%s \"%s\" failed", failed, name);
2259 } 2196 }
2260 2197
2261 2198
2262 static void 2199 static void
2263 ngx_http_upstream_dummy_handler(ngx_event_t *wev) 2200 ngx_http_upstream_dummy_handler(ngx_event_t *wev)