Mercurial > hg > nginx-quic
annotate src/core/ngx_file.c @ 2233:f62751dab60d
remove unused #include's
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 05 Sep 2008 15:25:47 +0000 |
parents | 2a92804f4109 |
children | dbe746851b31 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
5 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
495 | 11 static ngx_atomic_uint_t ngx_temp_number; |
800 | 12 static ngx_atomic_uint_t ngx_random_number; |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
13 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
14 |
493 | 15 ssize_t |
16 ngx_write_chain_to_temp_file(ngx_temp_file_t *tf, ngx_chain_t *chain) | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
17 { |
467 | 18 ngx_int_t rc; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
19 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
20 if (tf->file.fd == NGX_INVALID_FILE) { |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
21 rc = ngx_create_temp_file(&tf->file, tf->path, tf->pool, |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1058
diff
changeset
|
22 tf->persistent, tf->clean, tf->access); |
208
0b67be7d4489
nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
23 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
24 if (rc == NGX_ERROR || rc == NGX_AGAIN) { |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
25 return rc; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
26 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
27 |
667 | 28 if (tf->log_level) { |
29 ngx_log_error(tf->log_level, tf->file.log, 0, "%s %V", | |
637 | 30 tf->warn, &tf->file.name); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
31 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
32 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
33 |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
34 return ngx_write_chain_to_file(&tf->file, chain, tf->offset, tf->pool); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
35 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
36 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
37 |
493 | 38 ngx_int_t |
39 ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path, ngx_pool_t *pool, | |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1058
diff
changeset
|
40 ngx_uint_t persistent, ngx_uint_t clean, ngx_uint_t access) |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 { |
1090
01b48bcb73bf
shorten temporary names on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
42 uint32_t n; |
509 | 43 ngx_err_t err; |
563 | 44 ngx_pool_cleanup_t *cln; |
45 ngx_pool_cleanup_file_t *clnf; | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 |
1091
58f1641783ca
allocate less memory on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1090
diff
changeset
|
47 file->name.len = path->name.len + 1 + path->len + 10; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 |
2049 | 49 file->name.data = ngx_pnalloc(pool, file->name.len + 1); |
501 | 50 if (file->name.data == NULL) { |
467 | 51 return NGX_ERROR; |
52 } | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 #if 0 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 for (i = 0; i < file->name.len; i++) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 file->name.data[i] = 'X'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
57 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 #endif |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
59 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
60 ngx_memcpy(file->name.data, path->name.data, path->name.len); |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
61 |
1090
01b48bcb73bf
shorten temporary names on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
62 n = (uint32_t) ngx_next_temp_number(0); |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
63 |
1747 | 64 cln = ngx_pool_cleanup_add(pool, sizeof(ngx_pool_cleanup_file_t)); |
65 if (cln == NULL) { | |
66 return NGX_ERROR; | |
67 } | |
68 | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
69 for ( ;; ) { |
517 | 70 (void) ngx_sprintf(file->name.data + path->name.len + 1 + path->len, |
1090
01b48bcb73bf
shorten temporary names on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
71 "%010uD%Z", n); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
72 |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
73 ngx_create_hashed_filename(path, file->name.data, file->name.len); |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
74 |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
75 ngx_log_debug1(NGX_LOG_DEBUG_CORE, file->log, 0, |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
76 "hashed path: %s", file->name.data); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
77 |
1046 | 78 file->fd = ngx_open_tempfile(file->name.data, persistent, access); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
79 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
80 ngx_log_debug1(NGX_LOG_DEBUG_CORE, file->log, 0, |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
81 "temp fd:%d", file->fd); |
75
869b10be682f
nginx-0.0.1-2003-04-14-21:04:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
74
diff
changeset
|
82 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
83 if (file->fd != NGX_INVALID_FILE) { |
563 | 84 |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1058
diff
changeset
|
85 cln->handler = clean ? ngx_pool_delete_file : ngx_pool_cleanup_file; |
563 | 86 clnf = cln->data; |
509 | 87 |
563 | 88 clnf->fd = file->fd; |
89 clnf->name = file->name.data; | |
90 clnf->log = pool->log; | |
509 | 91 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
92 return NGX_OK; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
93 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
94 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
95 err = ngx_errno; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
96 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
97 if (err == NGX_EEXIST) { |
1090
01b48bcb73bf
shorten temporary names on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
98 n = (uint32_t) ngx_next_temp_number(1); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 continue; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
100 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
101 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
301
diff
changeset
|
102 if ((path->level[0] == 0) |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
301
diff
changeset
|
103 || (err != NGX_ENOENT |
461 | 104 #if (NGX_WIN32) |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
301
diff
changeset
|
105 && err != NGX_ENOTDIR |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
106 #endif |
467 | 107 )) |
108 { | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
109 ngx_log_error(NGX_LOG_CRIT, file->log, err, |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
110 ngx_open_tempfile_n " \"%s\" failed", |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
111 file->name.data); |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
112 return NGX_ERROR; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
113 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
114 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 if (ngx_create_path(file, path) == NGX_ERROR) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
116 return NGX_ERROR; |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
117 } |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
118 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
119 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
121 |
493 | 122 void |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
123 ngx_create_hashed_filename(ngx_path_t *path, u_char *file, size_t len) |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
124 { |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
125 size_t i, level; |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
126 ngx_uint_t n; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
127 |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
128 i = path->name.len + 1; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
129 |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
130 file[path->name.len + path->len] = '/'; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
131 |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
132 for (n = 0; n < 3; n++) { |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
133 level = path->level[n]; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
134 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
135 if (level == 0) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
136 break; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
137 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
138 |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
139 len -= level; |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
140 file[i - 1] = '/'; |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
141 ngx_memcpy(&file[i], &file[len], level); |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
142 i += level + 1; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
143 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
144 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
145 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
146 |
493 | 147 ngx_int_t |
148 ngx_create_path(ngx_file_t *file, ngx_path_t *path) | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
149 { |
517 | 150 size_t pos; |
151 ngx_err_t err; | |
152 ngx_uint_t i; | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
153 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 pos = path->name.len; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
155 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
156 for (i = 0; i < 3; i++) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 if (path->level[i] == 0) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 break; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
160 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
161 pos += path->level[i] + 1; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 file->name.data[pos] = '\0'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
165 ngx_log_debug1(NGX_LOG_DEBUG_CORE, file->log, 0, |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
166 "temp file: \"%s\"", file->name.data); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 |
669 | 168 if (ngx_create_dir(file->name.data, 0700) == NGX_FILE_ERROR) { |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
169 err = ngx_errno; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
170 if (err != NGX_EEXIST) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
171 ngx_log_error(NGX_LOG_CRIT, file->log, err, |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
172 ngx_create_dir_n " \"%s\" failed", |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
173 file->name.data); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
174 return NGX_ERROR; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
175 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
176 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
177 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
178 file->name.data[pos] = '/'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
179 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
180 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
181 return NGX_OK; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
182 } |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
183 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
184 |
637 | 185 ngx_err_t |
669 | 186 ngx_create_full_path(u_char *dir, ngx_uint_t access) |
637 | 187 { |
188 u_char *p, ch; | |
189 ngx_err_t err; | |
190 | |
191 for (p = dir + 1; *p; p++) { | |
192 ch = *p; | |
193 | |
194 if (ch != '/') { | |
195 continue; | |
196 } | |
197 | |
198 *p = '\0'; | |
199 | |
669 | 200 if (ngx_create_dir(dir, access) == NGX_FILE_ERROR) { |
637 | 201 err = ngx_errno; |
202 if (err != NGX_EEXIST) { | |
203 return err; | |
204 } | |
205 } | |
206 | |
207 *p = '/'; | |
208 } | |
209 | |
210 return 0; | |
211 } | |
212 | |
213 | |
493 | 214 void |
499 | 215 ngx_init_temp_number(void) |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
216 { |
493 | 217 ngx_temp_number = 0; |
800 | 218 ngx_random_number = 123456; |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
219 } |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
220 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
221 |
495 | 222 ngx_atomic_uint_t |
493 | 223 ngx_next_temp_number(ngx_uint_t collision) |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
224 { |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
225 if (collision) { |
800 | 226 ngx_temp_number += ngx_random_number; |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
227 } |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
228 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
229 return ngx_temp_number++; |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
230 } |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
231 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
232 |
493 | 233 char * |
234 ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
235 { |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
236 char *p = conf; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
237 |
467 | 238 ssize_t level; |
629 | 239 ngx_str_t *value; |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
240 ngx_uint_t i, n; |
479 | 241 ngx_path_t *path, **slot; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
242 |
467 | 243 slot = (ngx_path_t **) (p + cmd->offset); |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
244 |
467 | 245 if (*slot) { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
246 return "is duplicate"; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
247 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
248 |
501 | 249 path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t)); |
250 if (path == NULL) { | |
467 | 251 return NGX_CONF_ERROR; |
252 } | |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
253 |
467 | 254 value = cf->args->elts; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
255 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
256 path->name = value[1]; |
629 | 257 |
661 | 258 if (path->name.data[path->name.len - 1] == '/') { |
259 path->name.len--; | |
260 } | |
261 | |
1352 | 262 if (ngx_conf_full_name(cf->cycle, &path->name, 0) == NGX_ERROR) { |
629 | 263 return NULL; |
264 } | |
265 | |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
266 path->len = 0; |
479 | 267 path->cleaner = (ngx_gc_handler_pt) cmd->post; |
467 | 268 path->conf_file = cf->conf_file->file.name.data; |
269 path->line = cf->conf_file->line; | |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
270 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
271 for (i = 0, n = 2; n < cf->args->nelts; i++, n++) { |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
272 level = ngx_atoi(value[n].data, value[n].len); |
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
273 if (level == NGX_ERROR || level == 0) { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
274 return "invalid value"; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
275 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
276 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
277 path->level[i] = level; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
278 path->len += level + 1; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
279 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
280 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
281 while (i < 3) { |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
282 path->level[i++] = 0; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
283 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
284 |
479 | 285 *slot = path; |
467 | 286 |
479 | 287 if (ngx_add_path(cf, slot) == NGX_ERROR) { |
288 return NGX_CONF_ERROR; | |
289 } | |
290 | |
291 return NGX_CONF_OK; | |
292 } | |
293 | |
294 | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
295 char * |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
296 ngx_conf_set_access_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
297 { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
298 char *confp = conf; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
299 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
300 u_char *p; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
301 ngx_str_t *value; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
302 ngx_uint_t i, right, shift, *access; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
303 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
304 access = (ngx_uint_t *) (confp + cmd->offset); |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
305 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
306 if (*access != NGX_CONF_UNSET_UINT) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
307 return "is duplicate"; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
308 } |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
309 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
310 value = cf->args->elts; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
311 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
312 *access = 0600; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
313 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
314 for (i = 1; i < cf->args->nelts; i++) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
315 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
316 p = value[i].data; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
317 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
318 if (ngx_strncmp(p, "user:", sizeof("user:") - 1) == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
319 shift = 6; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
320 p += sizeof("user:") - 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
321 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
322 } else if (ngx_strncmp(p, "group:", sizeof("group:") - 1) == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
323 shift = 3; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
324 p += sizeof("group:") - 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
325 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
326 } else if (ngx_strncmp(p, "all:", sizeof("all:") - 1) == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
327 shift = 0; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
328 p += sizeof("all:") - 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
329 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
330 } else { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
331 goto invalid; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
332 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
333 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
334 if (ngx_strcmp(p, "rw") == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
335 right = 6; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
336 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
337 } else if (ngx_strcmp(p, "r") == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
338 right = 4; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
339 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
340 } else { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
341 goto invalid; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
342 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
343 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
344 *access |= right << shift; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
345 } |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
346 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
347 return NGX_CONF_OK; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
348 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
349 invalid: |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
350 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
351 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid value \"%V\"", &value[i]); |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
352 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
353 return NGX_CONF_ERROR; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
354 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
355 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
356 |
493 | 357 ngx_int_t |
358 ngx_add_path(ngx_conf_t *cf, ngx_path_t **slot) | |
479 | 359 { |
360 ngx_uint_t i, n; | |
361 ngx_path_t *path, **p; | |
362 | |
363 path = *slot; | |
364 | |
365 p = cf->cycle->pathes.elts; | |
467 | 366 for (i = 0; i < cf->cycle->pathes.nelts; i++) { |
479 | 367 if (p[i]->name.len == path->name.len |
368 && ngx_strcmp(p[i]->name.data, path->name.data) == 0) | |
467 | 369 { |
370 for (n = 0; n < 3; n++) { | |
479 | 371 if (p[i]->level[n] != path->level[n]) { |
372 if (path->conf_file == NULL) { | |
481 | 373 if (p[i]->conf_file == NULL) { |
374 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
375 "the default path name \"%V\" has " | |
376 "the same name as another default path, " | |
377 "but the different levels, you need to " | |
378 "redefine one of them in http section", | |
379 &p[i]->name); | |
380 return NGX_ERROR; | |
381 } | |
382 | |
479 | 383 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
384 "the path name \"%V\" in %s:%ui has " | |
481 | 385 "the same name as default path, but " |
479 | 386 "the different levels, you need to " |
387 "define default path in http section", | |
388 &p[i]->name, p[i]->conf_file, p[i]->line); | |
389 return NGX_ERROR; | |
390 } | |
391 | |
467 | 392 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
479 | 393 "the same path name \"%V\" in %s:%ui " |
394 "has the different levels than", | |
395 &p[i]->name, p[i]->conf_file, p[i]->line); | |
396 return NGX_ERROR; | |
467 | 397 } |
398 | |
479 | 399 if (p[i]->level[n] == 0) { |
467 | 400 break; |
401 } | |
402 } | |
403 | |
479 | 404 *slot = p[i]; |
467 | 405 |
479 | 406 return NGX_OK; |
467 | 407 } |
408 } | |
409 | |
501 | 410 p = ngx_array_push(&cf->cycle->pathes); |
411 if (p == NULL) { | |
479 | 412 return NGX_ERROR; |
467 | 413 } |
414 | |
479 | 415 *p = path; |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
416 |
479 | 417 return NGX_OK; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
418 } |
467 | 419 |
420 | |
493 | 421 ngx_int_t |
422 ngx_create_pathes(ngx_cycle_t *cycle, ngx_uid_t user) | |
467 | 423 { |
424 ngx_err_t err; | |
425 ngx_uint_t i; | |
426 ngx_path_t **path; | |
427 | |
428 path = cycle->pathes.elts; | |
429 for (i = 0; i < cycle->pathes.nelts; i++) { | |
430 | |
669 | 431 if (ngx_create_dir(path[i]->name.data, 0700) == NGX_FILE_ERROR) { |
467 | 432 err = ngx_errno; |
433 if (err != NGX_EEXIST) { | |
434 ngx_log_error(NGX_LOG_EMERG, cycle->log, err, | |
435 ngx_create_dir_n " \"%s\" failed", | |
436 path[i]->name.data); | |
437 return NGX_ERROR; | |
438 } | |
439 } | |
440 | |
517 | 441 if (user == (ngx_uid_t) NGX_CONF_UNSET_UINT) { |
467 | 442 continue; |
443 } | |
444 | |
445 #if !(NGX_WIN32) | |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1695
diff
changeset
|
446 { |
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1695
diff
changeset
|
447 ngx_file_info_t fi; |
467 | 448 |
449 if (ngx_file_info((const char *) path[i]->name.data, &fi) == -1) { | |
450 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
451 ngx_file_info_n " \"%s\" failed", path[i]->name.data); | |
452 return NGX_ERROR; | |
453 } | |
454 | |
455 if (fi.st_uid != user) { | |
456 if (chown((const char *) path[i]->name.data, user, -1) == -1) { | |
457 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
458 "chown(\"%s\", %d) failed", | |
459 path[i]->name.data, user); | |
460 return NGX_ERROR; | |
461 } | |
462 } | |
463 | |
464 if ((fi.st_mode & (S_IRUSR|S_IWUSR|S_IXUSR)) | |
465 != (S_IRUSR|S_IWUSR|S_IXUSR)) | |
466 { | |
467 fi.st_mode |= (S_IRUSR|S_IWUSR|S_IXUSR); | |
468 | |
469 if (chmod((const char *) path[i]->name.data, fi.st_mode) == -1) { | |
470 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
471 "chmod() \"%s\" failed", path[i]->name.data); | |
472 return NGX_ERROR; | |
473 } | |
474 } | |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1695
diff
changeset
|
475 } |
467 | 476 #endif |
477 } | |
478 | |
479 return NGX_OK; | |
480 } | |
956 | 481 |
482 | |
483 ngx_int_t | |
1826
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
484 ngx_ext_rename_file(ngx_str_t *src, ngx_str_t *to, ngx_ext_rename_file_t *ext) |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
485 { |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
486 ngx_err_t err; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
487 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
488 #if !(NGX_WIN32) |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
489 |
1826
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
490 if (ngx_change_file_access(src->data, ext->access) == NGX_FILE_ERROR) { |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
491 ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno, |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
492 ngx_change_file_access_n " \"%s\" failed", src->data); |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
493 err = 0; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
494 goto failed; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
495 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
496 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
497 #endif |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
498 |
1826
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
499 if (ext->time != -1) { |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
500 if (ngx_set_file_time(src->data, ext->fd, ext->time) != NGX_OK) { |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
501 ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno, |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
502 ngx_set_file_time_n " \"%s\" failed", src->data); |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
503 err = 0; |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
504 goto failed; |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
505 } |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
506 } |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
507 |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
508 if (ngx_rename_file(src->data, to->data) != NGX_FILE_ERROR) { |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
509 return NGX_OK; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
510 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
511 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
512 err = ngx_errno; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
513 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
514 if (err == NGX_ENOENT) { |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
515 |
1826
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
516 if (!ext->create_path) { |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
517 goto failed; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
518 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
519 |
1826
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
520 err = ngx_create_full_path(to->data, ngx_dir_access(ext->access)); |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
521 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
522 if (err) { |
1826
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
523 ngx_log_error(NGX_LOG_CRIT, ext->log, err, |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
524 ngx_create_dir_n " \"%s\" failed", to->data); |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
525 err = 0; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
526 goto failed; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
527 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
528 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
529 if (ngx_rename_file(src->data, to->data) != NGX_FILE_ERROR) { |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
530 return NGX_OK; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
531 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
532 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
533 err = ngx_errno; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
534 goto failed; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
535 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
536 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
537 #if (NGX_WIN32) |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
538 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
539 if (err == NGX_EEXIST) { |
1826
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
540 if (ngx_win32_rename_file(src, to, ext->log) == NGX_OK) { |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
541 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
542 if (ngx_rename_file(src->data, to->data) != NGX_FILE_ERROR) { |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
543 return NGX_OK; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
544 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
545 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
546 err = ngx_errno; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
547 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
548 } else { |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
549 err = 0; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
550 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
551 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
552 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
553 #endif |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
554 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
555 failed: |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
556 |
1909 | 557 if (ext->delete_file) { |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
558 if (ngx_delete_file(src->data) == NGX_FILE_ERROR) { |
1826
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
559 ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno, |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
560 ngx_delete_file_n " \"%s\" failed", src->data); |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
561 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
562 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
563 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
564 if (err) { |
1826
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
565 ngx_log_error(NGX_LOG_CRIT, ext->log, err, |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
566 ngx_rename_file_n " \"%s\" to \"%s\" failed", |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
567 src->data, to->data); |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
568 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
569 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
570 return NGX_ERROR; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
571 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
572 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
573 |
1750 | 574 /* |
575 * ctx->init_handler() - see ctx->alloc | |
576 * ctx->file_handler() - file handler | |
577 * ctx->pre_tree_handler() - handler is called before entering directory | |
578 * ctx->post_tree_handler() - handler is called after leaving directory | |
579 * ctx->spec_handler() - special (socket, FIFO, etc.) file handler | |
580 * | |
581 * ctx->data - some data structure, it may be the same on all levels, or | |
582 * reallocated if ctx->alloc is nonzero | |
583 * | |
584 * ctx->alloc - a size of data structure that is allocated at every level | |
585 * and is initilialized by ctx->init_handler() | |
586 * | |
587 * ctx->log - a log | |
588 * | |
589 * on fatal (memory) error handler must return NGX_ABORT to stop walking tree | |
590 */ | |
591 | |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
592 ngx_int_t |
956 | 593 ngx_walk_tree(ngx_tree_ctx_t *ctx, ngx_str_t *tree) |
594 { | |
595 void *data, *prev; | |
596 u_char *p, *name; | |
597 size_t len; | |
598 ngx_int_t rc; | |
599 ngx_err_t err; | |
977
b9836e87dd4d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
956
diff
changeset
|
600 ngx_str_t file, buf; |
956 | 601 ngx_dir_t dir; |
602 | |
603 buf.len = 0; | |
604 buf.data = NULL; | |
605 | |
606 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
607 "walk tree \"%V\"", tree); | |
608 | |
609 if (ngx_open_dir(tree, &dir) == NGX_ERROR) { | |
610 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, | |
611 ngx_open_dir_n " \"%s\" failed", tree->data); | |
612 return NGX_ERROR; | |
613 } | |
614 | |
615 prev = ctx->data; | |
616 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
617 if (ctx->alloc) { |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
618 data = ngx_alloc(ctx->alloc, ctx->log); |
956 | 619 if (data == NULL) { |
620 goto failed; | |
621 } | |
622 | |
623 if (ctx->init_handler(data, prev) == NGX_ABORT) { | |
624 goto failed; | |
625 } | |
626 | |
627 ctx->data = data; | |
1319 | 628 |
629 } else { | |
630 data = NULL; | |
956 | 631 } |
632 | |
633 for ( ;; ) { | |
634 | |
635 ngx_set_errno(0); | |
636 | |
637 if (ngx_read_dir(&dir) == NGX_ERROR) { | |
638 err = ngx_errno; | |
639 | |
640 if (err == NGX_ENOMOREFILES) { | |
641 rc = NGX_OK; | |
642 | |
643 } else { | |
644 ngx_log_error(NGX_LOG_CRIT, ctx->log, err, | |
645 ngx_read_dir_n " \"%s\" failed", tree->data); | |
646 rc = NGX_ERROR; | |
647 } | |
648 | |
649 goto done; | |
650 } | |
651 | |
652 len = ngx_de_namelen(&dir); | |
653 name = ngx_de_name(&dir); | |
654 | |
655 ngx_log_debug2(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
656 "tree name %uz:\"%s\"", len, name); | |
657 | |
658 if (len == 1 && name[0] == '.') { | |
659 continue; | |
660 } | |
661 | |
662 if (len == 2 && name[0] == '.' && name[1] == '.') { | |
663 continue; | |
664 } | |
665 | |
666 file.len = tree->len + 1 + len; | |
667 | |
668 if (file.len + NGX_DIR_MASK_LEN > buf.len) { | |
669 | |
670 if (buf.len) { | |
671 ngx_free(buf.data); | |
672 } | |
673 | |
674 buf.len = tree->len + 1 + len + NGX_DIR_MASK_LEN; | |
675 | |
676 buf.data = ngx_alloc(buf.len + 1, ctx->log); | |
677 if (buf.data == NULL) { | |
678 goto failed; | |
679 } | |
680 } | |
681 | |
682 p = ngx_cpymem(buf.data, tree->data, tree->len); | |
683 *p++ = '/'; | |
684 ngx_memcpy(p, name, len + 1); | |
685 | |
686 file.data = buf.data; | |
687 | |
688 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
689 "tree path \"%s\"", file.data); | |
690 | |
691 if (!dir.valid_info) { | |
692 if (ngx_de_info(file.data, &dir) == NGX_FILE_ERROR) { | |
693 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, | |
694 ngx_de_info_n " \"%s\" failed", file.data); | |
695 continue; | |
696 } | |
697 } | |
698 | |
699 if (ngx_de_is_file(&dir)) { | |
700 | |
701 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
702 "tree file \"%s\"", file.data); | |
703 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
704 ctx->size = ngx_de_size(&dir); |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
705 ctx->access = ngx_de_access(&dir); |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
706 ctx->mtime = ngx_de_mtime(&dir); |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
707 |
956 | 708 if (ctx->file_handler(ctx, &file) == NGX_ABORT) { |
709 goto failed; | |
710 } | |
711 | |
712 } else if (ngx_de_is_dir(&dir)) { | |
713 | |
714 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
715 "tree enter dir \"%s\"", file.data); | |
716 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
717 ctx->access = ngx_de_access(&dir); |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
718 ctx->mtime = ngx_de_mtime(&dir); |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
719 |
956 | 720 if (ctx->pre_tree_handler(ctx, &file) == NGX_ABORT) { |
721 goto failed; | |
722 } | |
723 | |
724 if (ngx_walk_tree(ctx, &file) == NGX_ABORT) { | |
725 goto failed; | |
726 } | |
727 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
728 ctx->access = ngx_de_access(&dir); |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
729 ctx->mtime = ngx_de_mtime(&dir); |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
730 |
956 | 731 if (ctx->post_tree_handler(ctx, &file) == NGX_ABORT) { |
732 goto failed; | |
733 } | |
734 | |
735 } else { | |
736 | |
737 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
738 "tree special \"%s\"", file.data); | |
739 | |
740 if (ctx->spec_handler(ctx, &file) == NGX_ABORT) { | |
741 goto failed; | |
742 } | |
743 } | |
744 } | |
745 | |
746 failed: | |
747 | |
748 rc = NGX_ABORT; | |
749 | |
750 done: | |
751 | |
752 if (buf.len) { | |
753 ngx_free(buf.data); | |
754 } | |
755 | |
1319 | 756 if (data) { |
757 ngx_free(data); | |
956 | 758 ctx->data = prev; |
759 } | |
760 | |
761 if (ngx_close_dir(&dir) == NGX_ERROR) { | |
762 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, | |
763 ngx_close_dir_n " \"%s\" failed", tree->data); | |
764 } | |
765 | |
766 return rc; | |
767 } |