Bug 408751 ? nsNavHistory::Init is fragile (r=sspitzer)

This commit is contained in:
dietrich@mozilla.com 2008-01-06 22:28:24 -08:00
Родитель b82f5eb340
Коммит e2bfb5aa89
1 изменённых файлов: 28 добавлений и 8 удалений

Просмотреть файл

@ -447,15 +447,26 @@ nsNavHistory::BackupDBFile()
nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(profDir));
// create unique file
nsCOMPtr<nsIFile> corruptBackup;
rv = profDir->Clone(getter_AddRefs(corruptBackup));
NS_ENSURE_SUCCESS(rv, rv);
rv = corruptBackup->Append(DB_CORRUPT_FILENAME);
NS_ENSURE_SUCCESS(rv, rv);
rv = corruptBackup->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
NS_ENSURE_SUCCESS(rv, rv);
return mDBFile->MoveTo(profDir, DB_CORRUPT_FILENAME);
// get unique name, and remove tmp file
nsAutoString backupName;
rv = corruptBackup->GetLeafName(backupName);
NS_ENSURE_SUCCESS(rv, rv);
rv = corruptBackup->Remove(PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
// copy contents of db file to new uniquely-named backup file
rv = mDBFile->CopyTo(profDir, backupName);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
// nsNavHistory::InitDBFile
@ -473,15 +484,24 @@ nsNavHistory::InitDBFile(PRBool aForceInit)
NS_ENSURE_SUCCESS(rv, rv);
// if forcing, backup and remove the old file
PRBool dbExists;
if (aForceInit) {
rv = BackupDBFile();
if (mDBConn) {
// close db connection if open
rv = mDBConn->Close();
NS_ENSURE_SUCCESS(rv, rv);
}
rv = BackupDBFile();
NS_ENSURE_SUCCESS(rv, rv);
rv = mDBFile->Remove(PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
dbExists = PR_FALSE;
}
else {
// file exists?
PRBool dbExists;
rv = mDBFile->Exists(&dbExists);
NS_ENSURE_SUCCESS(rv, rv);
}
// open the database
mDBService = do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID, &rv);