Bug 828281 - UpdateRecord in CloseOutputStream can be removed. r=michal.novotny

This commit is contained in:
Alfred Kayser 2013-02-03 17:09:48 +01:00
Родитель 0ce0423e6c
Коммит 513cb2b5df
1 изменённых файлов: 27 добавлений и 46 удалений

73
netwerk/cache/nsDiskCacheStreams.cpp поставляемый
Просмотреть файл

@ -463,66 +463,47 @@ nsDiskCacheStreamIO::Flush()
} }
// write data to cache blocks, or flush mBuffer to file // write data to cache blocks, or flush mBuffer to file
NS_ASSERTION(mStreamEnd <= kMaxBufferSize, "stream is bigger than buffer");
nsDiskCacheMap *cacheMap = mDevice->CacheMap(); // get map reference nsDiskCacheMap *cacheMap = mDevice->CacheMap(); // get map reference
nsresult rv; nsDiskCacheRecord * record = &mBinding->mRecord;
nsresult rv = NS_OK;
bool written = false; // delete existing storage
if (record->DataLocationInitialized()) {
rv = cacheMap->DeleteStorage(record, nsDiskCache::kData);
NS_ENSURE_SUCCESS(rv, rv);
if (mStreamEnd <= kMaxBufferSize) { // Only call UpdateRecord when there is no data to write,
// store data (if any) in cache block files // because WriteDataCacheBlocks / FlushBufferToFile calls it.
if ((mStreamEnd == 0) && (!mBinding->mDoomed)) {
// delete existing storage rv = cacheMap->UpdateRecord(record);
nsDiskCacheRecord * record = &mBinding->mRecord;
if (record->DataLocationInitialized()) {
rv = cacheMap->DeleteStorage(record, nsDiskCache::kData);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING("cacheMap->DeleteStorage() failed."); NS_WARNING("cacheMap->UpdateRecord() failed.");
return rv; return rv; // XXX doom cache entry
}
}
// flush buffer to block files
written = true;
if (mStreamEnd > 0) {
rv = cacheMap->WriteDataCacheBlocks(mBinding, mBuffer, mStreamEnd);
if (NS_FAILED(rv)) {
NS_WARNING("WriteDataCacheBlocks() failed.");
written = false;
} }
} }
} }
if (mStreamEnd == 0) return NS_OK; // nothing to write
// try to write to the cache blocks
rv = cacheMap->WriteDataCacheBlocks(mBinding, mBuffer, mStreamEnd);
if (NS_FAILED(rv)) {
NS_WARNING("WriteDataCacheBlocks() failed.");
if (!written && mStreamEnd > 0) {
// failed to store in cacheblocks, save as separate file // failed to store in cacheblocks, save as separate file
rv = FlushBufferToFile(); // initializes DataFileLocation() if necessary rv = FlushBufferToFile(); // initializes DataFileLocation() if necessary
if (mFD) { if (mFD) {
// Update the file size of the disk file in the cache UpdateFileSize();
UpdateFileSize(); (void) PR_Close(mFD);
mFD = nullptr;
// close file descriptor
(void) PR_Close(mFD);
mFD = nullptr;
} }
else else
NS_WARNING("no file descriptor"); NS_WARNING("no file descriptor");
// close mFD first if possible before returning if FlushBufferToFile
// failed
NS_ENSURE_SUCCESS(rv, rv);
} }
// XXX do we need this here? WriteDataCacheBlocks() calls UpdateRecord() return rv;
// update cache map if entry isn't doomed
if (!mBinding->mDoomed) {
rv = cacheMap->UpdateRecord(&mBinding->mRecord);
if (NS_FAILED(rv)) {
NS_WARNING("cacheMap->UpdateRecord() failed.");
return rv; // XXX doom cache entry
}
}
return NS_OK;
} }