]> granicus.if.org Git - apache/commitdiff
- Use apr_file_mktemp() and rename the header data file to its final location, instea...
authorPaul Querna <pquerna@apache.org>
Sat, 11 Jun 2005 00:26:19 +0000 (00:26 +0000)
committerPaul Querna <pquerna@apache.org>
Sat, 11 Jun 2005 00:26:19 +0000 (00:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@190043 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
modules/cache/mod_disk_cache.c

diff --git a/CHANGES b/CHANGES
index 5201d1a35dffb22aeb6abdecec0b049a0ed80f16..2fc99443afd5c2d6028c257c9c8f37a426990318 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,8 @@ Changes with Apache 2.1.5
 
   [Remove entries to the current 2.0 section below, when backported]
 
+  *) mod_disk_cache: Atomically create the header data file. [Paul Querna]
+
   *) mod_cache: Fix 'Vary: *' behavior to be RFC compliant. PR 16125. 
      [Paul Querna]
 
index b7365c47422f1844ce86834d7396c0acdebfa8ea..5e46c870ee590db4ddaa086d58627b5addf5fab4 100644 (file)
@@ -535,21 +535,14 @@ static apr_status_t store_headers(cache_handle_t *h, request_rec *r, cache_info
     /* This is flaky... we need to manage the cache_info differently */
     h->cache_obj->info = *info;
 
-    /* Remove old file with the same name. If remove fails, then
-     * perhaps we need to create the directory tree where we are
-     * about to write the new headers file.
-     */
-    rv = apr_file_remove(dobj->hdrsfile, r->pool);
-    if (rv != APR_SUCCESS) {
-        mkdir_structure(conf, dobj->hdrsfile, r->pool);
-    }
+    rv = apr_file_mktemp(&dobj->hfd, dobj->tempfile,
+                         APR_CREATE | APR_WRITE | APR_BINARY |
+                         APR_BUFFERED | APR_EXCL, r->pool);
 
-    rv = apr_file_open(&dobj->hfd, dobj->hdrsfile,
-                       APR_WRITE | APR_CREATE | APR_EXCL,
-                       APR_OS_DEFAULT, r->pool);
     if (rv != APR_SUCCESS) {
         return rv;
     }
+
     dobj->name = h->cache_obj->key;
 
     disk_info.format = DISK_FORMAT_VERSION;
@@ -607,6 +600,26 @@ static apr_status_t store_headers(cache_handle_t *h, request_rec *r, cache_info
     
     apr_file_close(dobj->hfd); /* flush and close */
 
+    /* Remove old file with the same name. If remove fails, then
+     * perhaps we need to create the directory tree where we are
+     * about to write the new headers file.
+     */
+    rv = apr_file_remove(dobj->hdrsfile, r->pool);
+    if (rv != APR_SUCCESS) {
+        mkdir_structure(conf, dobj->hdrsfile, r->pool);
+    }
+    
+    rv = apr_file_rename(dobj->tempfile, dobj->hdrsfile, r->pool);
+
+    if (rv != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, rv, r->server,
+                     "disk_cache: rename tempfile to hdrsfile failed: %s -> %s",
+                     dobj->tempfile, dobj->hdrsfile);
+        return rv;
+    }
+
+    dobj->tempfile = apr_pstrcat(r->pool, conf->cache_root, AP_TEMPFILE, NULL);
+
     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
                  "disk_cache: Stored headers for URL %s",  dobj->name);
     return APR_SUCCESS;