Mercurial > hg > nginx-quic
annotate src/core/ngx_file.c @ 4569:1db899642518
Upstream: reject upstreams without normal servers.
Such upstreams cause CPU hog later in the code as number of peers isn't
expected to be 0. Currently this may happen either if there are only backup
servers defined in an upstream block, or if server with ipv6 address used
in an upstream block.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 02 Apr 2012 21:29:35 +0000 |
parents | d620f497c50f |
children | 67653855682e |
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 |
3035
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
12 static ngx_atomic_t temp_number = 0; |
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
13 ngx_atomic_t *ngx_temp_number = &temp_number; |
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
14 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
|
15 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
16 |
493 | 17 ssize_t |
18 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
|
19 { |
467 | 20 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
|
21 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
22 if (tf->file.fd == NGX_INVALID_FILE) { |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
23 rc = ngx_create_temp_file(&tf->file, tf->path, tf->pool, |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1058
diff
changeset
|
24 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
|
25 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
26 if (rc == NGX_ERROR || rc == NGX_AGAIN) { |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
27 return rc; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
28 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
29 |
667 | 30 if (tf->log_level) { |
31 ngx_log_error(tf->log_level, tf->file.log, 0, "%s %V", | |
637 | 32 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
|
33 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
34 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
35 |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
36 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
|
37 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
38 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
39 |
493 | 40 ngx_int_t |
41 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
|
42 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
|
43 { |
1090
01b48bcb73bf
shorten temporary names on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
44 uint32_t n; |
509 | 45 ngx_err_t err; |
563 | 46 ngx_pool_cleanup_t *cln; |
47 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
|
48 |
1091
58f1641783ca
allocate less memory on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1090
diff
changeset
|
49 file->name.len = path->name.len + 1 + path->len + 10; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
50 |
2049 | 51 file->name.data = ngx_pnalloc(pool, file->name.len + 1); |
501 | 52 if (file->name.data == NULL) { |
467 | 53 return NGX_ERROR; |
54 } | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 #if 0 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
57 for (i = 0; i < file->name.len; i++) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 file->name.data[i] = 'X'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
59 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
60 #endif |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
61 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
62 ngx_memcpy(file->name.data, path->name.data, path->name.len); |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
63 |
1090
01b48bcb73bf
shorten temporary names on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
64 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
|
65 |
1747 | 66 cln = ngx_pool_cleanup_add(pool, sizeof(ngx_pool_cleanup_file_t)); |
67 if (cln == NULL) { | |
68 return NGX_ERROR; | |
69 } | |
70 | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
71 for ( ;; ) { |
517 | 72 (void) ngx_sprintf(file->name.data + path->name.len + 1 + path->len, |
1090
01b48bcb73bf
shorten temporary names on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
73 "%010uD%Z", n); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
74 |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
75 ngx_create_hashed_filename(path, file->name.data, file->name.len); |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
76 |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
77 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
|
78 "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
|
79 |
1046 | 80 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
|
81 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
82 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
|
83 "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
|
84 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
85 if (file->fd != NGX_INVALID_FILE) { |
563 | 86 |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1058
diff
changeset
|
87 cln->handler = clean ? ngx_pool_delete_file : ngx_pool_cleanup_file; |
563 | 88 clnf = cln->data; |
509 | 89 |
563 | 90 clnf->fd = file->fd; |
91 clnf->name = file->name.data; | |
92 clnf->log = pool->log; | |
509 | 93 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
94 return NGX_OK; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
95 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
96 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
97 err = ngx_errno; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
98 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 if (err == NGX_EEXIST) { |
1090
01b48bcb73bf
shorten temporary names on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
100 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
|
101 continue; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
102 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
103 |
3023 | 104 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
|
105 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
|
106 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
|
107 file->name.data); |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
108 return NGX_ERROR; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
109 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
110 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
111 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
|
112 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
|
113 } |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
114 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
116 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
117 |
493 | 118 void |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
119 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
|
120 { |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
121 size_t i, level; |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
122 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
|
123 |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
124 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
|
125 |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
126 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
|
127 |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
128 for (n = 0; n < 3; n++) { |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
129 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
|
130 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
131 if (level == 0) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
132 break; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
133 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
134 |
1748
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
135 len -= level; |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
136 file[i - 1] = '/'; |
91d381e4e691
ngx_create_hashed_filename() does not need ngx_file_t
Igor Sysoev <igor@sysoev.ru>
parents:
1747
diff
changeset
|
137 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
|
138 i += level + 1; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
139 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
140 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
141 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
142 |
493 | 143 ngx_int_t |
144 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
|
145 { |
517 | 146 size_t pos; |
147 ngx_err_t err; | |
148 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
|
149 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
150 pos = path->name.len; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
151 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
152 for (i = 0; i < 3; i++) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
153 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
|
154 break; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
155 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
156 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 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
|
158 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 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
|
160 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
161 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
|
162 "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
|
163 |
669 | 164 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
|
165 err = ngx_errno; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 if (err != NGX_EEXIST) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 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
|
168 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
|
169 file->name.data); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
170 return NGX_ERROR; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
171 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
172 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
173 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
174 file->name.data[pos] = '/'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
175 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
176 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
177 return NGX_OK; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
178 } |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
179 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
180 |
637 | 181 ngx_err_t |
669 | 182 ngx_create_full_path(u_char *dir, ngx_uint_t access) |
637 | 183 { |
184 u_char *p, ch; | |
185 ngx_err_t err; | |
186 | |
3202
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
187 err = 0; |
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
188 |
3201
5fae6f9085e1
do not create Win32 drive letter in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
189 #if (NGX_WIN32) |
5fae6f9085e1
do not create Win32 drive letter in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
190 p = dir + 3; |
5fae6f9085e1
do not create Win32 drive letter in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
191 #else |
5fae6f9085e1
do not create Win32 drive letter in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
192 p = dir + 1; |
5fae6f9085e1
do not create Win32 drive letter in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
193 #endif |
5fae6f9085e1
do not create Win32 drive letter in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
194 |
5fae6f9085e1
do not create Win32 drive letter in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3035
diff
changeset
|
195 for ( /* void */ ; *p; p++) { |
637 | 196 ch = *p; |
197 | |
198 if (ch != '/') { | |
199 continue; | |
200 } | |
201 | |
202 *p = '\0'; | |
203 | |
669 | 204 if (ngx_create_dir(dir, access) == NGX_FILE_ERROR) { |
637 | 205 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
|
206 |
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
207 switch (err) { |
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
208 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
|
209 err = 0; |
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
210 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
|
211 break; |
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
212 |
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
213 default: |
637 | 214 return err; |
215 } | |
216 } | |
217 | |
218 *p = '/'; | |
219 } | |
220 | |
3202
121fae8c673c
ignore EACCES errors for top level directories in ngx_create_full_path()
Igor Sysoev <igor@sysoev.ru>
parents:
3201
diff
changeset
|
221 return err; |
637 | 222 } |
223 | |
224 | |
495 | 225 ngx_atomic_uint_t |
493 | 226 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
|
227 { |
3035
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
228 ngx_atomic_uint_t n, add; |
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
229 |
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
230 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
|
231 |
3035
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
232 n = ngx_atomic_fetch_add(ngx_temp_number, add); |
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
233 |
f9d97311c652
*) share temporary number between workers
Igor Sysoev <igor@sysoev.ru>
parents:
3034
diff
changeset
|
234 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
|
235 } |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
236 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
237 |
493 | 238 char * |
239 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
|
240 { |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
241 char *p = conf; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
242 |
467 | 243 ssize_t level; |
629 | 244 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
|
245 ngx_uint_t i, n; |
479 | 246 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
|
247 |
467 | 248 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
|
249 |
467 | 250 if (*slot) { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
251 return "is duplicate"; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
252 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
253 |
501 | 254 path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t)); |
255 if (path == NULL) { | |
467 | 256 return NGX_CONF_ERROR; |
257 } | |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
258 |
467 | 259 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
|
260 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
261 path->name = value[1]; |
629 | 262 |
661 | 263 if (path->name.data[path->name.len - 1] == '/') { |
264 path->name.len--; | |
265 } | |
266 | |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2394
diff
changeset
|
267 if (ngx_conf_full_name(cf->cycle, &path->name, 0) != NGX_OK) { |
629 | 268 return NULL; |
269 } | |
270 | |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
271 path->len = 0; |
3018 | 272 path->manager = NULL; |
273 path->loader = NULL; | |
467 | 274 path->conf_file = cf->conf_file->file.name.data; |
275 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
|
276 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
277 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
|
278 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
|
279 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
|
280 return "invalid value"; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
281 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
282 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
283 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
|
284 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
|
285 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
286 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
287 while (i < 3) { |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
288 path->level[i++] = 0; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
289 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
290 |
479 | 291 *slot = path; |
467 | 292 |
479 | 293 if (ngx_add_path(cf, slot) == NGX_ERROR) { |
294 return NGX_CONF_ERROR; | |
295 } | |
296 | |
297 return NGX_CONF_OK; | |
298 } | |
299 | |
300 | |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
301 char * |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
302 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
|
303 ngx_path_init_t *init) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
304 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
305 if (*path) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
306 return NGX_CONF_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
307 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
308 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
309 if (prev) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
310 *path = prev; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
311 return NGX_CONF_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
312 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
313 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
314 *path = ngx_palloc(cf->pool, sizeof(ngx_path_t)); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
315 if (*path == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
316 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
317 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
318 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
319 (*path)->name = init->name; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
320 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
321 if (ngx_conf_full_name(cf->cycle, &(*path)->name, 0) != NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
322 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
323 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
324 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
325 (*path)->level[0] = init->level[0]; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
326 (*path)->level[1] = init->level[1]; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
327 (*path)->level[2] = init->level[2]; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
328 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
329 (*path)->len = init->level[0] + (init->level[0] ? 1 : 0) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
330 + init->level[1] + (init->level[1] ? 1 : 0) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
331 + init->level[2] + (init->level[2] ? 1 : 0); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
332 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
333 (*path)->manager = NULL; |
3018 | 334 (*path)->loader = NULL; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
335 (*path)->conf_file = NULL; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
336 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
337 if (ngx_add_path(cf, path) != NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
338 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
339 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
340 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
341 return NGX_CONF_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
342 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
343 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
344 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
345 char * |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
346 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
|
347 { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
348 char *confp = conf; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
349 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
350 u_char *p; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
351 ngx_str_t *value; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
352 ngx_uint_t i, right, shift, *access; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
353 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
354 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
|
355 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
356 if (*access != NGX_CONF_UNSET_UINT) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
357 return "is duplicate"; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
358 } |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
359 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
360 value = cf->args->elts; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
361 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
362 *access = 0600; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
363 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
364 for (i = 1; i < cf->args->nelts; i++) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
365 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
366 p = value[i].data; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
367 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
368 if (ngx_strncmp(p, "user:", sizeof("user:") - 1) == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
369 shift = 6; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
370 p += sizeof("user:") - 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
371 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
372 } 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
|
373 shift = 3; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
374 p += sizeof("group:") - 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
375 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
376 } 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
|
377 shift = 0; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
378 p += sizeof("all:") - 1; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
379 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
380 } else { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
381 goto invalid; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
382 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
383 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
384 if (ngx_strcmp(p, "rw") == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
385 right = 6; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
386 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
387 } else if (ngx_strcmp(p, "r") == 0) { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
388 right = 4; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
389 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
390 } else { |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
391 goto invalid; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
392 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
393 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
394 *access |= right << shift; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
395 } |
1295
5383f5232364
proxy_store and fastcgi_store were changed,
Igor Sysoev <igor@sysoev.ru>
parents:
1291
diff
changeset
|
396 |
1291
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
397 return NGX_CONF_OK; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
398 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
399 invalid: |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
400 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
401 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
|
402 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
403 return NGX_CONF_ERROR; |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
404 } |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
405 |
13a4ce6e7f1e
proxy_store and fastcgi_store
Igor Sysoev <igor@sysoev.ru>
parents:
1091
diff
changeset
|
406 |
493 | 407 ngx_int_t |
408 ngx_add_path(ngx_conf_t *cf, ngx_path_t **slot) | |
479 | 409 { |
410 ngx_uint_t i, n; | |
411 ngx_path_t *path, **p; | |
412 | |
413 path = *slot; | |
414 | |
415 p = cf->cycle->pathes.elts; | |
467 | 416 for (i = 0; i < cf->cycle->pathes.nelts; i++) { |
479 | 417 if (p[i]->name.len == path->name.len |
418 && ngx_strcmp(p[i]->name.data, path->name.data) == 0) | |
467 | 419 { |
420 for (n = 0; n < 3; n++) { | |
479 | 421 if (p[i]->level[n] != path->level[n]) { |
422 if (path->conf_file == NULL) { | |
481 | 423 if (p[i]->conf_file == NULL) { |
424 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
425 "the default path name \"%V\" has " | |
426 "the same name as another default path, " | |
427 "but the different levels, you need to " | |
428 "redefine one of them in http section", | |
429 &p[i]->name); | |
430 return NGX_ERROR; | |
431 } | |
432 | |
479 | 433 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
434 "the path name \"%V\" in %s:%ui has " | |
481 | 435 "the same name as default path, but " |
479 | 436 "the different levels, you need to " |
437 "define default path in http section", | |
438 &p[i]->name, p[i]->conf_file, p[i]->line); | |
439 return NGX_ERROR; | |
440 } | |
441 | |
467 | 442 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
479 | 443 "the same path name \"%V\" in %s:%ui " |
444 "has the different levels than", | |
445 &p[i]->name, p[i]->conf_file, p[i]->line); | |
446 return NGX_ERROR; | |
467 | 447 } |
448 | |
479 | 449 if (p[i]->level[n] == 0) { |
467 | 450 break; |
451 } | |
452 } | |
453 | |
479 | 454 *slot = p[i]; |
467 | 455 |
479 | 456 return NGX_OK; |
467 | 457 } |
458 } | |
459 | |
501 | 460 p = ngx_array_push(&cf->cycle->pathes); |
461 if (p == NULL) { | |
479 | 462 return NGX_ERROR; |
467 | 463 } |
464 | |
479 | 465 *p = path; |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
466 |
479 | 467 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
|
468 } |
467 | 469 |
470 | |
493 | 471 ngx_int_t |
472 ngx_create_pathes(ngx_cycle_t *cycle, ngx_uid_t user) | |
467 | 473 { |
474 ngx_err_t err; | |
475 ngx_uint_t i; | |
476 ngx_path_t **path; | |
477 | |
478 path = cycle->pathes.elts; | |
479 for (i = 0; i < cycle->pathes.nelts; i++) { | |
480 | |
669 | 481 if (ngx_create_dir(path[i]->name.data, 0700) == NGX_FILE_ERROR) { |
467 | 482 err = ngx_errno; |
483 if (err != NGX_EEXIST) { | |
484 ngx_log_error(NGX_LOG_EMERG, cycle->log, err, | |
485 ngx_create_dir_n " \"%s\" failed", | |
486 path[i]->name.data); | |
487 return NGX_ERROR; | |
488 } | |
489 } | |
490 | |
517 | 491 if (user == (ngx_uid_t) NGX_CONF_UNSET_UINT) { |
467 | 492 continue; |
493 } | |
494 | |
495 #if !(NGX_WIN32) | |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1695
diff
changeset
|
496 { |
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1695
diff
changeset
|
497 ngx_file_info_t fi; |
467 | 498 |
2782
4bd7825fab80
uniform ngx_file_info() interface with ngx_fd_info()
Igor Sysoev <igor@sysoev.ru>
parents:
2616
diff
changeset
|
499 if (ngx_file_info((const char *) path[i]->name.data, &fi) |
4bd7825fab80
uniform ngx_file_info() interface with ngx_fd_info()
Igor Sysoev <igor@sysoev.ru>
parents:
2616
diff
changeset
|
500 == NGX_FILE_ERROR) |
4bd7825fab80
uniform ngx_file_info() interface with ngx_fd_info()
Igor Sysoev <igor@sysoev.ru>
parents:
2616
diff
changeset
|
501 { |
467 | 502 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
503 ngx_file_info_n " \"%s\" failed", path[i]->name.data); | |
504 return NGX_ERROR; | |
505 } | |
506 | |
507 if (fi.st_uid != user) { | |
508 if (chown((const char *) path[i]->name.data, user, -1) == -1) { | |
509 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
510 "chown(\"%s\", %d) failed", | |
511 path[i]->name.data, user); | |
512 return NGX_ERROR; | |
513 } | |
514 } | |
515 | |
516 if ((fi.st_mode & (S_IRUSR|S_IWUSR|S_IXUSR)) | |
517 != (S_IRUSR|S_IWUSR|S_IXUSR)) | |
518 { | |
519 fi.st_mode |= (S_IRUSR|S_IWUSR|S_IXUSR); | |
520 | |
521 if (chmod((const char *) path[i]->name.data, fi.st_mode) == -1) { | |
522 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
523 "chmod() \"%s\" failed", path[i]->name.data); | |
524 return NGX_ERROR; | |
525 } | |
526 } | |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1695
diff
changeset
|
527 } |
467 | 528 #endif |
529 } | |
530 | |
531 return NGX_OK; | |
532 } | |
956 | 533 |
534 | |
535 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
|
536 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
|
537 { |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
538 u_char *name; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
539 ngx_err_t err; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
540 ngx_copy_file_t cf; |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
541 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
542 #if !(NGX_WIN32) |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
543 |
2394
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
544 if (ext->access) { |
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
545 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
|
546 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
|
547 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
|
548 err = 0; |
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
549 goto failed; |
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
550 } |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
551 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
552 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
553 #endif |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
554 |
1826
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
555 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
|
556 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
|
557 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
|
558 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
|
559 err = 0; |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
560 goto failed; |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
561 } |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
562 } |
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
563 |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
564 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
|
565 return NGX_OK; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
566 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
567 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
568 err = ngx_errno; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
569 |
3023 | 570 if (err == NGX_ENOPATH) { |
571 | |
1826
8d50173ccba2
transform ngx_create_path_and_rename_file() to ngx_ext_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1750
diff
changeset
|
572 if (!ext->create_path) { |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
573 goto failed; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
574 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
575 |
2394
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
576 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
|
577 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
578 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
|
579 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
|
580 ngx_create_dir_n " \"%s\" failed", to->data); |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
581 err = 0; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
582 goto failed; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
583 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
584 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
585 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
|
586 return NGX_OK; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
587 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
588 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
589 err = ngx_errno; |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
590 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
591 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
592 #if (NGX_WIN32) |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
593 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
594 if (err == NGX_EEXIST) { |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3202
diff
changeset
|
595 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
|
596 |
a02b6d2e3bfd
fix Win32 error message when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
597 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
|
598 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
|
599 } |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
600 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
601 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
602 #endif |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
603 |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
604 if (err == NGX_EXDEV) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
605 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
606 cf.size = -1; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
607 cf.buf_size = 0; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
608 cf.access = ext->access; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
609 cf.time = ext->time; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
610 cf.log = ext->log; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
611 |
3032
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3027
diff
changeset
|
612 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
|
613 if (name == NULL) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
614 return NGX_ERROR; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
615 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
616 |
3032
524ba56ba9f7
fix copy destination name length, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3027
diff
changeset
|
617 (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
|
618 (uint32_t) ngx_next_temp_number(0)); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
619 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
620 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
|
621 |
3033
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
622 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
|
623 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
|
624 |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
625 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
|
626 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
|
627 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
|
628 src->data); |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
629 return NGX_ERROR; |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
630 } |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
631 |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
632 return NGX_OK; |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
633 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
634 |
3033
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
635 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
|
636 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
|
637 name, to->data); |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
638 |
3033
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
639 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
|
640 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
|
641 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
|
642 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
643 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
644 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
645 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
646 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
|
647 |
db3e5c4c7413
fix copy failure logging and stale files removal, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3032
diff
changeset
|
648 err = 0; |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
649 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
650 |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
651 failed: |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
652 |
1909 | 653 if (ext->delete_file) { |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
654 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
|
655 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
|
656 ngx_delete_file_n " \"%s\" failed", src->data); |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
657 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
658 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
659 |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
660 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
|
661 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
|
662 ngx_rename_file_n " \"%s\" to \"%s\" failed", |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
663 src->data, to->data); |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
664 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
665 |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
666 return NGX_ERROR; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
667 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
668 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
669 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
670 ngx_int_t |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
671 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
|
672 { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
673 char *buf; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
674 off_t size; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
675 size_t len; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
676 ssize_t n; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
677 ngx_fd_t fd, nfd; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
678 ngx_int_t rc; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
679 ngx_file_info_t fi; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
680 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
681 rc = NGX_ERROR; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
682 buf = NULL; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
683 nfd = NGX_INVALID_FILE; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
684 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
685 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
|
686 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
687 if (fd == NGX_INVALID_FILE) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
688 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
|
689 ngx_open_file_n " \"%s\" failed", from); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
690 goto failed; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
691 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
692 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
693 if (cf->size != -1) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
694 size = cf->size; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
695 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
696 } else { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
697 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
|
698 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
|
699 ngx_fd_info_n " \"%s\" failed", from); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
700 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
701 goto failed; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
702 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
703 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
704 size = ngx_file_size(&fi); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
705 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
706 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
707 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
|
708 |
3027
3e1b653fd22f
fix building on 64-bit platforms, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
709 if ((off_t) len > size) { |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
710 len = (size_t) size; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
711 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
712 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
713 buf = ngx_alloc(len, cf->log); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
714 if (buf == NULL) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
715 goto failed; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
716 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
717 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
718 nfd = ngx_open_file(to, NGX_FILE_WRONLY, NGX_FILE_CREATE_OR_OPEN, |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
719 cf->access); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
720 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
721 if (nfd == NGX_INVALID_FILE) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
722 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
|
723 ngx_open_file_n " \"%s\" failed", to); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
724 goto failed; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
725 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
726 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
727 while (size > 0) { |
2394
dbe746851b31
use ngx_ext_rename_file() for single file MOVE
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
728 |
3027
3e1b653fd22f
fix building on 64-bit platforms, introduced in r3025
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
729 if ((off_t) len > size) { |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
730 len = (size_t) size; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
731 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
732 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
733 n = ngx_read_fd(fd, buf, len); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
734 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
735 if (n == NGX_FILE_ERROR) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
736 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
|
737 ngx_read_fd_n " \"%s\" failed", from); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
738 goto failed; |
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 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
741 if ((size_t) n != len) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
742 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
|
743 ngx_read_fd_n " has read only %z of %uz from %s", |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
744 n, size, from); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
745 goto failed; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
746 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
747 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
748 n = ngx_write_fd(nfd, buf, len); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
749 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
750 if (n == NGX_FILE_ERROR) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
751 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
|
752 ngx_write_fd_n " \"%s\" failed", to); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
753 goto failed; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
754 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
755 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
756 if ((size_t) n != len) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
757 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
|
758 ngx_write_fd_n " has written only %z of %uz to %s", |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
759 n, size, to); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
760 goto failed; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
761 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
762 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
763 size -= n; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
764 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
765 |
3481
35e258519a83
do not set file time in ngx_copy_file() if the time is -1,
Igor Sysoev <igor@sysoev.ru>
parents:
3387
diff
changeset
|
766 if (cf->time != -1) { |
35e258519a83
do not set file time in ngx_copy_file() if the time is -1,
Igor Sysoev <igor@sysoev.ru>
parents:
3387
diff
changeset
|
767 if (ngx_set_file_time(to, nfd, cf->time) != NGX_OK) { |
35e258519a83
do not set file time in ngx_copy_file() if the time is -1,
Igor Sysoev <igor@sysoev.ru>
parents:
3387
diff
changeset
|
768 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, |
35e258519a83
do not set file time in ngx_copy_file() if the time is -1,
Igor Sysoev <igor@sysoev.ru>
parents:
3387
diff
changeset
|
769 ngx_set_file_time_n " \"%s\" failed", to); |
35e258519a83
do not set file time in ngx_copy_file() if the time is -1,
Igor Sysoev <igor@sysoev.ru>
parents:
3387
diff
changeset
|
770 goto failed; |
35e258519a83
do not set file time in ngx_copy_file() if the time is -1,
Igor Sysoev <igor@sysoev.ru>
parents:
3387
diff
changeset
|
771 } |
3024
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
772 } |
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 rc = NGX_OK; |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
775 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
776 failed: |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
777 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
778 if (nfd != NGX_INVALID_FILE) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
779 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
|
780 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
|
781 ngx_close_file_n " \"%s\" failed", to); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
782 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
783 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
784 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
785 if (fd != NGX_INVALID_FILE) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
786 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
|
787 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
|
788 ngx_close_file_n " \"%s\" failed", from); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
789 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
790 } |
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 if (buf) { |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
793 ngx_free(buf); |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
794 } |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
795 |
8101d9101ed8
allow cross device temporary files atomic copying:
Igor Sysoev <igor@sysoev.ru>
parents:
3023
diff
changeset
|
796 return rc; |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
797 } |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
798 |
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
799 |
1750 | 800 /* |
801 * ctx->init_handler() - see ctx->alloc | |
802 * ctx->file_handler() - file handler | |
803 * ctx->pre_tree_handler() - handler is called before entering directory | |
804 * ctx->post_tree_handler() - handler is called after leaving directory | |
805 * ctx->spec_handler() - special (socket, FIFO, etc.) file handler | |
806 * | |
807 * ctx->data - some data structure, it may be the same on all levels, or | |
808 * reallocated if ctx->alloc is nonzero | |
809 * | |
810 * ctx->alloc - a size of data structure that is allocated at every level | |
811 * and is initilialized by ctx->init_handler() | |
812 * | |
813 * ctx->log - a log | |
814 * | |
815 * on fatal (memory) error handler must return NGX_ABORT to stop walking tree | |
816 */ | |
817 | |
1695
8c4532a48b0a
ngx_create_path_and_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
818 ngx_int_t |
956 | 819 ngx_walk_tree(ngx_tree_ctx_t *ctx, ngx_str_t *tree) |
820 { | |
821 void *data, *prev; | |
822 u_char *p, *name; | |
823 size_t len; | |
824 ngx_int_t rc; | |
825 ngx_err_t err; | |
977
b9836e87dd4d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
956
diff
changeset
|
826 ngx_str_t file, buf; |
956 | 827 ngx_dir_t dir; |
828 | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3481
diff
changeset
|
829 ngx_str_null(&buf); |
956 | 830 |
831 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
832 "walk tree \"%V\"", tree); | |
833 | |
834 if (ngx_open_dir(tree, &dir) == NGX_ERROR) { | |
835 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, | |
836 ngx_open_dir_n " \"%s\" failed", tree->data); | |
837 return NGX_ERROR; | |
838 } | |
839 | |
840 prev = ctx->data; | |
841 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
842 if (ctx->alloc) { |
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
843 data = ngx_alloc(ctx->alloc, ctx->log); |
956 | 844 if (data == NULL) { |
845 goto failed; | |
846 } | |
847 | |
848 if (ctx->init_handler(data, prev) == NGX_ABORT) { | |
849 goto failed; | |
850 } | |
851 | |
852 ctx->data = data; | |
1319 | 853 |
854 } else { | |
855 data = NULL; | |
956 | 856 } |
857 | |
858 for ( ;; ) { | |
859 | |
860 ngx_set_errno(0); | |
861 | |
862 if (ngx_read_dir(&dir) == NGX_ERROR) { | |
863 err = ngx_errno; | |
864 | |
865 if (err == NGX_ENOMOREFILES) { | |
866 rc = NGX_OK; | |
867 | |
868 } else { | |
869 ngx_log_error(NGX_LOG_CRIT, ctx->log, err, | |
870 ngx_read_dir_n " \"%s\" failed", tree->data); | |
871 rc = NGX_ERROR; | |
872 } | |
873 | |
874 goto done; | |
875 } | |
876 | |
877 len = ngx_de_namelen(&dir); | |
878 name = ngx_de_name(&dir); | |
879 | |
880 ngx_log_debug2(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
881 "tree name %uz:\"%s\"", len, name); | |
882 | |
883 if (len == 1 && name[0] == '.') { | |
884 continue; | |
885 } | |
886 | |
887 if (len == 2 && name[0] == '.' && name[1] == '.') { | |
888 continue; | |
889 } | |
890 | |
891 file.len = tree->len + 1 + len; | |
892 | |
893 if (file.len + NGX_DIR_MASK_LEN > buf.len) { | |
894 | |
895 if (buf.len) { | |
896 ngx_free(buf.data); | |
897 } | |
898 | |
899 buf.len = tree->len + 1 + len + NGX_DIR_MASK_LEN; | |
900 | |
901 buf.data = ngx_alloc(buf.len + 1, ctx->log); | |
902 if (buf.data == NULL) { | |
903 goto failed; | |
904 } | |
905 } | |
906 | |
907 p = ngx_cpymem(buf.data, tree->data, tree->len); | |
908 *p++ = '/'; | |
909 ngx_memcpy(p, name, len + 1); | |
910 | |
911 file.data = buf.data; | |
912 | |
913 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
914 "tree path \"%s\"", file.data); | |
915 | |
916 if (!dir.valid_info) { | |
917 if (ngx_de_info(file.data, &dir) == NGX_FILE_ERROR) { | |
918 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, | |
919 ngx_de_info_n " \"%s\" failed", file.data); | |
920 continue; | |
921 } | |
922 } | |
923 | |
924 if (ngx_de_is_file(&dir)) { | |
925 | |
926 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
927 "tree file \"%s\"", file.data); | |
928 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
929 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
|
930 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
|
931 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
|
932 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
|
933 |
956 | 934 if (ctx->file_handler(ctx, &file) == NGX_ABORT) { |
935 goto failed; | |
936 } | |
937 | |
938 } else if (ngx_de_is_dir(&dir)) { | |
939 | |
940 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
941 "tree enter dir \"%s\"", file.data); | |
942 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
943 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
|
944 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
|
945 |
956 | 946 if (ctx->pre_tree_handler(ctx, &file) == NGX_ABORT) { |
947 goto failed; | |
948 } | |
949 | |
950 if (ngx_walk_tree(ctx, &file) == NGX_ABORT) { | |
951 goto failed; | |
952 } | |
953 | |
1058
01f818c6f7de
add size, access, and mtime to ngx_walk_tree()
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
954 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
|
955 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
|
956 |
956 | 957 if (ctx->post_tree_handler(ctx, &file) == NGX_ABORT) { |
958 goto failed; | |
959 } | |
960 | |
961 } else { | |
962 | |
963 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0, | |
964 "tree special \"%s\"", file.data); | |
965 | |
966 if (ctx->spec_handler(ctx, &file) == NGX_ABORT) { | |
967 goto failed; | |
968 } | |
969 } | |
970 } | |
971 | |
972 failed: | |
973 | |
974 rc = NGX_ABORT; | |
975 | |
976 done: | |
977 | |
978 if (buf.len) { | |
979 ngx_free(buf.data); | |
980 } | |
981 | |
1319 | 982 if (data) { |
983 ngx_free(data); | |
956 | 984 ctx->data = prev; |
985 } | |
986 | |
987 if (ngx_close_dir(&dir) == NGX_ERROR) { | |
988 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, | |
989 ngx_close_dir_n " \"%s\" failed", tree->data); | |
990 } | |
991 | |
992 return rc; | |
993 } |