- Fixing deletion of cache on version change

- DBRecovery(): removing all fancy moves to trash folder. Just delete
  the cache when it is corrupted.
r=neeti
This commit is contained in:
dp%netscape.com 2000-09-14 18:48:57 +00:00
Родитель 8528da1a73
Коммит c097ee7045
1 изменённых файлов: 23 добавлений и 18 удалений

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

@ -180,6 +180,9 @@ nsNetDiskCache::~nsNetDiskCache()
NS_IMETHODIMP nsNetDiskCache::InitCacheFolder()
{
#ifdef DEBUG_dp
printf("CACHE: InitCacheFolder()\n");
#endif /* DEBUG_dp */
// don't initialize if no cache folder is set.
if(!mDiskCacheFolder) return NS_OK ;
@ -387,6 +390,10 @@ nsNetDiskCache::GetCachedNetData(const char* key, PRUint32 length, nsINetDataCac
if ( NS_FAILED( rv ) )
DBRecovery();
#ifdef DEBUG_dp
printf("CACHE: GetCachedNetData(%s) created nsDiskCacheRecord %p id=%d\n", key, _retval, id);
#endif /* DEBUG_dp */
return rv;
}
@ -417,9 +424,16 @@ nsNetDiskCache::GetCachedNetDataByID(PRInt32 RecordID, nsINetDataCacheRecord **_
} else {
delete newRecord;
}
#ifdef DEBUG_dp
printf("CACHE: GetCachedNetDataByID(id=%d) created nsDiskCacheRecord %p\n", RecordID, *_retval);
#endif /* DEBUG_dp */
return rv;
}
#ifdef DEBUG_dp
printf("CACHE: GetCachedNetDataByID(id=%d) = RecordID not in DB\n", RecordID);
#endif /* DEBUG_dp */
NS_WARNING("Error: RecordID not in DB\n");
DBRecovery();
return rv;
@ -518,6 +532,9 @@ nsNetDiskCache::GetStorageInUse(PRUint32 *aStorageInUse)
NS_IMETHODIMP
nsNetDiskCache::RemoveAll(void)
{
#ifdef DEBUG_dp
printf("CACHE: RemoveAll()\n");
#endif /* DEBUG_dp */
NS_ASSERTION(mDB, "no db.") ;
NS_ASSERTION(mDiskCacheFolder, "no cache folder.") ;
@ -689,23 +706,7 @@ nsNetDiskCache::SetSizeEntry(void)
NS_IMETHODIMP
nsNetDiskCache::DBRecovery(void)
{
// rename all the sub cache dirs and remove them later during dtor.
nsresult rv = RenameCacheSubDirs() ;
if(NS_FAILED(rv))
return rv ;
// remove corrupted db file, don't care if db->shutdown fails or not.
mDB->Shutdown() ;
// False since we want to delete a file rather than recursively delete a directory
rv = mDBFile->Delete(PR_FALSE) ;
if (NS_FAILED ( rv ) ) return rv;
// reinitilize DB
return InitDB() ;
return RemoveAll();
}
@ -772,6 +773,10 @@ nsNetDiskCache::fixCacheVersion (const char *cache_dir, unsigned version)
if (fVersion < version)
{
// Make sure we reset fileptr to the beginning
PR_Seek(vf, 0, PR_SEEK_SET);
// Write the new version number
sprintf (vBuf, "%u", version);
if (PR_Write (vf, vBuf, sizeof (vBuf)) != sizeof (vBuf))
{