Mercurial > hg > nginx
comparison src/http/modules/ngx_http_dav_module.c @ 1828:1f3c2b6607e0
use ngx_ext_rename_file() in PUT
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 03 Jan 2008 22:18:21 +0000 |
parents | 2e0fbfef56d4 |
children | bf8666beb499 |
comparison
equal
deleted
inserted
replaced
1827:cb9d4278b476 | 1828:1f3c2b6607e0 |
---|---|
205 | 205 |
206 | 206 |
207 static void | 207 static void |
208 ngx_http_dav_put_handler(ngx_http_request_t *r) | 208 ngx_http_dav_put_handler(ngx_http_request_t *r) |
209 { | 209 { |
210 char *failed; | |
211 u_char *name; | |
212 size_t root; | 210 size_t root; |
213 time_t date; | 211 time_t date; |
214 ngx_err_t err; | |
215 ngx_str_t *temp, path; | 212 ngx_str_t *temp, path; |
216 ngx_uint_t status, not_found; | 213 ngx_uint_t status; |
217 ngx_file_info_t fi; | 214 ngx_file_info_t fi; |
215 ngx_ext_rename_file_t ext; | |
218 ngx_http_dav_loc_conf_t *dlcf; | 216 ngx_http_dav_loc_conf_t *dlcf; |
219 | 217 |
220 ngx_http_map_uri_to_path(r, &path, &root, 0); | 218 ngx_http_map_uri_to_path(r, &path, &root, 0); |
221 | 219 |
222 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 220 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
245 } | 243 } |
246 } | 244 } |
247 | 245 |
248 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module); | 246 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module); |
249 | 247 |
250 #if !(NGX_WIN32) | 248 ext.access = dlcf->access; |
251 | 249 ext.time = -1; |
252 if (ngx_change_file_access(temp->data, dlcf->access) == NGX_FILE_ERROR) { | 250 ext.create_path = dlcf->create_full_put_path; |
253 err = ngx_errno; | 251 ext.delete = 1; |
254 not_found = NGX_HTTP_INTERNAL_SERVER_ERROR; | 252 ext.log = r->connection->log; |
255 failed = ngx_change_file_access_n; | |
256 name = temp->data; | |
257 | |
258 goto failed; | |
259 } | |
260 | |
261 #endif | |
262 | 253 |
263 if (r->headers_in.date) { | 254 if (r->headers_in.date) { |
264 date = ngx_http_parse_time(r->headers_in.date->value.data, | 255 date = ngx_http_parse_time(r->headers_in.date->value.data, |
265 r->headers_in.date->value.len); | 256 r->headers_in.date->value.len); |
266 | 257 |
267 if (date != NGX_ERROR) { | 258 if (date != NGX_ERROR) { |
268 if (ngx_set_file_time(temp->data, | 259 ext.time = date; |
269 r->request_body->temp_file->file.fd, date) | 260 ext.fd = r->request_body->temp_file->file.fd; |
270 != NGX_OK) | 261 } |
271 { | 262 } |
272 err = ngx_errno; | 263 |
273 not_found = NGX_HTTP_INTERNAL_SERVER_ERROR; | 264 if (ngx_ext_rename_file(temp, &path, &ext) != NGX_OK) { |
274 failed = ngx_set_file_time_n; | 265 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
275 name = temp->data; | 266 return; |
276 | 267 } |
277 goto failed; | |
278 } | |
279 } | |
280 } | |
281 | |
282 not_found = NGX_HTTP_CONFLICT; | |
283 failed = ngx_rename_file_n; | |
284 name = path.data; | |
285 | |
286 if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) { | |
287 goto ok; | |
288 } | |
289 | |
290 err = ngx_errno; | |
291 | |
292 if (err == NGX_ENOENT) { | |
293 | |
294 if (dlcf->create_full_put_path) { | |
295 err = ngx_create_full_path(path.data, ngx_dir_access(dlcf->access)); | |
296 | |
297 if (err == 0) { | |
298 if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) { | |
299 goto ok; | |
300 } | |
301 | |
302 err = ngx_errno; | |
303 } | |
304 } | |
305 } | |
306 | |
307 #if (NGX_WIN32) | |
308 | |
309 if (err == NGX_EEXIST) { | |
310 if (ngx_win32_rename_file(temp, &path, r->connection->log) == NGX_OK) { | |
311 | |
312 if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) { | |
313 goto ok; | |
314 } | |
315 } | |
316 | |
317 err = ngx_errno; | |
318 } | |
319 | |
320 #endif | |
321 | |
322 failed: | |
323 | |
324 if (ngx_delete_file(temp->data) == NGX_FILE_ERROR) { | |
325 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, | |
326 ngx_delete_file_n " \"%s\" failed", | |
327 temp->data); | |
328 } | |
329 | |
330 ngx_http_finalize_request(r, | |
331 ngx_http_dav_error(r->connection->log, err, | |
332 not_found, failed, name)); | |
333 | |
334 return; | |
335 | |
336 ok: | |
337 | 268 |
338 if (status == NGX_HTTP_CREATED) { | 269 if (status == NGX_HTTP_CREATED) { |
339 if (ngx_http_dav_location(r, path.data) != NGX_OK) { | 270 if (ngx_http_dav_location(r, path.data) != NGX_OK) { |
340 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 271 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
341 return; | 272 return; |