зеркало из https://github.com/mozilla/pjs.git
Bug 408751 ? nsNavHistory::Init is fragile (r=sspitzer)
This commit is contained in:
Родитель
4eb76336c4
Коммит
9df1541c90
|
@ -446,16 +446,27 @@ nsNavHistory::BackupDBFile()
|
|||
nsCOMPtr<nsIFile> profDir;
|
||||
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) {
|
||||
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?
|
||||
rv = mDBFile->Exists(&dbExists);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
// file exists?
|
||||
PRBool dbExists;
|
||||
rv = mDBFile->Exists(&dbExists);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// open the database
|
||||
mDBService = do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID, &rv);
|
||||
|
|
Загрузка…
Ссылка в новой задаче