Mercurial > hg > nginx-quic
annotate src/core/ngx_file.c @ 8467:2ab7b55ae4a0
Stream: the "fastopen" parameter of the "listen" directive.
Based on a patch by Anbang Wen.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Thu, 20 May 2021 19:59:16 +0300 |
parents | 061ec464813f |
children |
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 |
4412 | 4 * Copyright (C) Nginx, Inc. |
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
|
5 */ |
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
|
6 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
5316
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
12 static ngx_int_t ngx_test_full_name(ngx_str_t *name); |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
13 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
14 |
3035
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
15 static ngx_atomic_t temp_number = 0; |
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
16 ngx_atomic_t *ngx_temp_number = &temp_number; |
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
17 ngx_atomic_int_t 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
|
18 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
19 |
5316
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
20 ngx_int_t |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
21 ngx_get_full_name(ngx_pool_t *pool, ngx_str_t *prefix, ngx_str_t *name) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
22 { |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
23 size_t len; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
24 u_char *p, *n; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
25 ngx_int_t rc; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
26 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
27 rc = ngx_test_full_name(name); |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
28 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
29 if (rc == NGX_OK) { |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
30 return rc; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
31 } |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
32 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
33 len = prefix->len; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
34 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
35 #if (NGX_WIN32) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
36 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
37 if (rc == 2) { |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
38 len = rc; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
39 } |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
40 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
41 #endif |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
42 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
43 n = ngx_pnalloc(pool, len + name->len + 1); |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
44 if (n == NULL) { |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
45 return NGX_ERROR; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
46 } |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
47 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
48 p = ngx_cpymem(n, prefix->data, len); |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
49 ngx_cpystrn(p, name->data, name->len + 1); |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
50 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
51 name->len += len; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
52 name->data = n; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
53 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
54 return NGX_OK; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
55 } |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
56 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
57 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
58 static ngx_int_t |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
59 ngx_test_full_name(ngx_str_t *name) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
60 { |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
61 #if (NGX_WIN32) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
62 u_char c0, c1; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
63 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
64 c0 = name->data[0]; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
65 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
66 if (name->len < 2) { |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
67 if (c0 == '/') { |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
68 return 2; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
69 } |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
70 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
71 return NGX_DECLINED; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
72 } |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
73 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
74 c1 = name->data[1]; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
75 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
76 if (c1 == ':') { |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
77 c0 |= 0x20; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
78 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
79 if ((c0 >= 'a' && c0 <= 'z')) { |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
80 return NGX_OK; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
81 } |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
82 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
83 return NGX_DECLINED; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
84 } |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
85 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
86 if (c1 == '/') { |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
87 return NGX_OK; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
88 } |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
89 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
90 if (c0 == '/') { |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
91 return 2; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
92 } |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
93 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
94 return NGX_DECLINED; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
95 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
96 #else |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
97 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
98 if (name->data[0] == '/') { |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
99 return NGX_OK; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
100 } |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
101 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
102 return NGX_DECLINED; |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
103 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
104 #endif |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
105 } |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
106 |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
4966
diff
changeset
|
107 |
493 | 108 ssize_t |
109 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
|
110 { |
467 | 111 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
|
112 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
113 if (tf->file.fd == NGX_INVALID_FILE) { |
5969
3281de8142f5
Core: reverted prefix-based temp files (a9138c35120d).
Roman Arutyunyan <arut@nginx.com>
parents:
5967
diff
changeset
|
114 rc = ngx_create_temp_file(&tf->file, tf->path, tf->pool, |
3281de8142f5
Core: reverted prefix-based temp files (a9138c35120d).
Roman Arutyunyan <arut@nginx.com>
parents:
5967
diff
changeset
|
115 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
|
116 |
5957
570677a06dce
Unified handling of ngx_create_temp_file() return value.
Valentin Bartenev <vbart@nginx.com>
parents:
5377
diff
changeset
|
117 if (rc != NGX_OK) { |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
118 return rc; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
119 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
120 |
667 | 121 if (tf->log_level) { |
122 ngx_log_error(tf->log_level, tf->file.log, 0, "%s %V", | |
637 | 123 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
|
124 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
125 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
126 |
6442
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6071
diff
changeset
|
127 #if (NGX_THREADS && NGX_HAVE_PWRITEV) |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6071
diff
changeset
|
128 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6071
diff
changeset
|
129 if (tf->thread_write) { |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6071
diff
changeset
|
130 return ngx_thread_write_chain_to_file(&tf->file, chain, tf->offset, |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6071
diff
changeset
|
131 tf->pool); |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6071
diff
changeset
|
132 } |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6071
diff
changeset
|
133 |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6071
diff
changeset
|
134 #endif |
6e10518f95d8
Threads: offloading of temp files writing to thread pools.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6071
diff
changeset
|
135 |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
136 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
|
137 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
138 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
139 |
493 | 140 ngx_int_t |
141 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
|
142 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
|
143 { |
6795
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
144 size_t levels; |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
145 u_char *p; |
1090
01b48bcb73bf
shorten temporary names on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
146 uint32_t n; |
509 | 147 ngx_err_t err; |
6795
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
148 ngx_str_t name; |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
149 ngx_uint_t prefix; |
563 | 150 ngx_pool_cleanup_t *cln; |
151 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
|
152 |
6795
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
153 if (file->name.len) { |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
154 name = file->name; |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
155 levels = 0; |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
156 prefix = 1; |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
157 |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
158 } else { |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
159 name = path->name; |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
160 levels = path->len; |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
161 prefix = 0; |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
162 } |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
163 |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
164 file->name.len = name.len + 1 + levels + 10; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
165 |
2049 | 166 file->name.data = ngx_pnalloc(pool, file->name.len + 1); |
501 | 167 if (file->name.data == NULL) { |
467 | 168 return NGX_ERROR; |
169 } | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
170 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
171 #if 0 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
172 for (i = 0; i < file->name.len; i++) { |
6474 | 173 file->name.data[i] = 'X'; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
174 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
175 #endif |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
176 |
6795
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
177 p = ngx_cpymem(file->name.data, name.data, name.len); |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
178 |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
179 if (prefix) { |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
180 *p = '.'; |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
181 } |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
182 |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
183 p += 1 + levels; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 |
1090
01b48bcb73bf
shorten temporary names on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
185 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
|
186 |
1747 | 187 cln = ngx_pool_cleanup_add(pool, sizeof(ngx_pool_cleanup_file_t)); |
188 if (cln == NULL) { | |
189 return NGX_ERROR; | |
190 } | |
191 | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
192 for ( ;; ) { |
6795
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
193 (void) ngx_sprintf(p, "%010uD%Z", n); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
194 |
6795
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
195 if (!prefix) { |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
196 ngx_create_hashed_filename(path, file->name.data, file->name.len); |
1a917932db96
Cache: prefix-based temporary files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6730
diff
changeset
|
197 } |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
198 |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
199 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
|
200 "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
|
201 |
1046 | 202 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
|
203 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
204 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
|
205 "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
|
206 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
207 if (file->fd != NGX_INVALID_FILE) { |
563 | 208 |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1058
diff
changeset
|
209 cln->handler = clean ? ngx_pool_delete_file : ngx_pool_cleanup_file; |
563 | 210 clnf = cln->data; |
509 | 211 |
563 | 212 clnf->fd = file->fd; |
213 clnf->name = file->name.data; | |
214 clnf->log = pool->log; | |
509 | 215 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
216 return NGX_OK; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
217 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
218 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
219 err = ngx_errno; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
220 |
6468
a5897d360977
Win32: additional error code NGX_EEXIST_FILE (ticket #910).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6442
diff
changeset
|
221 if (err == NGX_EEXIST_FILE) { |
1090
01b48bcb73bf
shorten temporary names on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
222 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
|
223 continue; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
224 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
225 |
5969
3281de8142f5
Core: reverted prefix-based temp files (a9138c35120d).
Roman Arutyunyan <arut@nginx.com>
parents:
5967
diff
changeset
|
226 if ((path->level[0] == 0) || (err != NGX_ENOPATH)) { |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
227 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
|
228 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
|
229 file->name.data); |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
230 return NGX_ERROR; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
231 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
232 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
233 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
|
234 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
|
235 } |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
236 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
237 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
238 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
239 |
493 | 240 void |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
241 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
|
242 { |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
243 size_t i, level; |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
244 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
|
245 |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
246 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
|
247 |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
248 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
|
249 |
6617
8bf484eef9ab
Use NGX_MAX_PATH_LEVEL where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6480
diff
changeset
|
250 for (n = 0; n < NGX_MAX_PATH_LEVEL; n++) { |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
251 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
|
252 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
253 if (level == 0) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
254 break; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
255 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
256 |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
257 len -= level; |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
258 file[i - 1] = '/'; |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
259 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
|
260 i += level + 1; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
261 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
262 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
263 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
264 |
493 | 265 ngx_int_t |
266 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
|
267 { |
517 | 268 size_t pos; |
269 ngx_err_t err; | |
270 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
|
271 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
272 pos = path->name.len; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
273 |
6617
8bf484eef9ab
Use NGX_MAX_PATH_LEVEL where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6480
diff
changeset
|
274 for (i = 0; i < NGX_MAX_PATH_LEVEL; i++) { |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
275 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
|
276 break; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
277 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
278 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
279 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
|
280 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
281 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
|
282 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
283 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
|
284 "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
|
285 |
669 | 286 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
|
287 err = ngx_errno; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
288 if (err != NGX_EEXIST) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
289 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
|
290 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
|
291 file->name.data); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
292 return NGX_ERROR; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
293 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
294 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
295 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
296 file->name.data[pos] = '/'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
297 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
298 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
299 return NGX_OK; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
300 } |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
301 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
302 |
637 | 303 ngx_err_t |
669 | 304 ngx_create_full_path(u_char *dir, ngx_uint_t access) |
637 | 305 { |
306 u_char *p, ch; | |
307 ngx_err_t err; | |
308 | |
3202
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
309 err = 0; |
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
310 |
3201
5fae6f9085e1
do not create Win32 drive letter in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
311 #if (NGX_WIN32) |
5fae6f9085e1
do not create Win32 drive letter in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
312 p = dir + 3; |
5fae6f9085e1
do not create Win32 drive letter in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
313 #else |
5fae6f9085e1
do not create Win32 drive letter in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
314 p = dir + 1; |
5fae6f9085e1
do not create Win32 drive letter in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
315 #endif |
5fae6f9085e1
do not create Win32 drive letter in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
316 |
5fae6f9085e1
do not create Win32 drive letter in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
317 for ( /* void */ ; *p; p++) { |
637 | 318 ch = *p; |
319 | |
320 if (ch != '/') { | |
321 continue; | |
322 } | |
323 | |
324 *p = '\0'; | |
325 | |
669 | 326 if (ngx_create_dir(dir, access) == NGX_FILE_ERROR) { |
637 | 327 err = ngx_errno; |
3202
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
328 |
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
329 switch (err) { |
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
330 case NGX_EEXIST: |
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
331 err = 0; |
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
332 case NGX_EACCES: |
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
333 break; |
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
334 |
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
335 default: |
637 | 336 return err; |
337 } | |
338 } | |
339 | |
340 *p = '/'; | |
341 } | |
342 | |
3202
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
343 return err; |
637 | 344 } |
345 | |
346 | |
495 | 347 ngx_atomic_uint_t |
493 | 348 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
|
349 { |
3035
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
350 ngx_atomic_uint_t n, add; |
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
351 |
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
352 add = collision ? ngx_random_number : 1; |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
353 |
3035
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
354 n = ngx_atomic_fetch_add(ngx_temp_number, add); |
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
355 |
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
356 return n + add; |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
357 } |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
358 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
359 |
493 | 360 char * |
361 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
|
362 { |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
363 char *p = conf; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
364 |
467 | 365 ssize_t level; |
629 | 366 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
|
367 ngx_uint_t i, n; |
479 | 368 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
|
369 |
467 | 370 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
|
371 |
467 | 372 if (*slot) { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
373 return "is duplicate"; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
374 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
375 |
501 | 376 path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t)); |
377 if (path == NULL) { | |
467 | 378 return NGX_CONF_ERROR; |
379 } | |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
380 |
467 | 381 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
|
382 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
383 path->name = value[1]; |
629 | 384 |
661 | 385 if (path->name.data[path->name.len - 1] == '/') { |
386 path->name.len--; | |
387 } | |
388 | |
5330
314c3d7cc3a5
Backed out f1a91825730a and 7094bd12c1ff.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5317
diff
changeset
|
389 if (ngx_conf_full_name(cf->cycle, &path->name, 0) != NGX_OK) { |
6069
e37ec0a33901
Core: fixed error handling on ngx_conf_full_name() failure.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5969
diff
changeset
|
390 return NGX_CONF_ERROR; |
629 | 391 } |
392 | |
467 | 393 path->conf_file = cf->conf_file->file.name.data; |
394 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
|
395 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
396 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
|
397 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
|
398 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
|
399 return "invalid value"; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
400 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
401 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
402 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
|
403 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
|
404 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
405 |
6071
7bdd34cd2711
Core: limited levels of subdirectory hierarchy used for temp files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6070
diff
changeset
|
406 if (path->len > 10 + i) { |
7bdd34cd2711
Core: limited levels of subdirectory hierarchy used for temp files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6070
diff
changeset
|
407 return "invalid value"; |
7bdd34cd2711
Core: limited levels of subdirectory hierarchy used for temp files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6070
diff
changeset
|
408 } |
7bdd34cd2711
Core: limited levels of subdirectory hierarchy used for temp files.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6070
diff
changeset
|
409 |
479 | 410 *slot = path; |
467 | 411 |
479 | 412 if (ngx_add_path(cf, slot) == NGX_ERROR) { |
413 return NGX_CONF_ERROR; | |
414 } | |
415 | |
416 return NGX_CONF_OK; | |
417 } | |
418 | |
419 | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
420 char * |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
421 ngx_conf_merge_path_value(ngx_conf_t *cf, ngx_path_t **path, ngx_path_t *prev, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
422 ngx_path_init_t *init) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
423 { |
6617
8bf484eef9ab
Use NGX_MAX_PATH_LEVEL where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6480
diff
changeset
|
424 ngx_uint_t i; |
8bf484eef9ab
Use NGX_MAX_PATH_LEVEL where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6480
diff
changeset
|
425 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
426 if (*path) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
427 return NGX_CONF_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
428 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
429 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
430 if (prev) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
431 *path = prev; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
432 return NGX_CONF_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
433 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
434 |
5375
7d8770196436
Use ngx_pcalloc() in ngx_conf_merge_path_value().
Valentin Bartenev <vbart@nginx.com>
parents:
5330
diff
changeset
|
435 *path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t)); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
436 if (*path == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
437 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
438 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
439 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
440 (*path)->name = init->name; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
441 |
5330
314c3d7cc3a5
Backed out f1a91825730a and 7094bd12c1ff.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5317
diff
changeset
|
442 if (ngx_conf_full_name(cf->cycle, &(*path)->name, 0) != NGX_OK) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
443 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
444 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
445 |
6617
8bf484eef9ab
Use NGX_MAX_PATH_LEVEL where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6480
diff
changeset
|
446 for (i = 0; i < NGX_MAX_PATH_LEVEL; i++) { |
8bf484eef9ab
Use NGX_MAX_PATH_LEVEL where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6480
diff
changeset
|
447 (*path)->level[i] = init->level[i]; |
8bf484eef9ab
Use NGX_MAX_PATH_LEVEL where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6480
diff
changeset
|
448 (*path)->len += init->level[i] + (init->level[i] ? 1 : 0); |
8bf484eef9ab
Use NGX_MAX_PATH_LEVEL where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6480
diff
changeset
|
449 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
450 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
451 if (ngx_add_path(cf, path) != NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
452 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
453 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
454 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
455 return NGX_CONF_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
456 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
457 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
458 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
459 char * |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
460 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
|
461 { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
462 char *confp = conf; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
463 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
464 u_char *p; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
465 ngx_str_t *value; |
6730
1606a817c1d4
Core: ngx_conf_set_access_slot() user access (ticket #1096).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6617
diff
changeset
|
466 ngx_uint_t i, right, shift, *access, user; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
467 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
468 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
|
469 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
470 if (*access != NGX_CONF_UNSET_UINT) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
471 return "is duplicate"; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
472 } |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
473 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
474 value = cf->args->elts; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
475 |
6730
1606a817c1d4
Core: ngx_conf_set_access_slot() user access (ticket #1096).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6617
diff
changeset
|
476 *access = 0; |
1606a817c1d4
Core: ngx_conf_set_access_slot() user access (ticket #1096).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6617
diff
changeset
|
477 user = 0600; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
478 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
479 for (i = 1; i < cf->args->nelts; i++) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
480 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
481 p = value[i].data; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
482 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
483 if (ngx_strncmp(p, "user:", sizeof("user:") - 1) == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
484 shift = 6; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
485 p += sizeof("user:") - 1; |
6730
1606a817c1d4
Core: ngx_conf_set_access_slot() user access (ticket #1096).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6617
diff
changeset
|
486 user = 0; |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
487 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
488 } 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
|
489 shift = 3; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
490 p += sizeof("group:") - 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
491 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
492 } 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
|
493 shift = 0; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
494 p += sizeof("all:") - 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
495 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
496 } else { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
497 goto invalid; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
498 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
499 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
500 if (ngx_strcmp(p, "rw") == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
501 right = 6; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
502 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
503 } else if (ngx_strcmp(p, "r") == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
504 right = 4; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
505 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
506 } else { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
507 goto invalid; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
508 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
509 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
510 *access |= right << shift; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
511 } |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
512 |
6730
1606a817c1d4
Core: ngx_conf_set_access_slot() user access (ticket #1096).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6617
diff
changeset
|
513 *access |= user; |
1606a817c1d4
Core: ngx_conf_set_access_slot() user access (ticket #1096).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6617
diff
changeset
|
514 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
515 return NGX_CONF_OK; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
516 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
517 invalid: |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
518 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
519 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
|
520 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
521 return NGX_CONF_ERROR; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
522 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
523 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
524 |
493 | 525 ngx_int_t |
526 ngx_add_path(ngx_conf_t *cf, ngx_path_t **slot) | |
479 | 527 { |
528 ngx_uint_t i, n; | |
529 ngx_path_t *path, **p; | |
530 | |
531 path = *slot; | |
532 | |
4870
8a9b7b4e9f2d
Correct plural form for "path" in the whole source base.
Andrey Belov <defan@nginx.com>
parents:
4572
diff
changeset
|
533 p = cf->cycle->paths.elts; |
8a9b7b4e9f2d
Correct plural form for "path" in the whole source base.
Andrey Belov <defan@nginx.com>
parents:
4572
diff
changeset
|
534 for (i = 0; i < cf->cycle->paths.nelts; i++) { |
479 | 535 if (p[i]->name.len == path->name.len |
536 && ngx_strcmp(p[i]->name.data, path->name.data) == 0) | |
467 | 537 { |
5377
cec155f07c84
Improved check for duplicate path names in ngx_add_path().
Valentin Bartenev <vbart@nginx.com>
parents:
5376
diff
changeset
|
538 if (p[i]->data != path->data) { |
cec155f07c84
Improved check for duplicate path names in ngx_add_path().
Valentin Bartenev <vbart@nginx.com>
parents:
5376
diff
changeset
|
539 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
cec155f07c84
Improved check for duplicate path names in ngx_add_path().
Valentin Bartenev <vbart@nginx.com>
parents:
5376
diff
changeset
|
540 "the same path name \"%V\" " |
cec155f07c84
Improved check for duplicate path names in ngx_add_path().
Valentin Bartenev <vbart@nginx.com>
parents:
5376
diff
changeset
|
541 "used in %s:%ui and", |
cec155f07c84
Improved check for duplicate path names in ngx_add_path().
Valentin Bartenev <vbart@nginx.com>
parents:
5376
diff
changeset
|
542 &p[i]->name, p[i]->conf_file, p[i]->line); |
cec155f07c84
Improved check for duplicate path names in ngx_add_path().
Valentin Bartenev <vbart@nginx.com>
parents:
5376
diff
changeset
|
543 return NGX_ERROR; |
cec155f07c84
Improved check for duplicate path names in ngx_add_path().
Valentin Bartenev <vbart@nginx.com>
parents:
5376
diff
changeset
|
544 } |
cec155f07c84
Improved check for duplicate path names in ngx_add_path().
Valentin Bartenev <vbart@nginx.com>
parents:
5376
diff
changeset
|
545 |
6617
8bf484eef9ab
Use NGX_MAX_PATH_LEVEL where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6480
diff
changeset
|
546 for (n = 0; n < NGX_MAX_PATH_LEVEL; n++) { |
479 | 547 if (p[i]->level[n] != path->level[n]) { |
548 if (path->conf_file == NULL) { | |
481 | 549 if (p[i]->conf_file == NULL) { |
550 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
551 "the default path name \"%V\" has " | |
552 "the same name as another default path, " | |
553 "but the different levels, you need to " | |
554 "redefine one of them in http section", | |
555 &p[i]->name); | |
556 return NGX_ERROR; | |
557 } | |
558 | |
479 | 559 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
560 "the path name \"%V\" in %s:%ui has " | |
481 | 561 "the same name as default path, but " |
479 | 562 "the different levels, you need to " |
563 "define default path in http section", | |
564 &p[i]->name, p[i]->conf_file, p[i]->line); | |
565 return NGX_ERROR; | |
566 } | |
567 | |
467 | 568 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
479 | 569 "the same path name \"%V\" in %s:%ui " |
570 "has the different levels than", | |
571 &p[i]->name, p[i]->conf_file, p[i]->line); | |
572 return NGX_ERROR; | |
467 | 573 } |
574 | |
479 | 575 if (p[i]->level[n] == 0) { |
467 | 576 break; |
577 } | |
578 } | |
579 | |
479 | 580 *slot = p[i]; |
467 | 581 |
479 | 582 return NGX_OK; |
467 | 583 } |
584 } | |
585 | |
4870
8a9b7b4e9f2d
Correct plural form for "path" in the whole source base.
Andrey Belov <defan@nginx.com>
parents:
4572
diff
changeset
|
586 p = ngx_array_push(&cf->cycle->paths); |
501 | 587 if (p == NULL) { |
479 | 588 return NGX_ERROR; |
467 | 589 } |
590 | |
479 | 591 *p = path; |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
592 |
479 | 593 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
|
594 } |
467 | 595 |
596 | |
493 | 597 ngx_int_t |
4870
8a9b7b4e9f2d
Correct plural form for "path" in the whole source base.
Andrey Belov <defan@nginx.com>
parents:
4572
diff
changeset
|
598 ngx_create_paths(ngx_cycle_t *cycle, ngx_uid_t user) |
467 | 599 { |
600 ngx_err_t err; | |
601 ngx_uint_t i; | |
602 ngx_path_t **path; | |
603 | |
4870
8a9b7b4e9f2d
Correct plural form for "path" in the whole source base.
Andrey Belov <defan@nginx.com>
parents:
4572
diff
changeset
|
604 path = cycle->paths.elts; |
8a9b7b4e9f2d
Correct plural form for "path" in the whole source base.
Andrey Belov <defan@nginx.com>
parents:
4572
diff
changeset
|
605 for (i = 0; i < cycle->paths.nelts; i++) { |
467 | 606 |
669 | 607 if (ngx_create_dir(path[i]->name.data, 0700) == NGX_FILE_ERROR) { |
467 | 608 err = ngx_errno; |
609 if (err != NGX_EEXIST) { | |
610 ngx_log_error(NGX_LOG_EMERG, cycle->log, err, | |
611 ngx_create_dir_n " \"%s\" failed", | |
612 path[i]->name.data); | |
613 return NGX_ERROR; | |
614 } | |
615 } | |
616 | |
517 | 617 if (user == (ngx_uid_t) NGX_CONF_UNSET_UINT) { |
467 | 618 continue; |
619 } | |
620 | |
621 #if !(NGX_WIN32) | |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1695
diff
changeset
|
622 { |
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1695
diff
changeset
|
623 ngx_file_info_t fi; |
467 | 624 |
7032
d48c8cdac201
Removed excessive casts for ngx_file_info().
Ruslan Ermilov <ru@nginx.com>
parents:
6795
diff
changeset
|
625 if (ngx_file_info(path[i]->name.data, &fi) == NGX_FILE_ERROR) { |
467 | 626 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
627 ngx_file_info_n " \"%s\" failed", path[i]->name.data); | |
628 return NGX_ERROR; | |
629 } | |
630 | |
631 if (fi.st_uid != user) { | |
632 if (chown((const char *) path[i]->name.data, user, -1) == -1) { | |
633 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
634 "chown(\"%s\", %d) failed", | |
635 path[i]->name.data, user); | |
636 return NGX_ERROR; | |
637 } | |
638 } | |
639 | |
640 if ((fi.st_mode & (S_IRUSR|S_IWUSR|S_IXUSR)) | |
641 != (S_IRUSR|S_IWUSR|S_IXUSR)) | |
642 { | |
643 fi.st_mode |= (S_IRUSR|S_IWUSR|S_IXUSR); | |
644 | |
645 if (chmod((const char *) path[i]->name.data, fi.st_mode) == -1) { | |
646 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
647 "chmod() \"%s\" failed", path[i]->name.data); | |
648 return NGX_ERROR; | |
649 } | |
650 } | |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1695
diff
changeset
|
651 } |
467 | 652 #endif |
653 } | |
654 | |
655 return NGX_OK; | |
656 } | |
956 | 657 |
658 | |
659 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
|
660 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
|
661 { |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
662 u_char *name; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
663 ngx_err_t err; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
664 ngx_copy_file_t cf; |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
665 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
666 #if !(NGX_WIN32) |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
667 |
2394
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
668 if (ext->access) { |
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
669 if (ngx_change_file_access(src->data, ext->access) == NGX_FILE_ERROR) { |
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
670 ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno, |
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
671 ngx_change_file_access_n " \"%s\" failed", src->data); |
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
672 err = 0; |
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
673 goto failed; |
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
674 } |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
675 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
676 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
677 #endif |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
678 |
1826
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
679 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
|
680 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
|
681 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
|
682 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
|
683 err = 0; |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
684 goto failed; |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
685 } |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
686 } |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
687 |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
688 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
|
689 return NGX_OK; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
690 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
691 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
692 err = ngx_errno; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
693 |
3023 | 694 if (err == NGX_ENOPATH) { |
695 | |
1826
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
696 if (!ext->create_path) { |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
697 goto failed; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
698 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
699 |
2394
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
700 err = ngx_create_full_path(to->data, ngx_dir_access(ext->path_access)); |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
701 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
702 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
|
703 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
|
704 ngx_create_dir_n " \"%s\" failed", to->data); |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
705 err = 0; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
706 goto failed; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
707 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
708 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
709 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
|
710 return NGX_OK; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
711 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
712 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
713 err = ngx_errno; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
714 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
715 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
716 #if (NGX_WIN32) |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
717 |
6468
a5897d360977
Win32: additional error code NGX_EEXIST_FILE (ticket #910).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6442
diff
changeset
|
718 if (err == NGX_EEXIST || err == NGX_EEXIST_FILE) { |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3202
diff
changeset
|
719 err = ngx_win32_rename_file(src, to, ext->log); |
3387
a02b6d2e3bfd
fix Win32 error message when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
720 |
a02b6d2e3bfd
fix Win32 error message when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
721 if (err == 0) { |
a02b6d2e3bfd
fix Win32 error message when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
722 return NGX_OK; |
a02b6d2e3bfd
fix Win32 error message when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
723 } |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
724 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
725 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
726 #endif |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
727 |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
728 if (err == NGX_EXDEV) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
729 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
730 cf.size = -1; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
731 cf.buf_size = 0; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
732 cf.access = ext->access; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
733 cf.time = ext->time; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
734 cf.log = ext->log; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
735 |
3032
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3027
diff
changeset
|
736 name = ngx_alloc(to->len + 1 + 10 + 1, ext->log); |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
737 if (name == NULL) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
738 return NGX_ERROR; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
739 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
740 |
3032
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3027
diff
changeset
|
741 (void) ngx_sprintf(name, "%*s.%010uD%Z", to->len, to->data, |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
742 (uint32_t) ngx_next_temp_number(0)); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
743 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
744 if (ngx_copy_file(src->data, name, &cf) == NGX_OK) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
745 |
3033
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
746 if (ngx_rename_file(name, to->data) != NGX_FILE_ERROR) { |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
747 ngx_free(name); |
3033
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
748 |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
749 if (ngx_delete_file(src->data) == NGX_FILE_ERROR) { |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
750 ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno, |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
751 ngx_delete_file_n " \"%s\" failed", |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
752 src->data); |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
753 return NGX_ERROR; |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
754 } |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
755 |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
756 return NGX_OK; |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
757 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
758 |
3033
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
759 ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno, |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
760 ngx_rename_file_n " \"%s\" to \"%s\" failed", |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
761 name, to->data); |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
762 |
3033
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
763 if (ngx_delete_file(name) == NGX_FILE_ERROR) { |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
764 ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno, |
3033
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
765 ngx_delete_file_n " \"%s\" failed", name); |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
766 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
767 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
768 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
769 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
770 ngx_free(name); |
3033
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
771 |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
772 err = 0; |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
773 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
774 |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
775 failed: |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
776 |
1909 | 777 if (ext->delete_file) { |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
778 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
|
779 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
|
780 ngx_delete_file_n " \"%s\" failed", src->data); |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
781 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
782 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
783 |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
784 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
|
785 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
|
786 ngx_rename_file_n " \"%s\" to \"%s\" failed", |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
787 src->data, to->data); |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
788 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
789 |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
790 return NGX_ERROR; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
791 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
792 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
793 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
794 ngx_int_t |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
795 ngx_copy_file(u_char *from, u_char *to, ngx_copy_file_t *cf) |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
796 { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
797 char *buf; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
798 off_t size; |
7329
63a76a594dd8
Dav: changed ngx_copy_file() to preserve access and mtime.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7328
diff
changeset
|
799 time_t time; |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
800 size_t len; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
801 ssize_t n; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
802 ngx_fd_t fd, nfd; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
803 ngx_int_t rc; |
7329
63a76a594dd8
Dav: changed ngx_copy_file() to preserve access and mtime.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7328
diff
changeset
|
804 ngx_uint_t access; |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
805 ngx_file_info_t fi; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
806 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
807 rc = NGX_ERROR; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
808 buf = NULL; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
809 nfd = NGX_INVALID_FILE; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
810 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
811 fd = ngx_open_file(from, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
812 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
813 if (fd == NGX_INVALID_FILE) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
814 ngx_log_error(NGX_LOG_CRIT, cf->log, ngx_errno, |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
815 ngx_open_file_n " \"%s\" failed", from); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
816 goto failed; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
817 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
818 |
7329
63a76a594dd8
Dav: changed ngx_copy_file() to preserve access and mtime.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7328
diff
changeset
|
819 if (cf->size != -1 && cf->access != 0 && cf->time != -1) { |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
820 size = cf->size; |
7329
63a76a594dd8
Dav: changed ngx_copy_file() to preserve access and mtime.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7328
diff
changeset
|
821 access = cf->access; |
63a76a594dd8
Dav: changed ngx_copy_file() to preserve access and mtime.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7328
diff
changeset
|
822 time = cf->time; |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
823 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
824 } else { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
825 if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
826 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
827 ngx_fd_info_n " \"%s\" failed", from); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
828 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
829 goto failed; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
830 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
831 |
7329
63a76a594dd8
Dav: changed ngx_copy_file() to preserve access and mtime.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7328
diff
changeset
|
832 size = (cf->size != -1) ? cf->size : ngx_file_size(&fi); |
63a76a594dd8
Dav: changed ngx_copy_file() to preserve access and mtime.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7328
diff
changeset
|
833 access = cf->access ? cf->access : ngx_file_access(&fi); |
63a76a594dd8
Dav: changed ngx_copy_file() to preserve access and mtime.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7328
diff
changeset
|
834 time = (cf->time != -1) ? cf->time : ngx_file_mtime(&fi); |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
835 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
836 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
837 len = cf->buf_size ? cf->buf_size : 65536; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
838 |
3027
3e1b653fd22f
fix building on 64-bit platforms, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
839 if ((off_t) len > size) { |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
840 len = (size_t) size; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
841 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
842 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
843 buf = ngx_alloc(len, cf->log); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
844 if (buf == NULL) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
845 goto failed; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
846 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
847 |
7329
63a76a594dd8
Dav: changed ngx_copy_file() to preserve access and mtime.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7328
diff
changeset
|
848 nfd = ngx_open_file(to, NGX_FILE_WRONLY, NGX_FILE_TRUNCATE, access); |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
849 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
850 if (nfd == NGX_INVALID_FILE) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
851 ngx_log_error(NGX_LOG_CRIT, cf->log, ngx_errno, |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
852 ngx_open_file_n " \"%s\" failed", to); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
853 goto failed; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
854 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
855 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
856 while (size > 0) { |
2394
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
857 |
3027
3e1b653fd22f
fix building on 64-bit platforms, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
858 if ((off_t) len > size) { |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
859 len = (size_t) size; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
860 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
861 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
862 n = ngx_read_fd(fd, buf, len); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
863 |
4966
c821975c9068
Fixed handling of ngx_write_fd() and ngx_read_fd() errors.
Valentin Bartenev <vbart@nginx.com>
parents:
4870
diff
changeset
|
864 if (n == -1) { |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
865 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
866 ngx_read_fd_n " \"%s\" failed", from); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
867 goto failed; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
868 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
869 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
870 if ((size_t) n != len) { |
4966
c821975c9068
Fixed handling of ngx_write_fd() and ngx_read_fd() errors.
Valentin Bartenev <vbart@nginx.com>
parents:
4870
diff
changeset
|
871 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, |
6480 | 872 ngx_read_fd_n " has read only %z of %O from %s", |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
873 n, size, from); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
874 goto failed; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
875 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
876 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
877 n = ngx_write_fd(nfd, buf, len); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
878 |
4966
c821975c9068
Fixed handling of ngx_write_fd() and ngx_read_fd() errors.
Valentin Bartenev <vbart@nginx.com>
parents:
4870
diff
changeset
|
879 if (n == -1) { |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
880 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
881 ngx_write_fd_n " \"%s\" failed", to); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
882 goto failed; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
883 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
884 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
885 if ((size_t) n != len) { |
4966
c821975c9068
Fixed handling of ngx_write_fd() and ngx_read_fd() errors.
Valentin Bartenev <vbart@nginx.com>
parents:
4870
diff
changeset
|
886 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, |
6480 | 887 ngx_write_fd_n " has written only %z of %O to %s", |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
888 n, size, to); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
889 goto failed; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
890 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
891 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
892 size -= n; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
893 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
894 |
7329
63a76a594dd8
Dav: changed ngx_copy_file() to preserve access and mtime.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7328
diff
changeset
|
895 if (ngx_set_file_time(to, nfd, time) != NGX_OK) { |
63a76a594dd8
Dav: changed ngx_copy_file() to preserve access and mtime.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7328
diff
changeset
|
896 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, |
63a76a594dd8
Dav: changed ngx_copy_file() to preserve access and mtime.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7328
diff
changeset
|
897 ngx_set_file_time_n " \"%s\" failed", to); |
63a76a594dd8
Dav: changed ngx_copy_file() to preserve access and mtime.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7328
diff
changeset
|
898 goto failed; |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
899 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
900 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
901 rc = NGX_OK; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
902 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
903 failed: |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
904 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
905 if (nfd != NGX_INVALID_FILE) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
906 if (ngx_close_file(nfd) == NGX_FILE_ERROR) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
907 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
908 ngx_close_file_n " \"%s\" failed", to); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
909 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
910 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
911 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
912 if (fd != NGX_INVALID_FILE) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
913 if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
914 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
915 ngx_close_file_n " \"%s\" failed", from); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
916 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
917 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
918 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
919 if (buf) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
920 ngx_free(buf); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
921 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
922 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
923 return rc; |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
924 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
925 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
926 |
1750 | 927 /* |
928 * ctx->init_handler() - see ctx->alloc | |
929 * ctx->file_handler() - file handler | |
930 * ctx->pre_tree_handler() - handler is called before entering directory | |
931 * ctx->post_tree_handler() - handler is called after leaving directory | |
932 * ctx->spec_handler() - special (socket, FIFO, etc.) file handler | |
933 * | |
934 * ctx->data - some data structure, it may be the same on all levels, or | |
935 * reallocated if ctx->alloc is nonzero | |
936 * | |
937 * ctx->alloc - a size of data structure that is allocated at every level | |
4572
67653855682e
Fixed spelling in multiline C comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
938 * and is initialized by ctx->init_handler() |
1750 | 939 * |
940 * ctx->log - a log | |
941 * | |
942 * on fatal (memory) error handler must return NGX_ABORT to stop walking tree | |
943 */ | |
944 | |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
945 ngx_int_t |
956 | 946 ngx_walk_tree(ngx_tree_ctx_t *ctx, ngx_str_t *tree) |
947 { | |
948 void *data, *prev; | |
949 u_char *p, *name; | |
950 size_t len; | |
951 ngx_int_t rc; | |
952 ngx_err_t err; | |
977
b9836e87dd4d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
956
diff
changeset
|
953 ngx_str_t file, buf; |
956 | 954 ngx_dir_t dir; |
955 | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3481
diff
changeset
|
956 ngx_str_null(&buf); |
956 | 957 |
958 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
959 "walk tree \"%V\"", tree); | |
960 | |
961 if (ngx_open_dir(tree, &dir) == NGX_ERROR) { | |
962 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, | |
963 ngx_open_dir_n " \"%s\" failed", tree->data); | |
964 return NGX_ERROR; | |
965 } | |
966 | |
967 prev = ctx->data; | |
968 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
969 if (ctx->alloc) { |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
970 data = ngx_alloc(ctx->alloc, ctx->log); |
956 | 971 if (data == NULL) { |
972 goto failed; | |
973 } | |
974 | |
975 if (ctx->init_handler(data, prev) == NGX_ABORT) { | |
976 goto failed; | |
977 } | |
978 | |
979 ctx->data = data; | |
1319 | 980 |
981 } else { | |
982 data = NULL; | |
956 | 983 } |
984 | |
985 for ( ;; ) { | |
986 | |
987 ngx_set_errno(0); | |
988 | |
989 if (ngx_read_dir(&dir) == NGX_ERROR) { | |
990 err = ngx_errno; | |
991 | |
992 if (err == NGX_ENOMOREFILES) { | |
993 rc = NGX_OK; | |
994 | |
995 } else { | |
996 ngx_log_error(NGX_LOG_CRIT, ctx->log, err, | |
997 ngx_read_dir_n " \"%s\" failed", tree->data); | |
998 rc = NGX_ERROR; | |
999 } | |
1000 | |
1001 goto done; | |
1002 } | |
1003 | |
1004 len = ngx_de_namelen(&dir); | |
1005 name = ngx_de_name(&dir); | |
1006 | |
1007 ngx_log_debug2(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
1008 "tree name %uz:\"%s\"", len, name); | |
1009 | |
1010 if (len == 1 && name[0] == '.') { | |
1011 continue; | |
1012 } | |
1013 | |
1014 if (len == 2 && name[0] == '.' && name[1] == '.') { | |
1015 continue; | |
1016 } | |
1017 | |
1018 file.len = tree->len + 1 + len; | |
1019 | |
7433
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7329
diff
changeset
|
1020 if (file.len > buf.len) { |
956 | 1021 |
1022 if (buf.len) { | |
1023 ngx_free(buf.data); | |
1024 } | |
1025 | |
7433
061ec464813f
Win32: removed NGX_DIR_MASK concept.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7329
diff
changeset
|
1026 buf.len = tree->len + 1 + len; |
956 | 1027 |
1028 buf.data = ngx_alloc(buf.len + 1, ctx->log); | |
1029 if (buf.data == NULL) { | |
1030 goto failed; | |
1031 } | |
1032 } | |
1033 | |
1034 p = ngx_cpymem(buf.data, tree->data, tree->len); | |
1035 *p++ = '/'; | |
1036 ngx_memcpy(p, name, len + 1); | |
1037 | |
1038 file.data = buf.data; | |
1039 | |
1040 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
1041 "tree path \"%s\"", file.data); | |
1042 | |
1043 if (!dir.valid_info) { | |
1044 if (ngx_de_info(file.data, &dir) == NGX_FILE_ERROR) { | |
1045 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, | |
1046 ngx_de_info_n " \"%s\" failed", file.data); | |
1047 continue; | |
1048 } | |
1049 } | |
1050 | |
1051 if (ngx_de_is_file(&dir)) { | |
1052 | |
1053 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
1054 "tree file \"%s\"", file.data); | |
1055 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
1056 ctx->size = ngx_de_size(&dir); |
3970
2d05952a324d
elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
1057 ctx->fs_size = ngx_de_fs_size(&dir); |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
1058 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
|
1059 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
|
1060 |
956 | 1061 if (ctx->file_handler(ctx, &file) == NGX_ABORT) { |
1062 goto failed; | |
1063 } | |
1064 | |
1065 } else if (ngx_de_is_dir(&dir)) { | |
1066 | |
1067 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
1068 "tree enter dir \"%s\"", file.data); | |
1069 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
1070 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
|
1071 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
|
1072 |
5967
863d9de1e62b
Core: supported directory skipping in ngx_walk_tree().
Roman Arutyunyan <arut@nginx.com>
parents:
5958
diff
changeset
|
1073 rc = ctx->pre_tree_handler(ctx, &file); |
863d9de1e62b
Core: supported directory skipping in ngx_walk_tree().
Roman Arutyunyan <arut@nginx.com>
parents:
5958
diff
changeset
|
1074 |
863d9de1e62b
Core: supported directory skipping in ngx_walk_tree().
Roman Arutyunyan <arut@nginx.com>
parents:
5958
diff
changeset
|
1075 if (rc == NGX_ABORT) { |
956 | 1076 goto failed; |
1077 } | |
1078 | |
5967
863d9de1e62b
Core: supported directory skipping in ngx_walk_tree().
Roman Arutyunyan <arut@nginx.com>
parents:
5958
diff
changeset
|
1079 if (rc == NGX_DECLINED) { |
863d9de1e62b
Core: supported directory skipping in ngx_walk_tree().
Roman Arutyunyan <arut@nginx.com>
parents:
5958
diff
changeset
|
1080 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, |
863d9de1e62b
Core: supported directory skipping in ngx_walk_tree().
Roman Arutyunyan <arut@nginx.com>
parents:
5958
diff
changeset
|
1081 "tree skip dir \"%s\"", file.data); |
863d9de1e62b
Core: supported directory skipping in ngx_walk_tree().
Roman Arutyunyan <arut@nginx.com>
parents:
5958
diff
changeset
|
1082 continue; |
863d9de1e62b
Core: supported directory skipping in ngx_walk_tree().
Roman Arutyunyan <arut@nginx.com>
parents:
5958
diff
changeset
|
1083 } |
863d9de1e62b
Core: supported directory skipping in ngx_walk_tree().
Roman Arutyunyan <arut@nginx.com>
parents:
5958
diff
changeset
|
1084 |
956 | 1085 if (ngx_walk_tree(ctx, &file) == NGX_ABORT) { |
1086 goto failed; | |
1087 } | |
1088 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
1089 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
|
1090 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
|
1091 |
956 | 1092 if (ctx->post_tree_handler(ctx, &file) == NGX_ABORT) { |
1093 goto failed; | |
1094 } | |
1095 | |
1096 } else { | |
1097 | |
1098 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
1099 "tree special \"%s\"", file.data); | |
1100 | |
1101 if (ctx->spec_handler(ctx, &file) == NGX_ABORT) { | |
1102 goto failed; | |
1103 } | |
1104 } | |
1105 } | |
1106 | |
1107 failed: | |
1108 | |
1109 rc = NGX_ABORT; | |
1110 | |
1111 done: | |
1112 | |
1113 if (buf.len) { | |
1114 ngx_free(buf.data); | |
1115 } | |
1116 | |
1319 | 1117 if (data) { |
1118 ngx_free(data); | |
956 | 1119 ctx->data = prev; |
1120 } | |
1121 | |
1122 if (ngx_close_dir(&dir) == NGX_ERROR) { | |
1123 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, | |
1124 ngx_close_dir_n " \"%s\" failed", tree->data); | |
1125 } | |
1126 | |
1127 return rc; | |
1128 } |