From 627dcdb633f037376d934512d81f5ac4f7c08538 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Thu, 19 May 2011 18:54:26 +0200 Subject: [PATCH] Backout bug 654926 because of perma orange on Win Opt xpcshell. --- netwerk/cache/nsCacheEntryDescriptor.cpp | 34 ++---- netwerk/cache/nsCacheEntryDescriptor.h | 17 ++- netwerk/cache/nsDiskCacheStreams.cpp | 7 +- netwerk/test/unit/test_bug654926.js | 101 ------------------ .../test/unit/test_bug654926_doom_and_read.js | 100 ----------------- netwerk/test/unit/test_bug654926_test_seek.js | 87 --------------- 6 files changed, 19 insertions(+), 327 deletions(-) delete mode 100644 netwerk/test/unit/test_bug654926.js delete mode 100644 netwerk/test/unit/test_bug654926_doom_and_read.js delete mode 100644 netwerk/test/unit/test_bug654926_test_seek.js diff --git a/netwerk/cache/nsCacheEntryDescriptor.cpp b/netwerk/cache/nsCacheEntryDescriptor.cpp index a8c2196255e7..0b2ed96c7eb6 100644 --- a/netwerk/cache/nsCacheEntryDescriptor.cpp +++ b/netwerk/cache/nsCacheEntryDescriptor.cpp @@ -609,34 +609,22 @@ nsOutputStreamWrapper::LazyInit() nsCacheEntry* cacheEntry = mDescriptor->CacheEntry(); if (!cacheEntry) return NS_ERROR_NOT_AVAILABLE; - NS_ASSERTION(mOutput == nsnull, "mOutput set in LazyInit"); - - nsCOMPtr stream; rv = nsCacheService::OpenOutputStreamForEntry(cacheEntry, mode, mStartOffset, - getter_AddRefs(stream)); - if (NS_FAILED(rv)) - return rv; + getter_AddRefs(mOutput)); + if (NS_FAILED(rv)) return rv; + + mDescriptor->mOutput = mOutput; nsCacheDevice* device = cacheEntry->CacheDevice(); - if (device) { - // the entry has been truncated to mStartOffset bytes, inform device - PRInt32 size = cacheEntry->DataSize(); - rv = device->OnDataSizeChange(cacheEntry, mStartOffset - size); - if (NS_SUCCEEDED(rv)) - cacheEntry->SetDataSize(mStartOffset); - } else { - rv = NS_ERROR_NOT_AVAILABLE; - } + if (!device) return NS_ERROR_NOT_AVAILABLE; - // If anything above failed, clean up internal state and get out of here - // (see bug #654926)... - if (NS_FAILED(rv)) { - mDescriptor->InternalCleanup(stream); - return rv; - } + // the entry has been truncated to mStartOffset bytes, inform the device. + PRInt32 size = cacheEntry->DataSize(); + rv = device->OnDataSizeChange(cacheEntry, mStartOffset - size); + if (NS_FAILED(rv)) return rv; + + cacheEntry->SetDataSize(mStartOffset); - // ... otherwise, set members and mark initialized - mDescriptor->mOutput = mOutput = stream; mInitialized = PR_TRUE; return NS_OK; } diff --git a/netwerk/cache/nsCacheEntryDescriptor.h b/netwerk/cache/nsCacheEntryDescriptor.h index 4416c5b9c9c5..c74ed5345744 100644 --- a/netwerk/cache/nsCacheEntryDescriptor.h +++ b/netwerk/cache/nsCacheEntryDescriptor.h @@ -77,22 +77,19 @@ public: void CloseOutput(void) { - InternalCleanup(mOutput); - mOutput = nsnull; - } - -private: - void InternalCleanup(nsIOutputStream *stream) - { - if (stream) { - nsCOMPtr tmp (do_QueryInterface(stream)); + if (mOutput) { + nsCOMPtr tmp (do_QueryInterface(mOutput)); if (tmp) tmp->CloseInternal(); else - stream->Close(); + mOutput->Close(); + + mOutput = nsnull; } } +private: + /************************************************************************* * input stream wrapper class - diff --git a/netwerk/cache/nsDiskCacheStreams.cpp b/netwerk/cache/nsDiskCacheStreams.cpp index 30bc6e60af65..36cd1eaea427 100644 --- a/netwerk/cache/nsDiskCacheStreams.cpp +++ b/netwerk/cache/nsDiskCacheStreams.cpp @@ -484,13 +484,8 @@ nsDiskCacheStreamIO::Flush() CACHE_LOG_DEBUG(("CACHE: Flush [%x doomed=%u]\n", mBinding->mRecord.HashNumber(), mBinding->mDoomed)); - if (!mBufDirty) { - if (mFD) { - (void) PR_Close(mFD); - mFD = nsnull; - } + if (!mBufDirty) return NS_OK; - } // write data to cache blocks, or flush mBuffer to file nsDiskCacheMap *cacheMap = mDevice->CacheMap(); // get map reference diff --git a/netwerk/test/unit/test_bug654926.js b/netwerk/test/unit/test_bug654926.js deleted file mode 100644 index 769521b60c77..000000000000 --- a/netwerk/test/unit/test_bug654926.js +++ /dev/null @@ -1,101 +0,0 @@ -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; - -var _CSvc; -function get_cache_service() { - if (_CSvc) - return _CSvc; - - return _CSvc = Cc["@mozilla.org/network/cache-service;1"]. - getService(Ci.nsICacheService); -} - -function get_ostream_for_entry(key, asFile, append, entryRef) -{ - var cache = get_cache_service(); - var session = cache.createSession( - "HTTP", - asFile ? Ci.nsICache.STORE_ON_DISK_AS_FILE - : Ci.nsICache.STORE_ON_DISK, - Ci.nsICache.STREAM_BASED); - var cacheEntry = session.openCacheEntry( - key, - append ? Ci.nsICache.ACCESS_READ_WRITE - : Ci.nsICache.ACCESS_WRITE, - true); - var oStream = cacheEntry.openOutputStream(append ? cacheEntry.dataSize : 0); - entryRef.value = cacheEntry; - return oStream; -} - -function gen_1MiB() -{ - var i; - var data="x"; - for (i=0 ; i < 20 ; i++) - data+=data; - return data; -} - -function write_and_check(str, data, len) -{ - var written = str.write(data, len); - if (written != len) { - do_throw("str.write has not written all data!\n" + - " Expected: " + len + "\n" + - " Actual: " + written + "\n"); - } -} - -function write_datafile() -{ - var entry = {}; - var oStr = get_ostream_for_entry("data", true, false, entry); - var data = gen_1MiB(); - - // 6MiB - var i; - for (i=0 ; i<6 ; i++) - write_and_check(oStr, data, data.length); - - oStr.close(); - entry.value.close(); -} - -function append_datafile() -{ - var entry = {}; - var oStr = get_ostream_for_entry("data", false, true, entry); - var data = gen_1MiB(); - - - // append 1MiB - try { - write_and_check(oStr, data, data.length); - do_throw(); - } - catch (ex) { } - - // closing the ostream should fail in this case - try { - oStr.close(); - do_throw(); - } - catch (ex) { } - - entry.value.close(); -} - -function run_test() { - do_get_profile(); - - // clear the cache - get_cache_service().evictEntries(Ci.nsICache.STORE_ANYWHERE); - - // force to write file bigger than 5MiB - write_datafile(); - - // try to append the entry - append_datafile(); -} diff --git a/netwerk/test/unit/test_bug654926_doom_and_read.js b/netwerk/test/unit/test_bug654926_doom_and_read.js deleted file mode 100644 index c180972f83b5..000000000000 --- a/netwerk/test/unit/test_bug654926_doom_and_read.js +++ /dev/null @@ -1,100 +0,0 @@ -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; - -var _CSvc; -function get_cache_service() { - if (_CSvc) - return _CSvc; - - return _CSvc = Cc["@mozilla.org/network/cache-service;1"]. - getService(Ci.nsICacheService); -} - -function get_ostream_for_entry(key, asFile, append, entryRef) -{ - var cache = get_cache_service(); - var session = cache.createSession( - "HTTP", - asFile ? Ci.nsICache.STORE_ON_DISK_AS_FILE - : Ci.nsICache.STORE_ON_DISK, - Ci.nsICache.STREAM_BASED); - var cacheEntry = session.openCacheEntry( - key, - append ? Ci.nsICache.ACCESS_READ_WRITE - : Ci.nsICache.ACCESS_WRITE, - true); - var oStream = cacheEntry.openOutputStream(append ? cacheEntry.dataSize : 0); - entryRef.value = cacheEntry; - return oStream; -} - -function gen_1MiB() -{ - var i; - var data="x"; - for (i=0 ; i < 20 ; i++) - data+=data; - return data; -} - -function write_and_check(str, data, len) -{ - var written = str.write(data, len); - if (written != len) { - do_throw("str.write has not written all data!\n" + - " Expected: " + len + "\n" + - " Actual: " + written + "\n"); - } -} - -function make_input_stream_scriptable(input) { - var wrapper = Cc["@mozilla.org/scriptableinputstream;1"]. - createInstance(Ci.nsIScriptableInputStream); - wrapper.init(input); - return wrapper; -} - -function write_datafile() -{ - var entry = {}; - var oStr = get_ostream_for_entry("data", true, false, entry); - var data = gen_1MiB(); - - write_and_check(oStr, data, data.length); - - oStr.close(); - entry.value.close(); -} - -function test_read_after_doom() -{ - var entry = {}; - var oStr = get_ostream_for_entry("data", false, true, entry); - var data = gen_1MiB(); - - entry.value.doom(); - write_and_check(oStr, data, data.length); - - oStr.close(); - - var iStr = make_input_stream_scriptable(entry.value.openInputStream(0)); - var read = iStr.read(iStr.available()); - do_check_eq(read.length, 2*1024*1024); - iStr.close(); - - entry.value.close(); -} - -function run_test() { - do_get_profile(); - - // clear the cache - get_cache_service().evictEntries(Ci.nsICache.STORE_ANYWHERE); - - // force to write file bigger than 5MiB - write_datafile(); - - // open, doom, append, read - test_read_after_doom(); -} diff --git a/netwerk/test/unit/test_bug654926_test_seek.js b/netwerk/test/unit/test_bug654926_test_seek.js deleted file mode 100644 index 61b70b99bb1c..000000000000 --- a/netwerk/test/unit/test_bug654926_test_seek.js +++ /dev/null @@ -1,87 +0,0 @@ -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; - -var _CSvc; -function get_cache_service() { - if (_CSvc) - return _CSvc; - - return _CSvc = Cc["@mozilla.org/network/cache-service;1"]. - getService(Ci.nsICacheService); -} - -function get_ostream_for_entry(key, asFile, append, entryRef) -{ - var cache = get_cache_service(); - var session = cache.createSession( - "HTTP", - asFile ? Ci.nsICache.STORE_ON_DISK_AS_FILE - : Ci.nsICache.STORE_ON_DISK, - Ci.nsICache.STREAM_BASED); - var cacheEntry = session.openCacheEntry( - key, - append ? Ci.nsICache.ACCESS_READ_WRITE - : Ci.nsICache.ACCESS_WRITE, - true); - var oStream = cacheEntry.openOutputStream(append ? cacheEntry.dataSize : 0); - entryRef.value = cacheEntry; - return oStream; -} - -function gen_1MiB() -{ - var i; - var data="x"; - for (i=0 ; i < 20 ; i++) - data+=data; - return data; -} - -function write_and_check(str, data, len) -{ - var written = str.write(data, len); - if (written != len) { - do_throw("str.write has not written all data!\n" + - " Expected: " + len + "\n" + - " Actual: " + written + "\n"); - } -} - -function write_datafile() -{ - var entry = {}; - var oStr = get_ostream_for_entry("data", true, false, entry); - var data = gen_1MiB(); - - write_and_check(oStr, data, data.length); - - oStr.close(); - entry.value.close(); -} - -function open_for_readwrite() -{ - var entry = {}; - var oStr = get_ostream_for_entry("data", false, true, entry); - - // Opening the entry for appending data calls nsDiskCacheStreamIO::Seek() - // which initializes mFD. If no data is written then mBufDirty is false and - // mFD won't be closed in nsDiskCacheStreamIO::Flush(). - - oStr.close(); - entry.value.close(); -} - -function run_test() { - do_get_profile(); - - // clear the cache - get_cache_service().evictEntries(Ci.nsICache.STORE_ANYWHERE); - - // force to write file bigger than 5MiB - write_datafile(); - - // try to open the entry for appending - open_for_readwrite(); -}