| 431 | } |
| 432 | |
| 433 | apr_status_t md_util_freplace(const char *fpath, apr_fileperms_t perms, apr_pool_t *p, |
| 434 | md_util_file_cb *write_cb, void *baton) |
| 435 | { |
| 436 | apr_status_t rv = APR_EEXIST; |
| 437 | apr_file_t *f; |
| 438 | const char *tmp; |
| 439 | int i, max; |
| 440 | |
| 441 | tmp = apr_psprintf(p, "%s.tmp", fpath); |
| 442 | i = 0; max = 20; |
| 443 | creat: |
| 444 | while (i < max && APR_EEXIST == (rv = md_util_fcreatex(&f, tmp, perms, p))) { |
| 445 | ++i; |
| 446 | apr_sleep(apr_time_from_msec(50)); |
| 447 | } |
| 448 | if (APR_EEXIST == rv |
| 449 | && APR_SUCCESS == (rv = apr_file_remove(tmp, p)) |
| 450 | && max <= 20) { |
| 451 | max *= 2; |
| 452 | goto creat; |
| 453 | } |
| 454 | |
| 455 | if (APR_SUCCESS == rv) { |
| 456 | rv = write_cb(baton, f, p); |
| 457 | apr_file_close(f); |
| 458 | |
| 459 | if (APR_SUCCESS == rv) { |
| 460 | rv = apr_file_rename(tmp, fpath, p); |
| 461 | if (APR_SUCCESS != rv) { |
| 462 | apr_file_remove(tmp, p); |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | return rv; |
| 467 | } |
| 468 | |
| 469 | /**************************************************************************************************/ |
| 470 | /* text files */ |
no test coverage detected