зеркало из https://github.com/mozilla/gecko-dev.git
Backout bug 654926 because of perma orange on Win Opt xpcshell.
This commit is contained in:
Родитель
083ab03e55
Коммит
627dcdb633
|
@ -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<nsIOutputStream> 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;
|
||||
}
|
||||
|
|
|
@ -77,22 +77,19 @@ public:
|
|||
|
||||
void CloseOutput(void)
|
||||
{
|
||||
InternalCleanup(mOutput);
|
||||
mOutput = nsnull;
|
||||
}
|
||||
|
||||
private:
|
||||
void InternalCleanup(nsIOutputStream *stream)
|
||||
{
|
||||
if (stream) {
|
||||
nsCOMPtr<nsIDiskCacheStreamInternal> tmp (do_QueryInterface(stream));
|
||||
if (mOutput) {
|
||||
nsCOMPtr<nsIDiskCacheStreamInternal> tmp (do_QueryInterface(mOutput));
|
||||
if (tmp)
|
||||
tmp->CloseInternal();
|
||||
else
|
||||
stream->Close();
|
||||
mOutput->Close();
|
||||
|
||||
mOutput = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* input stream wrapper class -
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -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();
|
||||
}
|
Загрузка…
Ссылка в новой задаче