comparison src/http/ngx_http_cache.c @ 176:c0552e5ab567

nginx-0.0.1-2003-11-09-23:03:38 import; separate building
author Igor Sysoev <igor@sysoev.ru>
date Sun, 09 Nov 2003 20:03:38 +0000
parents e92c2c647c57
children 2d143372a1ee
comparison
equal deleted inserted replaced
175:e92c2c647c57 176:c0552e5ab567
6 #include <md5.h> 6 #include <md5.h>
7 7
8 8
9 int ngx_http_cache_get_file(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx) 9 int ngx_http_cache_get_file(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx)
10 { 10 {
11 ssize_t n; 11 MD5_CTX md5;
12 MD5_CTX md5;
13 ngx_err_t err;
14 ngx_http_cache_header_t *h;
15 12
16 ctx->header_size = sizeof(ngx_http_cache_header_t) + ctx->key.len + 1; 13 ctx->header_size = sizeof(ngx_http_cache_header_t) + ctx->key.len + 1;
17 14
18 ctx->file.name.len = ctx->path->name.len + 1 + ctx->path->len + 32; 15 ctx->file.name.len = ctx->path->name.len + 1 + ctx->path->len + 32;
19 if (!(ctx->file.name.data = ngx_palloc(r->pool, ctx->file.name.len + 1))) { 16 if (!(ctx->file.name.data = ngx_palloc(r->pool, ctx->file.name.len + 1))) {
36 33
37 ngx_log_debug(r->connection->log, "FILE: %s" _ ctx->file.name.data); 34 ngx_log_debug(r->connection->log, "FILE: %s" _ ctx->file.name.data);
38 35
39 /* TODO: look open files cache */ 36 /* TODO: look open files cache */
40 37
38 return ngx_http_cache_open_file(r, ctx, 0);
39 }
40
41
42 /* TODO: Win32 inode analogy */
43
44 int ngx_http_cache_open_file(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx,
45 ngx_file_uniq_t uniq)
46 {
47 ssize_t n;
48 ngx_err_t err;
49 ngx_http_cache_header_t *h;
50
41 ctx->file.fd = ngx_open_file(ctx->file.name.data, 51 ctx->file.fd = ngx_open_file(ctx->file.name.data,
42 NGX_FILE_RDONLY, NGX_FILE_OPEN); 52 NGX_FILE_RDONLY, NGX_FILE_OPEN);
43 53
44 if (ctx->file.fd == NGX_INVALID_FILE) { 54 if (ctx->file.fd == NGX_INVALID_FILE) {
45 err = ngx_errno; 55 err = ngx_errno;
49 } 59 }
50 60
51 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, 61 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
52 ngx_open_file_n " \"%s\" failed", ctx->file.name.data); 62 ngx_open_file_n " \"%s\" failed", ctx->file.name.data);
53 return NGX_ERROR; 63 return NGX_ERROR;
64 }
65
66 if (uniq) {
67 if (ngx_stat_fd(ctx->file.fd, &ctx->file.info) == NGX_FILE_ERROR) {
68 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
69 ngx_stat_fd_n " \"%s\" failed", ctx->file.name.data);
70
71 return NGX_ERROR;
72 }
73
74 if (ngx_file_uniq(ctx->file.info) == uniq) {
75 if (ngx_close_file(ctx->file.fd) == NGX_FILE_ERROR) {
76 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
77 ngx_close_file_n " \"%s\" failed",
78 ctx->file.name.data);
79 }
80
81 return NGX_HTTP_CACHE_THE_SAME;
82 }
54 } 83 }
55 84
56 n = ngx_read_file(&ctx->file, ctx->buf->pos, 85 n = ngx_read_file(&ctx->file, ctx->buf->pos,
57 ctx->buf->end - ctx->buf->last, 0); 86 ctx->buf->end - ctx->buf->last, 0);
58 87