diff -ru httpd-2.0.50.orig/modules/experimental/mod_disk_cache.c httpd-2.0.50/modules/experimental/mod_disk_cache.c --- httpd-2.0.50.orig/modules/experimental/mod_disk_cache.c 2004-02-09 21:53:16.000000000 +0100 +++ httpd-2.0.50/modules/experimental/mod_disk_cache.c 2004-08-18 22:28:46.000000000 +0200 @@ -116,7 +116,8 @@ *p = '\0'; rv = apr_dir_make(file, - APR_UREAD|APR_UWRITE|APR_UEXECUTE, pool); + APR_UREAD|APR_UWRITE|APR_UEXECUTE| + APR_GREAD|APR_GWRITE|APR_GEXECUTE, pool); if (rv != APR_SUCCESS && !APR_STATUS_IS_EEXIST(rv)) { /* XXX */ } @@ -135,6 +136,24 @@ /* move the data over */ if (dobj->fd) { apr_file_flush(dobj->fd); + /* Check if connection has been aborted. Do not rename the temporary + * file in this case but simply delete it. Reason: Aborted connections + * may lead to incomplete data files which MUST not be cached as + * they deliver incomplete content in future requests. + */ + if (r->connection->aborted) { + apr_file_close(dobj->fd); + dobj->fd = NULL; + rv = apr_file_remove(dobj->tempfile, r->pool); + if (rv != APR_SUCCESS) { + /* XXX log */ + } + ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, + "cache_disk: Discarding body for URL %s " + "because connection has been aborted.", + h->cache_obj->key); + return APR_INCOMPLETE; + } if (!dobj->datafile) { dobj->datafile = data_file(r->pool, conf->dirlevels, conf->dirlength, conf->cache_root, h->cache_obj->key); @@ -631,7 +650,7 @@ if (!dobj->fd) { rv = apr_file_open(&dobj->fd, dobj->tempfile, APR_WRITE | APR_CREATE | APR_BINARY| APR_TRUNCATE | APR_BUFFERED, - APR_UREAD | APR_UWRITE, r->pool); + APR_OS_DEFAULT, r->pool); if (rv != APR_SUCCESS) { return rv; } @@ -643,9 +662,10 @@ apr_file_write(dobj->fd, str, &length); } if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(b))) { - file_cache_el_final(h, r); /* Link to the perm file, and close the descriptor */ - ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, - "disk_cache: Cached body for URL %s", dobj->name); + if (file_cache_el_final(h, r) == APR_SUCCESS) { /* Link to the perm file, and close the descriptor */ + ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server, + "disk_cache: Cached body for URL %s", dobj->name); + } } return APR_SUCCESS;