diff --git a/mozilla/netwerk/cache/src/nsCacheService.cpp b/mozilla/netwerk/cache/src/nsCacheService.cpp index 25710ba6589..b5cb4ef68c2 100644 --- a/mozilla/netwerk/cache/src/nsCacheService.cpp +++ b/mozilla/netwerk/cache/src/nsCacheService.cpp @@ -433,7 +433,13 @@ nsCacheService::CreateDiskDevice() nsresult rv = mDiskDevice->Init(); if (NS_FAILED(rv)) { - // XXX log error +#if DEBUG + printf("###\n"); + printf("### mDiskDevice->Init() failed (0x%.8x)\n", rv); + printf("### - disabling disk cache for this session.\n"); + printf("###\n"); +#endif + mEnableDiskDevice = PR_FALSE; delete mDiskDevice; mDiskDevice = nsnull; } @@ -732,28 +738,36 @@ nsCacheService::EnsureEntryHasDevice(nsCacheEntry * entry) { nsCacheDevice * device = entry->CacheDevice(); if (device) return device; + nsresult rv = NS_OK; if (entry->IsStreamData() && entry->IsAllowedOnDisk() && mEnableDiskDevice) { // this is the default if (!mDiskDevice) { - nsresult rv = CreateDiskDevice(); - if (NS_FAILED(rv)) - return nsnull; + rv = CreateDiskDevice(); // ignore the error (check for mDiskDevice instead) } - device = mDiskDevice; - } else if (mEnableMemoryDevice) { + if (mDiskDevice) { + entry->MarkBinding(); // XXX + rv = mDiskDevice->BindEntry(entry); + entry->ClearBinding(); // XXX + if (NS_SUCCEEDED(rv)) + device = mDiskDevice; + } + } + + // if we can't use mDiskDevice, try mMemoryDevice + if (!device && mEnableMemoryDevice) { NS_ASSERTION(entry->IsAllowedInMemory(), "oops.. bad flags"); - device = mMemoryDevice; + + entry->MarkBinding(); // XXX + rv = mMemoryDevice->BindEntry(entry); + entry->ClearBinding(); // XXX + if (NS_SUCCEEDED(rv)) + device = mMemoryDevice; } if (device == nsnull) return nsnull; - entry->MarkBinding(); // XXX - nsresult rv = device->BindEntry(entry); - entry->ClearBinding(); // XXX - if (NS_FAILED(rv)) return nsnull; - entry->SetCacheDevice(device); return device; } diff --git a/mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp b/mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp index 8cd008f8ed4..f51103c6c93 100644 --- a/mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp +++ b/mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp @@ -633,6 +633,14 @@ nsDiskCacheDevice::Init() gFileTransportService = do_GetService("@mozilla.org/network/file-transport-service;1", &rv); if (NS_FAILED(rv)) return rv; + // delete "Cache.Trash" folder + nsCOMPtr cacheTrashDir; + rv = mCacheDirectory->Clone(getter_AddRefs(cacheTrashDir)); + if (NS_FAILED(rv)) return rv; + rv = cacheTrashDir->SetLeafName("Cache.Trash"); + if (NS_FAILED(rv)) return rv; + (void) cacheTrashDir->Delete(PR_TRUE); // ignore errors, we tried... + // XXX read in persistent information about the cache. this can fail, if // no cache directory has ever existed before. rv = readCacheMap(); @@ -1502,7 +1510,45 @@ nsresult nsDiskCacheDevice::clobberDiskCache() // recursively delete the disk cache directory. rv = mCacheDirectory->Delete(PR_TRUE); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) { + // try moving it aside + + // get parent directory of cache directory + nsCOMPtr cacheParentDir; + rv = mCacheDirectory->GetParent(getter_AddRefs(cacheParentDir)); + if (NS_FAILED(rv)) return rv; + + // create "Cache.Trash" directory if necessary + nsCOMPtr oldCacheDir; + rv = cacheParentDir->Clone(getter_AddRefs(oldCacheDir)); + if (NS_FAILED(rv)) return rv; + rv = oldCacheDir->Append("Cache.Trash"); + if (NS_FAILED(rv)) return rv; + + PRBool exists = PR_FALSE; + rv = oldCacheDir->Exists(&exists); + if (NS_FAILED(rv)) return rv; + + if (!exists) { + // create the "Cache.Trash" directory + rv = oldCacheDir->Create(nsIFile::DIRECTORY_TYPE,0777); + if (NS_FAILED(rv)) return rv; + } + + // create a directory with unique name to contain existing cache directory + rv = oldCacheDir->Append("Cache"); + if (NS_FAILED(rv)) return rv; + rv = oldCacheDir->CreateUnique(nsnull,nsIFile::DIRECTORY_TYPE, 0777); + if (NS_FAILED(rv)) return rv; + + // move existing cache directory into profileDir/Cache.Trash/CacheUnique + nsCOMPtr existingCacheDir; + rv = mCacheDirectory->Clone(getter_AddRefs(existingCacheDir)); + if (NS_FAILED(rv)) return rv; + rv = existingCacheDir->MoveTo(oldCacheDir, nsnull); + if (NS_FAILED(rv)) return rv; + } + rv = mCacheDirectory->Create(nsIFile::DIRECTORY_TYPE, 0777); if (NS_FAILED(rv)) return rv;