View | Details | Raw Unified | Return to bug 41362
Collapse All | Expand All

(-)mod_disk_cache.c (-65 / +77 lines)
Lines 1457-1462 Link Here
1457
static apr_status_t store_disk_header(disk_cache_object_t *dobj,
1457
static apr_status_t store_disk_header(disk_cache_object_t *dobj,
1458
                                       request_rec *r, cache_info *info)
1458
                                       request_rec *r, cache_info *info)
1459
{
1459
{
1460
	if ( dobj->initial_size < 0) return APR_SUCCESS; //do not store incorrect size. GG
1460
    disk_cache_format_t format = DISK_FORMAT_VERSION;
1461
    disk_cache_format_t format = DISK_FORMAT_VERSION;
1461
    struct iovec iov[3];
1462
    struct iovec iov[3];
1462
    int niov;
1463
    int niov;
Lines 1472-1493 Link Here
1472
    disk_info.status = info->status;
1473
    disk_info.status = info->status;
1473
    disk_info.file_size = dobj->initial_size;
1474
    disk_info.file_size = dobj->initial_size;
1474
1475
1475
    niov = 0;
1476
		
1476
    iov[niov].iov_base = (void*)&format;
1477
	niov = 0;
1477
    iov[niov++].iov_len = sizeof(format);
1478
	iov[niov].iov_base = (void*)&format;
1478
    iov[niov].iov_base = (void*)&disk_info;
1479
	iov[niov++].iov_len = sizeof(format);
1479
    iov[niov++].iov_len = sizeof(disk_cache_info_t);
1480
	iov[niov].iov_base = (void*)&disk_info;
1481
	iov[niov++].iov_len = sizeof(disk_cache_info_t);
1480
1482
1481
    disk_info.name_len = strlen(dobj->name);
1483
	disk_info.name_len = strlen(dobj->name);
1482
    iov[niov].iov_base = (void*)dobj->name;
1484
	iov[niov].iov_base = (void*)dobj->name;
1483
    iov[niov++].iov_len = disk_info.name_len;
1485
	iov[niov++].iov_len = disk_info.name_len;
1484
1486
1485
    rv = apr_file_writev(dobj->hfd, (const struct iovec *) &iov, niov, &amt);
1487
	rv = apr_file_writev(dobj->hfd, (const struct iovec *) &iov, niov, &amt);
1486
    if (rv != APR_SUCCESS) {
1488
	if (rv != APR_SUCCESS) {
1487
        file_cache_errorcleanup(dobj, r);
1489
		file_cache_errorcleanup(dobj, r);
1488
        return rv;
1490
		return rv;
1489
    }
1491
	}
1492
	
1490
1493
1494
1491
    if (r->headers_out) {
1495
    if (r->headers_out) {
1492
        apr_table_t *headers_out;
1496
        apr_table_t *headers_out;
1493
1497
Lines 1536-1542 Link Here
1536
    int flags=0, rewriting;
1540
    int flags=0, rewriting;
1537
    disk_cache_object_t *dobj = (disk_cache_object_t*) h->cache_obj->vobj;
1541
    disk_cache_object_t *dobj = (disk_cache_object_t*) h->cache_obj->vobj;
1538
1542
1539
1540
    /* This is flaky... we need to manage the cache_info differently */
1543
    /* This is flaky... we need to manage the cache_info differently */
1541
    h->cache_obj->info = *info;
1544
    h->cache_obj->info = *info;
1542
1545
Lines 1845-1908 Link Here
1845
1848
1846
        apr_brigade_cleanup(dobj->tmpbb);
1849
        apr_brigade_cleanup(dobj->tmpbb);
1847
1850
1848
    }
1849
1851
1850
    
1852
		// EOS, so we update the headers. GG
1851
    /* Drop out here if this wasn't the end */
1853
		if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(bb))) {
1852
    if (!APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(bb))) {
1854
		
1853
        return APR_SUCCESS;
1855
			ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
1854
    }
1856
						 "disk_cache: Done caching URL %s, len %" APR_OFF_T_FMT,
1857
						 dobj->name, dobj->file_size);
1858
		
1859
			if (APR_SUCCESS != dobj->frv) {
1860
				ap_log_error(APLOG_MARK, APLOG_ERR, dobj->frv, r->server,
1861
							 "disk_cache: An error occurred while writing to the "
1862
							 "network for URL %s.",
1863
							 h->cache_obj->key);
1864
			}
1855
1865
1856
    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
1866
			if (dobj->file_size < conf->minfs) {
1857
                 "disk_cache: Done caching URL %s, len %" APR_OFF_T_FMT,
1867
				ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
1858
                 dobj->name, dobj->file_size);
1868
							 "disk_cache: URL %s failed the size check "
1869
							 "(%" APR_OFF_T_FMT "<%" APR_OFF_T_FMT ")",
1870
							 h->cache_obj->key, dobj->file_size, conf->minfs);
1871
				/* Remove the intermediate cache file and return filter status */
1872
				file_cache_errorcleanup(dobj, r);
1873
				return dobj->frv;
1874
			}
1875
			if (dobj->initial_size < 0) {
1876
				/* Update header information now that we know the size */
1877
				dobj->initial_size = dobj->file_size;
1878
				dobj->disk_info.file_size = dobj->file_size; //GG added. required?
1879
				rv = store_headers(h, r, &(h->cache_obj->info));
1880
				if (rv != APR_SUCCESS) {
1881
					file_cache_errorcleanup(dobj, r);
1882
					return dobj->frv;
1883
				}
1884
			}
1885
			else if (dobj->initial_size != dobj->file_size) {
1886
				ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
1887
							 "disk_cache: URL %s - body size mismatch: suggested %"
1888
							 APR_OFF_T_FMT "  bodysize %" APR_OFF_T_FMT ")",
1889
							 dobj->name, dobj->initial_size, dobj->file_size);
1890
				file_cache_errorcleanup(dobj, r);
1891
				return dobj->frv;
1892
			}
1893
		
1894
			/* All checks were fine, close output file */
1895
			rv = apr_file_close(dobj->fd);
1896
			dobj->fd = NULL;
1897
			if (rv != APR_SUCCESS) {
1898
				ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
1899
							 "disk_cache: While trying to close the cache file for "
1900
							 "URL %s, the close failed", dobj->name);
1901
				file_cache_errorcleanup(dobj, r);
1902
				return dobj->frv;
1903
			}
1904
		
1905
			return dobj->frv;
1906
				
1907
				
1908
				
1909
				
1910
		}
1859
1911
1860
    if (APR_SUCCESS != dobj->frv) {
1861
        ap_log_error(APLOG_MARK, APLOG_ERR, dobj->frv, r->server,
1862
                     "disk_cache: An error occurred while writing to the "
1863
                     "network for URL %s.",
1864
                     h->cache_obj->key);
1865
    }
1866
1912
1867
    if (dobj->file_size < conf->minfs) {
1868
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
1869
                     "disk_cache: URL %s failed the size check "
1870
                     "(%" APR_OFF_T_FMT "<%" APR_OFF_T_FMT ")",
1871
                     h->cache_obj->key, dobj->file_size, conf->minfs);
1872
        /* Remove the intermediate cache file and return filter status */
1873
        file_cache_errorcleanup(dobj, r);
1874
        return dobj->frv;
1875
    }
1876
    if (dobj->initial_size < 0) {
1877
        /* Update header information now that we know the size */
1878
        dobj->initial_size = dobj->file_size;
1879
        rv = store_headers(h, r, &(h->cache_obj->info));
1880
        if (rv != APR_SUCCESS) {
1881
            file_cache_errorcleanup(dobj, r);
1882
            return dobj->frv;
1883
        }
1884
    }
1885
    else if (dobj->initial_size != dobj->file_size) {
1886
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
1887
                     "disk_cache: URL %s - body size mismatch: suggested %"
1888
                     APR_OFF_T_FMT "  bodysize %" APR_OFF_T_FMT ")",
1889
                     dobj->name, dobj->initial_size, dobj->file_size);
1890
        file_cache_errorcleanup(dobj, r);
1891
        return dobj->frv;
1892
    }
1893
1913
1894
    /* All checks were fine, close output file */
1895
    rv = apr_file_close(dobj->fd);
1896
    dobj->fd = NULL;
1897
    if (rv != APR_SUCCESS) {
1898
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
1899
                     "disk_cache: While trying to close the cache file for "
1900
                     "URL %s, the close failed", dobj->name);
1901
        file_cache_errorcleanup(dobj, r);
1902
        return dobj->frv;
1903
    }
1914
    }
1904
1915
1905
    return dobj->frv;
1916
	return APR_SUCCESS;
1917
1906
}
1918
}
1907
1919
1908
1920

Return to bug 41362